:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --border: #e9ecef;
    --text: #212529;
    --text-muted: #6c757d;
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --danger: #dc3545;
    --danger-hover: #bb2d3b;
    --success: #198754;
    --warning: #ffc107;
    --warning-text: #664d03;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Login */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-card .logo {
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Layout */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
}

.sidebar-brand {
    padding: 0 1.25rem 1.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand strong {
    display: block;
    font-size: 1.1rem;
    color: var(--text);
    letter-spacing: 0;
    text-transform: none;
}

.sidebar-nav {
    list-style: none;
    padding: 0.75rem 0;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: var(--text);
    background: var(--bg);
}

.sidebar-nav a.active {
    border-right: 2px solid var(--primary);
    font-weight: 500;
}

.sidebar-nav svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
}

.sidebar-footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
}

.sidebar-footer a:hover {
    color: var(--danger);
}

.main {
    flex: 1;
    margin-left: 240px;
    padding: 2rem;
    max-width: 1200px;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-size: 1.35rem;
    font-weight: 600;
}

.page-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1.25rem;
}

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

.stat-card .value.danger { color: var(--danger); }
.stat-card .value.warning { color: var(--warning-text); }
.stat-card .value.success { color: var(--success); }

/* Table */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--bg);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-danger { background: #f8d7da; color: var(--danger); }
.badge-warning { background: #fff3cd; color: var(--warning-text); }
.badge-success { background: #d1e7dd; color: var(--success); }
.badge-muted { background: var(--bg); color: var(--text-muted); }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="email"],
select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,110,253,0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover { background: #157347; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg);
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.btn-block {
    display: flex;
    width: 100%;
    justify-content: center;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-danger { background: #f8d7da; color: var(--danger); border: 1px solid #f5c2c7; }
.alert-success { background: #d1e7dd; color: var(--success); border: 1px solid #badbcc; }
.alert-warning { background: #fff3cd; color: var(--warning-text); border: 1px solid #ffecb5; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.9rem;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    margin: 1rem;
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.modal-header button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.25rem;
    line-height: 1;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Searchable Select */
.searchable-select {
    position: relative;
}

.searchable-select input[type="text"] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
}

.searchable-select input[type="text"].has-value {
    border-color: var(--primary);
    background: #f0f6ff;
}

.searchable-select-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 110;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.searchable-select.open .searchable-select-dropdown {
    display: block;
}

.searchable-select-option {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.searchable-select-option:hover,
.searchable-select-option.highlighted {
    background: var(--bg);
    color: var(--primary);
}

.searchable-select-option.hidden {
    display: none;
}

.searchable-select-empty {
    padding: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Loading */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s;
    }

    .sidebar.open { transform: translateX(0); }

    .main {
        margin-left: 0;
        padding: 1rem;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
    }
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-1 { gap: 0.5rem; }
.justify-between { justify-content: space-between; }
