/* ==========================================================================
   GlobalDebrid v16 — Design System (base.css)
   Tokens · reset · typography · layout · components
   Mobile-first. Light + dark via [data-theme].
   ========================================================================== */

:root {
    /* Brand */
    --brand-50: #eef2ff;
    --brand-100: #e0e7ff;
    --brand-200: #c7d2fe;
    --brand-300: #a5b4fc;
    --brand-400: #818cf8;
    --brand-500: #6366f1;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;
    --brand-800: #3730a3;
    --accent-500: #0ea5e9;
    --accent-600: #0284c7;

    /* Semantic */
    --success-500: #10b981;
    --success-600: #059669;
    --warning-500: #f59e0b;
    --warning-600: #d97706;
    --danger-500: #ef4444;
    --danger-600: #dc2626;
    --info-500: #3b82f6;

    /* Surfaces (light) */
    --bg: #f5f6fa;
    --bg-elev: #eef0f6;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #f1f3f9;
    --border: #e4e7ee;
    --border-strong: #d2d6e0;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;
    --text-inverse: #ffffff;

    --primary: var(--brand-600);
    --primary-hover: var(--brand-700);
    --primary-soft: rgba(79, 70, 229, 0.10);
    --primary-ring: rgba(79, 70, 229, 0.28);

    --success: var(--success-600);
    --success-soft: rgba(16, 185, 129, 0.12);
    --warning: var(--warning-600);
    --warning-soft: rgba(245, 158, 11, 0.14);
    --danger: var(--danger-600);
    --danger-soft: rgba(239, 68, 68, 0.12);
    --info: var(--info-500);
    --info-soft: rgba(59, 130, 246, 0.12);

    /* Shape */
    --r-xs: 6px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 24px;
    --r-full: 999px;

    /* Elevation */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 6px 16px -4px rgba(15, 23, 42, 0.10), 0 2px 6px -2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 16px 40px -8px rgba(15, 23, 42, 0.16);
    --shadow-xl: 0 32px 64px -16px rgba(15, 23, 42, 0.24);

    /* Type */
    --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
    --fs-xs: 0.75rem;    /* 12 */
    --fs-sm: 0.8125rem;  /* 13 */
    --fs-base: 0.9375rem;/* 15 */
    --fs-md: 1rem;
    --fs-lg: 1.125rem;   /* 18 */
    --fs-xl: 1.375rem;   /* 22 */
    --fs-2xl: 1.75rem;   /* 28 */
    --fs-3xl: 2.25rem;   /* 36 */
    --fs-4xl: 3rem;      /* 48 */

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --t-fast: 140ms var(--ease);
    --t-base: 200ms var(--ease);
    --t-slow: 320ms var(--ease);

    /* Layout */
    --container: 1180px;
    --sidebar-w: 256px;
    --sidebar-w-collapsed: 72px;
    --topbar-h: 60px;

    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0b0f1a;
    --bg-elev: #0f1524;
    --surface: #111827;
    --surface-2: #161e30;
    --surface-3: #1c2538;
    --border: #232c40;
    --border-strong: #2f3a52;
    --text: #f1f5f9;
    --text-2: #a5b1c5;
    --text-3: #6b7a93;

    --primary: var(--brand-400);
    --primary-hover: var(--brand-300);
    --primary-soft: rgba(129, 140, 248, 0.16);
    --primary-ring: rgba(129, 140, 248, 0.35);

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.16);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.16);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.16);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, 0.16);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 8px 20px -6px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, 0.65);
    --shadow-xl: 0 32px 72px -16px rgba(0, 0, 0, 0.75);

    color-scheme: dark;
}

