/* ============================================================
   Mailer Admin — Design System
   Industrial / data-dense aesthetic. Fira Code + Fira Sans.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
    --font-display: 'Fira Code', ui-monospace, 'SF Mono', Menlo, monospace;
    --font-sans: 'Fira Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --color-bg: #F8FAFC;
    --color-surface: #FFFFFF;
    --color-surface-2: #F1F5F9;
    --color-surface-3: #E2E8F0;
    --color-border: #E2E8F0;
    --color-border-strong: #CBD5E1;

    --color-text: #0F172A;
    --color-text-muted: #475569;
    --color-text-subtle: #64748B;

    --color-primary: #1E40AF;
    --color-primary-hover: #1D4ED8;
    --color-primary-soft: rgba(59,130,246,0.08);
    --color-accent: #3B82F6;
    --color-accent-hover: #2563EB;
    --color-warn: #F59E0B;
    --color-warn-hover: #D97706;
    --color-danger: #EF4444;
    --color-danger-hover: #DC2626;
    --color-success: #10B981;
    --color-success-hover: #059669;
    --color-purple: #8B5CF6;
    --color-purple-hover: #7C3AED;

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    --shadow-xs: 0 1px 2px rgba(15,23,42,0.04);
    --shadow-sm: 0 1px 3px rgba(15,23,42,0.05), 0 1px 2px rgba(15,23,42,0.03);
    --shadow-md: 0 4px 12px rgba(15,23,42,0.06);
    --shadow-lg: 0 12px 32px rgba(15,23,42,0.10);
    --shadow-focus: 0 0 0 3px rgba(59,130,246,0.18);

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

    --sidebar-w: 240px;
    --topbar-h: 56px;

    --z-dropdown: 20;
    --z-sidebar: 30;
    --z-topbar: 40;
    --z-overlay: 80;
    --z-modal: 90;
    --z-toast: 100;

    --duration-fast: 150ms;
    --duration: 200ms;
    --duration-slow: 300ms;
    --easing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { overflow-x: hidden; }
html { -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    background-image: radial-gradient(circle at 1px 1px, rgba(15,23,42,0.045) 1px, transparent 0);
    background-size: 24px 24px;
    background-attachment: fixed;
    min-height: 100vh;
    text-rendering: optimizeLegibility;
}

/* ---------- App shell (sidebar + topbar + main) ---------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

.app-sidebar {
    grid-area: sidebar;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
}

.app-topbar {
    grid-area: topbar;
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    gap: var(--space-4);
    min-height: var(--topbar-h);
}

.app-main {
    grid-area: main;
    padding: var(--space-6);
    min-width: 0; /* allow grid children to shrink */
    max-width: 100%;
}

@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: var(--topbar-h) 1fr;
        grid-template-areas: "topbar" "main";
    }
    .app-sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 280px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform var(--duration) var(--easing);
        box-shadow: var(--shadow-lg);
    }
    .app-sidebar.open { transform: translateX(0); }
    .app-sidebar-backdrop {
        position: fixed; inset: 0;
        background: rgba(15,23,42,0.45);
        z-index: calc(var(--z-sidebar) - 1);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--duration) var(--easing);
    }
    .app-sidebar.open + .app-sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 768px) {
    .app-main { padding: var(--space-4); }
    .app-topbar { padding: 0 var(--space-4); gap: var(--space-2); }
}

/* ---------- Sidebar brand & nav ---------- */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 var(--space-5);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    text-decoration: none;
    flex-shrink: 0;
}
.brand:hover { color: var(--color-text); }
.brand-mark {
    width: 26px; height: 26px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(30,64,175,0.25);
}

.nav-section {
    padding: var(--space-3) var(--space-3);
}
.nav-section-bottom {
    margin-top: auto;
    border-top: 1px solid var(--color-border);
}
.nav-section-title {
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-subtle);
    padding: 0 var(--space-3) var(--space-2);
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    position: relative;
    cursor: pointer;
    transition: background var(--duration-fast) var(--easing),
                color var(--duration-fast) var(--easing);
    margin-bottom: 1px;
}
.nav-item:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
.nav-item.active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 7px; bottom: 7px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--color-primary);
}
.nav-icon {
    width: 18px; height: 18px;
    flex-shrink: 0;
}

/* ---------- Topbar ---------- */
.topbar-burger {
    display: none;
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast), color var(--duration-fast);
}
.topbar-burger:hover { background: var(--color-surface-2); color: var(--color-text); }
@media (max-width: 1024px) {
    .topbar-burger { display: inline-flex; }
}

