/* ============================================================
   Design Tokens
   ============================================================ */
:root {
    --color-bg:          #f4f6f9;
    --color-surface:     #ffffff;
    --color-border:      #e3e8ee;
    --color-text:        #1f2937;
    --color-text-muted:  #6b7280;
    --color-primary:     #2563eb;
    --color-primary-600: #1d4ed8;
    --color-primary-50:  #eff6ff;
    --color-sidebar:     #111827;
    --color-sidebar-2:   #1f2937;
    --color-success:     #16a34a;
    --color-warning:     #d97706;
    --color-danger:      #dc2626;

    --radius:            10px;
    --radius-sm:         6px;
    --shadow-sm:         0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md:         0 4px 12px rgba(16, 24, 40, .08);
    --font:              -apple-system, BlinkMacSystemFont, "Segoe UI",
                         Roboto, "Helvetica Neue", Arial, sans-serif;

    --sidebar-w:         240px;
    --topbar-h:          64px;
}
/* ============================================================
   Dark Mode
   ============================================================ */
:root[data-theme="dark"] {
    --color-bg:          #0f172a;
    --color-surface:     #1e293b;
    --color-border:      #334155;
    --color-text:        #e2e8f0;
    --color-text-muted:  #94a3b8;
    --color-primary:     #3b82f6;
    --color-primary-600: #2563eb;
    --color-primary-50:  rgba(59,130,246,.15);
    --color-sidebar:     #020617;
    --color-sidebar-2:   #0f172a;
    --shadow-sm:         0 1px 2px rgba(0,0,0,.4);
    --shadow-md:         0 4px 12px rgba(0,0,0,.5);
}
.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.nav-item .icon { opacity: .85; }
:root[data-theme="dark"] table.data thead th { background: #0f172a; }
:root[data-theme="dark"] table.data tbody tr:hover { background: #233047; }
:root[data-theme="dark"] .topbar__search { background: #0f172a; }
:root[data-theme="dark"] .btn--secondary { background: #1e293b; color: #e2e8f0; }
:root[data-theme="dark"] .btn--secondary:hover { background: #334155; }
:root[data-theme="dark"] .btn--danger { background: #1e293b; }
:root[data-theme="dark"] .btn--danger:hover { background: #7f1d1d33; }
:root[data-theme="dark"] .badge { background: #334155; color: #cbd5e1; }
:root[data-theme="dark"] .badge--info { background: rgba(59,130,246,.2); color: #93c5fd; }
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .field textarea,
:root[data-theme="dark"] .toolbar input[type="text"] {
    background: #0f172a;
    color: #e2e8f0;
}
:root[data-theme="dark"] .flash--success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
:root[data-theme="dark"] .flash--error   { background: #7f1d1d; color: #fca5a5; border-color: #991b1b; }
/* ============================================================
   Reset / Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 8px; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

/* ============================================================
   Layout
   ============================================================ */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.main { display: flex; flex-direction: column; min-width: 0; }

.content {
    padding: 24px 32px;
    max-width: 1200px;
    width: 100%;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    background: var(--color-sidebar);
    color: #d1d5db;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--color-primary);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700;
    font-size: 16px;
}

.brand-name { font-weight: 600; color: #fff; letter-spacing: .02em; }

.sidebar__nav { padding: 12px 12px; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--color-sidebar-2); color: #fff; text-decoration: none; }
.nav-item.is-active {
    background: var(--color-primary);
    color: #fff;
}
.nav-icon { width: 18px; text-align: center; font-size: 14px; opacity: .9; }

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,.06);
    margin: 12px 4px;
}

.sidebar__footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.06);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.04);
}
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 600;
}
.user-name { font-size: 13px; color: #fff; font-weight: 500; }
.user-role { font-size: 11px; color: #9ca3af; }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
    height: var(--topbar-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar__search {
    flex: 1;
    max-width: 480px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f9fafb;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    height: 38px;
    transition: border-color .15s, box-shadow .15s;
}
.topbar__search:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-50);
}
.topbar__search input {
    border: 0;
    background: transparent;
    outline: 0;
    flex: 1;
    font-size: 14px;
    color: var(--color-text);
}
.search-icon { opacity: .5; }

.topbar__actions { margin-left: auto; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; }

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

.btn--secondary {
    background: #fff;
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn--secondary:hover { background: #f9fafb; }

.btn--danger { background: #fff; color: var(--color-danger); border-color: #fecaca; }
.btn--danger:hover { background: #fef2f2; }

.btn--ghost { background: transparent; color: var(--color-text-muted); }
.btn--ghost:hover { background: #f3f4f6; color: var(--color-text); }

.btn--sm { padding: 5px 10px; font-size: 12.5px; }

/* ============================================================
   Cards & Page Header
   ============================================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header h1 { margin: 0; }
.page-header__sub { color: var(--color-text-muted); font-size: 13px; margin-top: 2px; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card + .card { margin-top: 20px; }

.card__header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card__title { font-weight: 600; font-size: 14px; }
.card__body { padding: 20px; }
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 20px;
}
.tab {
    padding: 10px 16px;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    font-weight: 500;
    font-size: 13.5px;
}
.tab:hover { color: var(--color-text); text-decoration: none; }
.tab.is-active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}
.tab-count {
    background: #e5e7eb;
    color: #374151;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 11px;
    margin-left: 6px;
}
:root[data-theme="dark"] .tab-count { background: #334155; color: #cbd5e1; }

.dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    margin: 0;
    font-size: 13.5px;
}
.dl dt { color: var(--color-text-muted); font-weight: 500; }
.dl dd { margin: 0; }
/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
table.data thead th {
    text-align: left;
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 10px 16px;
    background: #f9fafb;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
table.data tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
table.data tbody tr:hover { background: #fafbfc; }
table.data tbody tr:last-child td { border-bottom: 0; }

.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions a { margin-left: 8px; font-size: 12.5px; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
    background: #f3f4f6;
    color: var(--color-text-muted);
}
.badge--success { background: #dcfce7; color: #166534; }
.badge--warning { background: #fef3c7; color: #92400e; }
.badge--danger  { background: #fee2e2; color: #991b1b; }
.badge--info    { background: var(--color-primary-50); color: var(--color-primary-600); }

/* ============================================================
   Forms
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 20px;
}
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--color-text-muted);
}
.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 0;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-50);
}
.field textarea { min-height: 90px; resize: vertical; }
.field .hint { font-size: 11.5px; color: var(--color-text-muted); }

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 16px;
    margin-top: 20px;
    border-top: 1px solid var(--color-border);
}

/* ============================================================
   Searchbar (in Listen)
   ============================================================ */
.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.toolbar input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    min-width: 260px;
    background: #fff;
}
.toolbar input[type="text"]:focus {
    outline: 0;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-50);
}

/* ============================================================
   Empty state
   ============================================================ */
.empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--color-text-muted);
}
.empty__icon { font-size: 32px; opacity: .5; margin-bottom: 8px; }

/* ============================================================
   Flash messages
   ============================================================ */
.flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid transparent;
}
.flash--success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.flash--error   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }


.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
}
.stat-card__icon {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    background: var(--color-primary-50);
    color: var(--color-primary);
    border-radius: 10px;
}
.stat-card__value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-card__label { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: var(--sidebar-w);
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 30;
    }
    .sidebar.is-open { transform: translateX(0); }
    .topbar { padding: 0 16px; }
    .content { padding: 20px 16px; }
    .form-grid { grid-template-columns: 1fr; }
}