/* --------------------------------------------------------------------------
   Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
img, svg, video { display: block; max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
h1, h2, h3, h4, h5 { line-height: 1.2; letter-spacing: -0.015em; font-weight: 700; color: var(--text); }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p { color: var(--text-2); }
code, pre, kbd { font-family: var(--mono); font-size: 0.9em; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--r-xs); }
::selection { background: var(--primary-soft); }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 20px; }
@media (min-width: 640px) { .container { padding: 0 28px; } }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-xs { font-size: var(--fs-xs); } .text-sm { font-size: var(--fs-sm); } .text-lg { font-size: var(--fs-lg); }
.text-2 { color: var(--text-2); } .text-3 { color: var(--text-3); }
.text-center { text-align: center; } .text-right { text-align: right; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { overflow-wrap: anywhere; word-break: break-word; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.hide-mobile { display: none !important; }
@media (min-width: 761px) and (max-width: 1360px) { .col-opt { display: none !important; } }
@media (min-width: 640px) { .hide-mobile { display: revert !important; } .hide-desktop { display: none !important; } }
.tabular { font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--border); border: 0; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.w-full { width: 100%; }
.relative { position: relative; }

/* Icons */
.icon { width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }
.icon-xl { width: 28px; height: 28px; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 0 16px;
    border-radius: var(--r-sm); border: 1px solid transparent;
    font-size: var(--fs-sm); font-weight: 600; line-height: 1; letter-spacing: 0.005em;
    white-space: nowrap; user-select: none;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
    text-decoration: none !important;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); box-shadow: 0 4px 14px var(--primary-ring); }
[data-theme="dark"] .btn-primary { color: #0b0f1a; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-soft:hover:not(:disabled) { background: var(--primary); color: #fff; }
[data-theme="dark"] .btn-soft:hover:not(:disabled) { color: #0b0f1a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.94); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(0.94); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-xs); border-radius: var(--r-xs); gap: 6px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-lg { min-height: 48px; padding: 0 24px; font-size: var(--fs-base); border-radius: var(--r-md); }
.btn-icon { width: 40px; min-width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; min-width: 32px; }
.btn-block { width: 100%; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.label .req { color: var(--danger); margin-left: 2px; }
.help { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.45; }
.input, .select, .textarea {
    width: 100%; min-height: 42px; padding: 9px 12px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--r-sm);
    font-size: var(--fs-base); line-height: 1.4;
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
    appearance: none; -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.input[readonly] { background: var(--surface-2); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.input-sm, .select-sm { min-height: 34px; padding: 5px 10px; font-size: var(--fs-sm); }
.textarea { min-height: 110px; resize: vertical; font-family: var(--font); }
.textarea.mono { font-family: var(--mono); font-size: var(--fs-sm); }
.select {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .icon { position: absolute; left: 12px; color: var(--text-3); pointer-events: none; }
.input-group > .input { padding-left: 38px; }
.input-group > .input-action { position: absolute; right: 6px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .input { flex: 1; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } }
.form-grid .field + .field { margin-top: 0; }
.error-text { font-size: var(--fs-xs); color: var(--danger); font-weight: 500; }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-sm); color: var(--text-2); }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; width: 44px; height: 26px; flex: 0 0 auto; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: var(--r-full); transition: background var(--t-base); }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform var(--t-base); }
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--primary-ring); }
.switch input:disabled + .track { opacity: 0.5; cursor: not-allowed; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; padding-bottom: 0; }
.switch-row:first-child { padding-top: 0; }
.switch-row .switch-text { min-width: 0; }
.switch-row .switch-title { font-weight: 600; font-size: var(--fs-sm); color: var(--text); }
.switch-row .switch-desc { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; line-height: 1.45; }
.switch-row .switch-state { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); min-width: 56px; text-align: right; }
.switch-row .switch-state.on { color: var(--success); }
.switch-row .switch-state.off { color: var(--text-3); }