.topbar-titles { min-width: 0; flex: 1; }
.topbar-titles .page-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0;
    cursor: default;
    flex-shrink: 0;
}

/* ---------- Page header ---------- */
.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
    margin-bottom: var(--space-6);
}
.page-title {
    font-family: var(--font-display);
    font-size: 18px;
    line-height: 1.25;
    letter-spacing: -0.02em;
    font-weight: 600;
    color: var(--color-text);
}
.page-subtitle {
    color: var(--color-text-subtle);
    font-size: 12.5px;
    margin-top: 2px;
}
.page-actions {
    margin-left: auto;
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    min-height: 36px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--duration-fast),
                border-color var(--duration-fast),
                color var(--duration-fast),
                box-shadow var(--duration-fast);
}
.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}
.btn:disabled, .btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

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

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-surface-2); color: var(--color-text); }

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

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

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

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

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

.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 12px; }
.btn-lg { padding: 12px 20px; min-height: 44px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 36px; min-height: 36px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--space-4); }
.form-group:last-child { margin-bottom: 0; }
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}
.label {
    display: block;
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}
.help {
    display: block;
    font-size: 12px;
    color: var(--color-text-subtle);
    margin-top: 5px;
    line-height: 1.5;
}
.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--color-text-subtle); }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-focus);
}
.textarea { resize: vertical; min-height: 100px; font-family: var(--font-display); }
.input-mono { font-family: var(--font-display); }

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}
.checkbox-group input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

@media (max-width: 768px) {
    .input, .select, .textarea {
        font-size: 16px; /* prevent iOS focus zoom */
    }
}

/* ---------- Panels / cards ---------- */
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}
.panel + .panel { margin-top: var(--space-5); }
.panel-head {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--color-surface);
}
.panel-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--color-text);
}
.panel-subtitle { font-size: 12px; color: var(--color-text-subtle); }
.panel-actions { margin-left: auto; display: flex; gap: var(--space-2); }
.panel-body { padding: var(--space-5); }
.panel-flush > .panel-body { padding: 0; }

