/* ============================================================
   ModernForum Admin — Design Tokens & Layout
   ============================================================ */

:root {
    --color-bg: #F7F7FA;
    --color-surface: #FFFFFF;
    --color-surface-2: #F2F2F6;
    --color-border: #EBEBF0;
    --color-text: #14151A;
    --color-text-secondary: #6E7180;
    --color-text-tertiary: #A0A3B1;

    --color-primary: #5B5FEF;
    --color-primary-hover: #4C4FE0;
    --color-primary-soft: #EEEEFD;

    --color-success: #10B981;
    --color-success-soft: #E7F9F1;
    --color-danger: #EF4444;
    --color-danger-soft: #FDECEC;
    --color-warning: #F59E0B;
    --color-warning-soft: #FEF6E7;

    --color-overlay: rgba(15, 16, 23, 0.48);

    --shadow-xs: 0 1px 2px rgba(20, 21, 26, 0.04);
    --shadow-sm: 0 2px 8px rgba(20, 21, 26, 0.06);
    --shadow-md: 0 8px 24px rgba(20, 21, 26, 0.08);
    --shadow-lg: 0 16px 48px rgba(20, 21, 26, 0.14);

    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 999px;

    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-8: 32px;

    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --sidebar-width: 248px;
    --topbar-height: 60px;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 120ms;
    --duration-base: 200ms;

    --z-modal: 300;
    --z-toast: 400;
    --z-sidebar: 200;
}

[data-theme="dark"] {
    --color-bg: #0D0E12;
    --color-surface: #17181D;
    --color-surface-2: #1F2026;
    --color-border: #2A2B33;
    --color-text: #F4F4F6;
    --color-text-secondary: #9A9CAB;
    --color-text-tertiary: #6C6E7C;
    --color-primary: #7B7FFF;
    --color-primary-hover: #9094FF;
    --color-primary-soft: #23244A;
    --color-success-soft: #103226;
    --color-danger-soft: #3A1A1A;
    --color-warning-soft: #3A2C0F;
    --color-overlay: rgba(0,0,0,0.6);
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.35);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.45);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.55);
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

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

a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; font-size: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; outline: none; }
ul { list-style: none; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: var(--radius-full); }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }

/* ============================================================
   App Shell
   ============================================================ */

#adminApp {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: var(--z-sidebar);
    transition: transform var(--duration-base) var(--ease-out);
}

.admin-sidebar__logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-4);
    font-weight: 800;
    font-size: 16px;
}

.admin-sidebar__logo-icon {
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--color-primary), #8B5CF6);
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 800; font-size: 14px;
    flex-shrink: 0;
}

.admin-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2) var(--space-3);
}

.admin-nav__section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary);
    padding: var(--space-3) var(--space-3) var(--space-2);
}

.admin-nav__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-3);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
    margin-bottom: 2px;
}

.admin-nav__item svg { width: 18px; height: 18px; flex-shrink: 0; }

.admin-nav__item:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.admin-nav__item.is-active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.admin-nav__badge {
    margin-left: auto;
    background: var(--color-danger);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-full);
}

.admin-sidebar__footer {
    padding: var(--space-3);
    border-top: 1px solid var(--color-border);
}

.admin-user-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
}

.admin-user-card img {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
}

.admin-user-card__info { min-width: 0; flex: 1; }
.admin-user-card__name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-user-card__role { font-size: 11px; color: var(--color-text-tertiary); }

/* ============================================================
   Main content area
   ============================================================ */

.admin-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.admin-topbar {
    height: var(--topbar-height);
    background: color-mix(in srgb, var(--color-surface) 90%, transparent);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-5);
    position: sticky;
    top: 0;
    z-index: 90;
    gap: var(--space-3);
}

.admin-topbar__title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.admin-topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.admin-menu-toggle {
    display: none;
}

.admin-content {
    padding: var(--space-5);
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    height: 40px; padding: 0 var(--space-4); border-radius: var(--radius-md);
    font-weight: 600; font-size: 14px;
    transition: transform var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out), opacity var(--duration-fast) var(--ease-out);
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-2); color: var(--color-text); }
.btn-outline { background: transparent; border: 1.5px solid var(--color-border); color: var(--color-text); }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-ghost { background: transparent; color: var(--color-primary); }
.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: 12px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: var(--radius-full); }
.btn-icon.btn-sm { width: 32px; height: 32px; }

/* ============================================================
   Cards / Stats
   ============================================================ */

.card { background: var(--color-surface); border-radius: var(--radius-lg); border: 1px solid var(--color-border); box-shadow: var(--shadow-xs); }
.card-pad { padding: var(--space-4); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

.stat-card__icon {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: var(--space-3);
    font-size: 16px;
}
.stat-card__icon svg { width: 18px; height: 18px; }

.stat-card__value { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
.stat-card__label { font-size: 12px; color: var(--color-text-secondary); margin-top: 2px; }

/* ============================================================
   Section header
   ============================================================ */

.section-title { font-size: 16px; font-weight: 800; margin-bottom: var(--space-3); letter-spacing: -0.01em; }
.section-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); gap: var(--space-3); flex-wrap: wrap; }