/* --------------------------------------------------------------------------
   Cards / panels
   -------------------------------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
}
.card-body { padding: 20px; }
@media (min-width: 640px) { .card-body { padding: 24px; } }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 0; flex-wrap: wrap; }
@media (min-width: 640px) { .card-header { padding: 20px 24px 0; } }
.card-header + .card-body { padding-top: 16px; }
.card-title { font-size: var(--fs-md); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-title .icon { color: var(--primary); }
.card-sub { font-size: var(--fs-xs); color: var(--text-3); margin-top: 3px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.card-compact .card-body { padding: 16px; }
.card-flat { box-shadow: none; }
.card-soft { background: var(--surface-2); }

/* Stat tile */
.stat {
    display: flex; flex-direction: column; gap: 10px; padding: 18px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
    min-width: 0;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.stat-icon { width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: var(--fs-xs); color: var(--text-3); }
.stat-sub .up { color: var(--success); font-weight: 600; }
.stat-sub .down { color: var(--danger); font-weight: 600; }
.stats-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
.stats-grid.cols-3 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 640px) { .stats-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* --------------------------------------------------------------------------
   Badges / pills
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: var(--r-full);
    font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2); border: 1px solid transparent;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-outline { background: transparent; border-color: var(--border-strong); }
.badge-role-user { background: var(--surface-3); color: var(--text-2); }
.badge-role-pro { background: var(--info-soft); color: var(--info); }
.badge-role-premium { background: var(--warning-soft); color: var(--warning); }
.badge-role-admin { background: var(--primary-soft); color: var(--primary); }
.badge-lg { padding: 6px 12px; font-size: var(--fs-sm); }

/* --------------------------------------------------------------------------
   Tables (desktop) + card mode (mobile)
   -------------------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-md); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.table th {
    text-align: left; font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--text-3); padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border);
    white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { display: inline-block; margin-left: 4px; opacity: 0.5; font-size: 10px; }
.table th.sorted .sort-ind { opacity: 1; color: var(--primary); }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.actions { text-align: right; white-space: nowrap; }
.table .cell-main { font-weight: 600; color: var(--text); }
.table .cell-sub { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.table .cell-trunc { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tr.is-pending td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.table tr.is-disabled td { opacity: 0.7; }
.row-actions { display: inline-flex; gap: 4px; }
.row-actions .btn-icon { color: var(--text-2); }
.row-actions .btn-icon:hover { color: var(--text); }
.row-actions .btn-icon.danger:hover { color: var(--danger); background: var(--danger-soft); }

/* Card-mode: at ≤ 760px tables with .table-cards become stacked cards */
@media (max-width: 760px) {
    .table-cards { border-spacing: 0 10px; }
    .table-cards thead { display: none; }
    .table-cards tbody, .table-cards tr, .table-cards td { display: block; }
    .table-cards tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 8px 14px; box-shadow: var(--shadow-xs); }
    .table-cards tbody tr:hover { background: var(--surface); }
    .table-cards td { border: 0; padding: 7px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
    .table-cards td::before { content: attr(data-label); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); text-align: left; flex: 0 0 auto; }
    .table-cards td.cell-title { display: block; text-align: left; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
    .table-cards td.cell-title::before { display: none; }
    .table-cards td.actions { justify-content: flex-end; padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--border); }
    .table-cards td.actions::before { display: none; }
    .table-cards td.num { text-align: right; }
    .table-cards .cell-trunc { max-width: 60vw; }
    .table-cards tr.is-pending td:first-child { box-shadow: none; }
    .table-cards tr.is-pending { border-left: 3px solid var(--warning); }
    .table-cards td.empty-cell { display: block; text-align: center; }
    .table-cards td.empty-cell::before { display: none; }
}