/* ---------- KPI cards ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}
.kpi {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-xs);
    position: relative;
    overflow: hidden;
}
.kpi::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 60px; height: 60px;
    background: radial-gradient(circle, var(--color-primary-soft), transparent 70%);
    pointer-events: none;
}
.kpi-label {
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-subtle);
    margin-bottom: 6px;
}
.kpi-value {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: -0.02em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.kpi-value.success { color: var(--color-success); }
.kpi-value.danger  { color: var(--color-danger); }
.kpi-value.warn    { color: var(--color-warn); }
.kpi-value.info    { color: var(--color-accent); }
.kpi-delta { font-size: 12px; margin-top: 4px; color: var(--color-text-subtle); }
.kpi-delta.up   { color: var(--color-success); }
.kpi-delta.down { color: var(--color-danger); }

/* ---------- Tables ---------- */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th, .table td {
    padding: 11px var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table th {
    font-family: var(--font-display);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-subtle);
    font-weight: 500;
    background: var(--color-surface-2);
    white-space: nowrap;
}
.table tbody tr {
    transition: background var(--duration-fast);
}
.table tbody tr:hover { background: var(--color-surface-2); }
.table .num,
.table .mono {
    font-family: var(--font-display);
    font-variant-numeric: tabular-nums;
}
.table .num { text-align: right; }
.table .clickable { cursor: pointer; }
.table .clickable:hover { background: var(--color-surface-2); }
.table-zebra tbody tr:nth-child(even) { background: rgba(241,245,249,0.5); }
.table-zebra tbody tr:hover { background: var(--color-surface-2); }
.table .truncate {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    border-radius: var(--radius-pill);
    background: var(--color-surface-2);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    white-space: nowrap;
}
.badge-success { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.badge-danger  { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.badge-warn    { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }
.badge-info    { background: #EFF6FF; color: #1E40AF; border-color: #BFDBFE; }
.badge-purple  { background: #F5F3FF; color: #5B21B6; border-color: #DDD6FE; }
.badge-mute    { background: var(--color-surface-2); color: var(--color-text-subtle); border-color: var(--color-border); }
.badge-dot::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

/* ---------- Tabs (subnav) ---------- */
.tabs {
    display: flex;
    gap: 2px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: var(--space-5);
    overflow-x: auto;
    scrollbar-width: thin;
}
.tab {
    padding: 8px var(--space-4);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--duration-fast), color var(--duration-fast);
    flex-shrink: 0;
}
.tab:hover { background: var(--color-surface-2); color: var(--color-text); }
.tab.active { background: var(--color-primary); color: #fff; }
.tab.active:hover { color: #fff; }

/* ---------- Section divider inside a panel body ---------- */
.panel-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-5) 0 var(--space-4);
}
.section-title {
    font-family: var(--font-display);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-subtle);
    margin-bottom: var(--space-3);
}

/* ---------- Progress bar ---------- */
.progress {
    height: 6px;
    background: var(--color-surface-3);
    border-radius: var(--radius-pill);
    overflow: hidden;
    width: 100%;
}
.progress-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: var(--radius-pill);
    transition: width var(--duration-slow) var(--easing);
}
.progress-fill.success { background: var(--color-success); }
.progress-fill.warn    { background: var(--color-warn); }
.progress-fill.danger  { background: var(--color-danger); }
.progress-lg { height: 24px; }
.progress-lg .progress-fill {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 500;
}

/* ---------- Toast / message ---------- */
.msg {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
}
.msg-ok  { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.msg-err { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.msg-warn { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }
.msg-info { background: #EFF6FF; color: #1E3A8A; border-color: #BFDBFE; }

/* ---------- Auth shell (login, oauth) ---------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-6);
    background:
        radial-gradient(circle at 20% 25%, rgba(59,130,246,0.10), transparent 45%),
        radial-gradient(circle at 80% 75%, rgba(245,158,11,0.06), transparent 45%),
        var(--color-bg);
}
.auth-card {
    width: 100%;
    max-width: 460px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-6) var(--space-8) var(--space-8);
}
@media (max-width: 480px) {
    .auth-card { padding: var(--space-5) var(--space-5) var(--space-6); }
}
.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: var(--space-5);
    height: 32px;
}
.auth-brand .brand-mark { width: 28px; height: 28px; font-size: 12px; border-radius: var(--radius-sm); }
.auth-brand-name {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.02em;
}
.auth-title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
    text-align: center;
    margin-bottom: 6px;
}
.auth-subtitle {
    text-align: center;
    color: var(--color-text-subtle);
    margin-bottom: var(--space-6);
    font-size: 13px;
}

/* ---------- Misc utility ---------- */
.muted     { color: var(--color-text-subtle); }
.subtle    { color: var(--color-text-muted); }
.mono      { font-family: var(--font-display); }
.tabular   { font-variant-numeric: tabular-nums; }
.truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex      { display: flex; }
.flex-col  { flex-direction: column; }
.flex-1    { flex: 1; }
.gap-1     { gap: var(--space-1); }
.gap-2     { gap: var(--space-2); }
.gap-3     { gap: var(--space-3); }
.gap-4     { gap: var(--space-4); }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.text-right { text-align: right; }
.text-center{ text-align: center; }
.w-full    { width: 100%; }
.hidden    { display: none !important; }

.mt-0 { margin-top: 0; }
.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); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }

/* ---------- Grid helpers ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-5); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-5); }
@media (max-width: 900px)  { .grid-2 { grid-template-columns: 1fr; } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Pager ---------- */
.pager {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: var(--space-3) 0 var(--space-5);
    flex-wrap: wrap;
}
.pager a, .pager span {
    padding: 6px 12px;
    min-width: 36px;
    text-align: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 13px;
    font-family: var(--font-display);
    transition: background var(--duration-fast), color var(--duration-fast);
}
.pager a:hover { background: var(--color-surface-2); color: var(--color-text); }
.pager .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Modal / overlay (carried over from spam) ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
}
.overlay.open { display: flex; }
.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-head {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
}
.modal-body { padding: var(--space-5); overflow: auto; }
.modal-foot {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    background: var(--color-surface-2);
}
.modal-close {
    background: transparent;
    border: none;
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    color: var(--color-text-subtle);
    display: grid; place-items: center;
    cursor: pointer;
    transition: background var(--duration-fast), color var(--duration-fast);
}
.modal-close:hover { background: var(--color-surface-2); color: var(--color-text); }
.modal-sm { width: 420px; max-width: 95vw; }
.modal-md { width: 560px; max-width: 95vw; }
.modal-lg { width: 800px; max-width: 95vw; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-6);
    color: var(--color-text-subtle);
}
.empty-state-icon {
    width: 48px; height: 48px;
    margin: 0 auto var(--space-3);
    color: var(--color-text-subtle);
    opacity: 0.5;
}
.empty-state-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}
.empty-state-help {
    font-size: 13px;
    line-height: 1.5;
    max-width: 360px;
    margin: 0 auto var(--space-4);
}