/* ============================================================
   Tables / Lists
   ============================================================ */

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--color-text-tertiary); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border);
}
.data-table td {
    padding: var(--space-3); border-bottom: 1px solid var(--color-border); font-size: 13px; vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-surface-2); }

.table-wrap { overflow-x: auto; }

.cell-user { display: flex; align-items: center; gap: var(--space-2); min-width: 180px; }
.cell-user img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.cell-user__name { font-weight: 700; font-size: 13px; }
.cell-user__sub { font-size: 12px; color: var(--color-text-tertiary); }

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: var(--radius-full);
}
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-primary { background: var(--color-primary-soft); color: var(--color-primary); }
.badge-neutral { background: var(--color-surface-2); color: var(--color-text-secondary); }

/* ============================================================
   Forms
   ============================================================ */

.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.field label { font-size: 12px; font-weight: 700; color: var(--color-text-secondary); }
.field input, .field textarea, .field select {
    background: var(--color-surface-2); border: 1.5px solid transparent; border-radius: var(--radius-md);
    padding: 10px 12px; font-size: 14px; color: var(--color-text); width: 100%;
    transition: border-color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--color-primary); background: var(--color-surface); }
.field textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.field-hint { font-size: 12px; color: var(--color-text-tertiary); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

.switch {
    position: relative; display: inline-flex; align-items: center; width: 44px; height: 26px; flex-shrink: 0;
}
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.switch__track { position: absolute; inset: 0; background: var(--color-surface-2); border: 1.5px solid var(--color-border); border-radius: var(--radius-full); transition: all var(--duration-base) var(--ease-out); }
.switch__thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: white; border-radius: 50%; box-shadow: var(--shadow-sm); transition: transform var(--duration-base) var(--ease-spring); }
.switch input:checked ~ .switch__track { background: var(--color-primary); border-color: var(--color-primary); }
.switch input:checked ~ .switch__thumb { transform: translateX(18px); }

.toggle-row {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row__label { font-size: 14px; font-weight: 600; }
.toggle-row__desc { font-size: 12px; color: var(--color-text-tertiary); margin-top: 2px; }

/* ============================================================
   Chips / Tabs
   ============================================================ */

.chip-row { display: flex; gap: var(--space-2); overflow-x: auto; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 var(--space-4);
    border-radius: var(--radius-full); background: var(--color-surface); border: 1.5px solid var(--color-border);
    font-size: 13px; font-weight: 600; color: var(--color-text-secondary); white-space: nowrap; flex-shrink: 0;
    transition: all var(--duration-fast) var(--ease-out);
}
.chip.is-active { background: var(--color-primary); border-color: var(--color-primary); color: white; }

.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-4); }
.tab-btn {
    padding: var(--space-3) var(--space-4); font-size: 13px; font-weight: 700; color: var(--color-text-tertiary);
    border-bottom: 2.5px solid transparent; transition: all var(--duration-fast) var(--ease-out);
}
.tab-btn.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ============================================================
   Icon picker / checkbox grid (agent forms)
   ============================================================ */

.icon-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: var(--space-2); }
.icon-picker__item {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 18px;
    border-radius: var(--radius-sm); background: var(--color-surface-2); transition: all var(--duration-fast) var(--ease-out);
}
.icon-picker__item.is-active { background: var(--color-primary-soft); outline: 2px solid var(--color-primary); }

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-2); }
.checkbox-pill {
    display: flex; align-items: center; gap: var(--space-2); padding: 8px 12px;
    border-radius: var(--radius-md); border: 1.5px solid var(--color-border); cursor: pointer; font-size: 13px; font-weight: 600;
    transition: all var(--duration-fast) var(--ease-out);
}
.checkbox-pill.is-active { border-color: var(--color-primary); background: var(--color-primary-soft); color: var(--color-primary); }
.checkbox-pill input { width: 0; height: 0; opacity: 0; position: absolute; }

/* ============================================================
   Empty / loading states
   ============================================================ */

.empty-state {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    padding: var(--space-8) var(--space-4); color: var(--color-text-secondary);
}
.empty-state__icon {
    width: 56px; height: 56px; border-radius: var(--radius-full); background: var(--color-surface-2);
    display: flex; align-items: center; justify-content: center; margin-bottom: var(--space-3); color: var(--color-text-tertiary);
}
.empty-state__icon svg { width: 24px; height: 24px; }
.empty-state__title { font-size: 15px; font-weight: 700; color: var(--color-text); margin-bottom: 2px; }
.empty-state__text { font-size: 12px; max-width: 280px; }