/* Pagination */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 0; flex-wrap: wrap; }
.pager-info { font-size: var(--fs-xs); color: var(--text-3); }
.pager-controls { display: inline-flex; gap: 6px; align-items: center; }
.pager-controls .page-num { min-width: 34px; height: 34px; padding: 0 8px; display: inline-grid; place-items: center; font-size: var(--fs-sm); font-weight: 600; border-radius: var(--r-xs); color: var(--text-2); }
.pager-controls .page-num.active { background: var(--primary); color: #fff; }
[data-theme="dark"] .pager-controls .page-num.active { color: #0b0f1a; }
.pager-controls .page-num:hover:not(.active) { background: var(--surface-3); }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .input-group { flex: 1 1 220px; min-width: 0; }
.toolbar .select { width: auto; min-width: 130px; flex: 0 1 auto; }
.toolbar .spacer { flex: 1 1 auto; }
@media (max-width: 640px) {
    .toolbar .select { flex: 1 1 calc(50% - 5px); min-width: 0; }
    .toolbar .btn:not(.btn-icon) { flex: 1 1 100%; }
    .toolbar .input-group { flex: 1 1 100%; }
}

/* --------------------------------------------------------------------------
   Empty / loading states
   -------------------------------------------------------------------------- */
.empty { text-align: center; padding: 44px 20px; color: var(--text-3); }
.empty .empty-icon { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: var(--r-md); background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); }
.empty h4 { font-size: var(--fs-md); color: var(--text); margin-bottom: 4px; }
.empty p { font-size: var(--fs-sm); max-width: 380px; margin: 0 auto; }
.empty .btn { margin-top: 16px; }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: var(--r-xs); color: transparent !important; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent); animation: shimmer 1.4s infinite; }
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skel-line { height: 12px; margin: 8px 0; }
.skel-line.w-40 { width: 40%; } .skel-line.w-60 { width: 60%; } .skel-line.w-80 { width: 80%; }