/* ---------- Sortable table headers ---------- */
.sortable-th {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background var(--duration-fast), color var(--duration-fast);
}
.sortable-th:hover { background: var(--color-surface-3); color: var(--color-text); }
.sortable-th::after {
    content: '';
    display: inline-block;
    width: 0; height: 0;
    margin-left: 6px;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 4px solid currentColor;
    opacity: 0.3;
    vertical-align: middle;
}
.sortable-th.sort-asc::after { border-top: none; border-bottom: 4px solid currentColor; opacity: 1; }
.sortable-th.sort-desc::after { opacity: 1; }

/* ---------- Filter bar (sticky chips) ---------- */
.filter-bar {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-xs);
    position: sticky;
    top: var(--topbar-h);
    z-index: var(--z-dropdown);
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border-radius: var(--radius-pill);
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 500;
}
.filter-chip-x {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    width: 14px; height: 14px;
    display: grid; place-items: center;
    border-radius: 50%;
    opacity: 0.6;
    transition: opacity var(--duration-fast);
}
.filter-chip-x:hover { opacity: 1; background: rgba(59,130,246,0.15); }
.filter-clear {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--color-text-subtle);
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
    padding: 4px 8px;
}
.filter-clear:hover { color: var(--color-text); }

/* ---------- Timeline (drill-down detail) ---------- */
.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
    position: relative;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 11px; top: 8px; bottom: 8px;
    width: 2px;
    background: var(--color-border);
    border-radius: 1px;
}
.timeline-item {
    position: relative;
    padding-left: var(--space-8);
    padding-bottom: var(--space-4);
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: 6px; top: 6px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 2px solid var(--color-border-strong);
    box-sizing: border-box;
}
.timeline-item.success::before { border-color: var(--color-success); background: var(--color-success); }
.timeline-item.danger::before  { border-color: var(--color-danger);  background: var(--color-danger); }
.timeline-item.warn::before    { border-color: var(--color-warn);    background: var(--color-warn); }
.timeline-item.info::before    { border-color: var(--color-accent);  background: var(--color-accent); }
.timeline-time {
    font-family: var(--font-display);
    font-size: 11px;
    color: var(--color-text-subtle);
    margin-bottom: 2px;
}
.timeline-title {
    font-weight: 500;
    font-size: 13.5px;
    color: var(--color-text);
}
.timeline-desc {
    font-size: 12.5px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ---------- Toast ---------- */
.toast-region {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    min-width: 240px;
    max-width: 360px;
    padding: 10px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    color: var(--color-text);
    transform: translateX(20px);
    opacity: 0;
    animation: toast-in var(--duration) var(--easing) forwards;
}
.toast.success { border-left-color: var(--color-success); }
.toast.danger  { border-left-color: var(--color-danger); }
.toast.warn    { border-left-color: var(--color-warn); }
.toast.fade-out { animation: toast-out var(--duration) var(--easing) forwards; }
@keyframes toast-in {
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
    to { transform: translateX(20px); opacity: 0; }
}

/* ---------- Code block ---------- */
.code-block {
    background: #0F172A;
    color: #E2E8F0;
    font-family: var(--font-display);
    font-size: 13px;
    line-height: 1.55;
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-md);
    overflow-x: auto;
    white-space: pre;
    position: relative;
}
.code-block-copy {
    position: absolute;
    top: 8px; right: 8px;
    padding: 4px 8px;
    background: rgba(255,255,255,0.08);
    color: #E2E8F0;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-xs);
    font-family: var(--font-display);
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--duration-fast), background var(--duration-fast);
}
.code-block:hover .code-block-copy { opacity: 1; }
.code-block-copy:hover { background: rgba(255,255,255,0.18); }
.code-block-copy.copied { background: var(--color-success); color: #fff; border-color: var(--color-success); opacity: 1; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- Print ---------- */
@media print {
    .app-sidebar, .app-topbar, .page-actions, .pager { display: none !important; }
    .app-shell { display: block; }
    .app-main { padding: 0; }
}