.spinner {
    width: 22px; height: 22px; border: 2.5px solid var(--color-border); border-top-color: var(--color-primary);
    border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.page-loading { display: flex; align-items: center; justify-content: center; padding: var(--space-8) 0; }

.skeleton {
    background: linear-gradient(90deg, var(--color-surface-2) 25%, var(--color-border) 37%, var(--color-surface-2) 63%);
    background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm);
}
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ============================================================
   Avatar / agent cards
   ============================================================ */

.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--color-surface-2); }
.avatar-sm { width: 32px; height: 32px; }
.avatar-md { width: 44px; height: 44px; }
.avatar-lg { width: 64px; height: 64px; }

.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-3); }

.agent-card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}
.agent-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.agent-card__top { display: flex; align-items: center; gap: var(--space-3); }
.agent-card__name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.agent-card__meta { font-size: 12px; color: var(--color-text-tertiary); }
.agent-card__stats { display: flex; gap: var(--space-4); }
.agent-card__stat-value { font-weight: 800; font-size: 15px; }
.agent-card__stat-label { font-size: 11px; color: var(--color-text-tertiary); }

.status-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block;
}
.status-dot.active { background: var(--color-success); }
.status-dot.paused { background: var(--color-warning); }
.status-dot.disabled { background: var(--color-text-tertiary); }

/* ============================================================
   Toasts
   ============================================================ */

.toast-container {
    position: fixed; top: var(--space-3); right: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2);
    z-index: var(--z-toast); pointer-events: none; max-width: 360px;
}
.toast {
    display: flex; align-items: center; gap: var(--space-3); background: var(--color-surface); border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); pointer-events: auto;
    animation: toast-in var(--duration-base) var(--ease-spring);
}
.toast.is-leaving { animation: toast-out var(--duration-base) var(--ease-out) forwards; }
@keyframes toast-in { from { opacity:0; transform: translateX(20px) scale(0.97); } to { opacity:1; transform: translateX(0) scale(1); } }
@keyframes toast-out { from { opacity:1; transform: translateX(0) scale(1); } to { opacity:0; transform: translateX(20px) scale(0.97); } }
.toast__icon { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: white; }
.toast__icon svg { width: 14px; height: 14px; }
.toast--success .toast__icon { background: var(--color-success); }
.toast--error .toast__icon { background: var(--color-danger); }
.toast--info .toast__icon { background: var(--color-primary); }
.toast--warning .toast__icon { background: var(--color-warning); }
.toast__message { flex: 1; font-size: 13px; font-weight: 500; }
.toast__close { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; color: var(--color-text-tertiary); border-radius: 50%; flex-shrink: 0; }
.toast__close svg { width: 14px; height: 14px; }

/* ============================================================
   Modals
   ============================================================ */

.modal-overlay {
    position: fixed; inset: 0; background: var(--color-overlay); z-index: var(--z-modal);
    display: flex; align-items: center; justify-content: center; opacity: 0;
    transition: opacity var(--duration-base) var(--ease-out); padding: var(--space-4);
}
.modal-overlay.is-open { opacity: 1; }
.modal-sheet {
    width: 100%; max-width: 520px; background: var(--color-surface); border-radius: var(--radius-lg);
    max-height: 88vh; display: flex; flex-direction: column;
    transform: scale(0.96); opacity: 0; transition: all var(--duration-base) var(--ease-spring);
}
.modal-overlay.is-open .modal-sheet { transform: scale(1); opacity: 1; }
.modal-sheet--lg { max-width: 680px; }
.modal-sheet__header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4); border-bottom: 1px solid var(--color-border); flex-shrink: 0; }
.modal-sheet__title { font-size: 16px; font-weight: 800; }
.modal-sheet__body { padding: var(--space-4); overflow-y: auto; flex: 1; }
.modal-sheet__footer { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); display: flex; gap: var(--space-3); justify-content: flex-end; flex-shrink: 0; }

/* ============================================================
   Utilities
   ============================================================ */

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); }
.mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); }
.text-sm { font-size: 12px; } .text-xs { font-size: 11px; } .text-lg { font-size: 16px; }
.text-secondary { color: var(--color-text-secondary); } .text-tertiary { color: var(--color-text-tertiary); }
.font-bold { font-weight: 700; } .font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.flex-1 { flex: 1; }
.relative { position: relative; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--color-border); margin: var(--space-3) 0; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
    .admin-sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .admin-sidebar.is-open { transform: translateX(0); }
    .admin-main { margin-left: 0; }
    .admin-menu-toggle { display: flex; }
    .field-row { grid-template-columns: 1fr; }
    .admin-content { padding: var(--space-3); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.admin-sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: var(--color-overlay); z-index: calc(var(--z-sidebar) - 1);
}
.admin-sidebar-overlay.is-open { display: block; }