/* Alerts */
.alert { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-sm); line-height: 1.5; }
.alert .icon { margin-top: 1px; flex: 0 0 auto; }
.alert-title { font-weight: 700; margin-bottom: 2px; color: inherit; }
.alert p { color: inherit; opacity: 0.9; }
.alert-info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.alert-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
[data-theme="light"] .alert-info, :root:not([data-theme="dark"]) .alert-info { color: #1d4ed8; }
:root:not([data-theme="dark"]) .alert-success { color: #047857; }
:root:not([data-theme="dark"]) .alert-warning { color: #b45309; }
:root:not([data-theme="dark"]) .alert-danger { color: #b91c1c; }

/* Progress */
.progress { height: 8px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: var(--r-full); transition: width var(--t-slow); }
.progress.warning > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }
.progress.success > span { background: var(--success); }

/* Ring */
.ring { position: relative; width: 84px; height: 84px; flex: 0 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; stroke-linecap: round; }
.ring .ring-bg { stroke: var(--surface-3); }
.ring .ring-fg { stroke: var(--primary); stroke-dasharray: 226; stroke-dashoffset: 226; transition: stroke-dashoffset var(--t-slow); }
.ring.warning .ring-fg { stroke: var(--warning); }
.ring.danger .ring-fg { stroke: var(--danger); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 700; font-size: var(--fs-md); line-height: 1; }
.ring-label small { display: block; font-size: 10px; color: var(--text-3); font-weight: 600; margin-top: 3px; text-transform: uppercase; letter-spacing: 0.05em; }

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: -1px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-3); border-bottom: 2px solid transparent; white-space: nowrap; transition: color var(--t-fast), border-color var(--t-fast); }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count { background: var(--surface-3); color: var(--text-2); font-size: 11px; padding: 1px 7px; border-radius: var(--r-full); }
.tab.active .count { background: var(--primary-soft); color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { padding: 6px 14px; border-radius: var(--r-xs); font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); transition: all var(--t-fast); min-height: 32px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* --------------------------------------------------------------------------
   Modal / drawer / toast
   -------------------------------------------------------------------------- */
.overlay { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.55); backdrop-filter: blur(3px); z-index: 90; opacity: 0; transition: opacity var(--t-base); }
.overlay.show { opacity: 1; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; padding: 0; pointer-events: none; }
@media (min-width: 640px) { .modal { align-items: center; padding: 24px; } }
.modal-panel {
    width: 100%; max-width: 560px; max-height: min(92dvh, 860px); display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-xl); pointer-events: auto;
    transform: translateY(24px); opacity: 0; transition: transform var(--t-slow), opacity var(--t-base);
}
@media (min-width: 640px) { .modal-panel { border-radius: var(--r-xl); } }
.modal.show .modal-panel { transform: translateY(0); opacity: 1; }
.modal-panel.lg { max-width: 760px; }
.modal-panel.sm { max-width: 440px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 0; }
@media (min-width: 640px) { .modal-head { padding: 22px 24px 0; } }
.modal-title { font-size: var(--fs-lg); font-weight: 700; }
.modal-sub { font-size: var(--fs-xs); color: var(--text-3); margin-top: 3px; }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1 1 auto; }
@media (min-width: 640px) { .modal-body { padding: 20px 24px; } }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@media (min-width: 640px) { .modal-foot { padding: 16px 24px 22px; } }
@media (max-width: 639px) { .modal-foot .btn { flex: 1 1 auto; } .modal-body { padding-bottom: max(18px, env(safe-area-inset-bottom)); } }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 100; width: 100%; max-width: 480px; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-xl); display: flex; flex-direction: column; transform: translateX(100%); transition: transform var(--t-slow); }
.drawer.show { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 16px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.toasts { position: fixed; z-index: 200; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
@media (min-width: 640px) { .toasts { left: auto; right: 20px; bottom: 20px; width: 380px; } }
.toast {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--primary);
    border-radius: var(--r-md); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); pointer-events: auto;
    transform: translateY(12px); opacity: 0; transition: transform var(--t-base), opacity var(--t-base);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast .icon { margin-top: 1px; flex: 0 0 auto; }
.toast-success { border-left-color: var(--success); } .toast-success .icon { color: var(--success); }
.toast-error { border-left-color: var(--danger); } .toast-error .icon { color: var(--danger); }
.toast-warning { border-left-color: var(--warning); } .toast-warning .icon { color: var(--warning); }
.toast-info .icon { color: var(--primary); }
.toast-msg { flex: 1; line-height: 1.45; overflow-wrap: anywhere; }
.toast-msg b { display: block; font-weight: 700; margin-bottom: 1px; }
.toast .close { color: var(--text-3); padding: 2px; border-radius: 4px; }
.toast .close:hover { color: var(--text); background: var(--surface-3); }

/* Description list */
.dl { display: grid; grid-template-columns: 1fr; gap: 0; }
.dl > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--text-3); font-weight: 500; flex: 0 0 auto; }
.dl dd { color: var(--text); font-weight: 600; text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* Code block */
.code { background: #0f172a; color: #e2e8f0; border-radius: var(--r-md); padding: 14px 16px; font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.6; overflow-x: auto; position: relative; }
[data-theme="dark"] .code { background: #060a14; border: 1px solid var(--border); }
.code .copy-btn { position: absolute; top: 8px; right: 8px; color: #94a3b8; background: rgba(255,255,255,0.06); border-radius: 6px; width: 30px; height: 30px; display: grid; place-items: center; }
.code .copy-btn:hover { color: #fff; background: rgba(255,255,255,0.14); }
.kbd { display: inline-block; padding: 1px 6px; font-size: 11px; font-family: var(--mono); background: var(--surface-3); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; color: var(--text-2); }

/* Avatar */
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: var(--fs-sm); flex: 0 0 auto; text-transform: uppercase; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 52px; height: 52px; font-size: var(--fs-lg); }

/* Theme toggle */
.theme-toggle { position: relative; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* Copy field */
.copy-field { display: flex; gap: 8px; align-items: center; }
.copy-field .input { font-family: var(--mono); font-size: var(--fs-sm); }

/* Animations */
.fade-in { animation: fadeIn var(--t-slow) both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 var(--success-soft); animation: pulse 1.8s infinite; display: inline-block; }
.pulse-dot.off { background: var(--danger); animation: none; }
.pulse-dot.warn { background: var(--warning); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); } 70% { box-shadow: 0 0 0 8px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
