/* =====================================================================
   Media Warehouse — theming layer
   Loaded AFTER app.css. Three sections:
     1. TOKENS      — accent palettes + light/dark surface tokens
     2. RETOKENIZE  — re-declares the few app.css rules that hard-coded the
                      teal brand colors, so accent switching works everywhere
     3. DARK        — surface overrides for the dark mode only
   The <html> element carries:
     data-theme="light|dark"        (resolved mode — what CSS reacts to)
     data-theme-pref="light|dark|auto"
     data-accent="teal|blue|indigo|violet|emerald|amber|rose"
   ===================================================================== */

/* =====================================================================
   1. TOKENS
   ===================================================================== */
:root {
  /* Neutral surface ladder — light values match the original stylesheet. */
  --surface-1: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --surface-4: #eef2f6;
  --surface-track: #e8edf4;
  --surface: var(--surface-1);
  --th-bg: #f6f9fc;
  --border-strong: #cbd5e1;
  --border-hover: #cde5e0;
  --on-primary: #ffffff;

  --topbar-bg: rgba(255, 255, 255, 0.82);
  --topbar-inset: rgba(255, 255, 255, 0.6);
  --glass: rgba(255, 255, 255, 0.95);
  --glass-soft: rgba(255, 255, 255, 0.65);
  --overlay: rgba(9, 16, 32, 0.55);
  --backdrop: rgba(15, 23, 42, 0.5);
  --scroll-thumb: #c3cdd9;
  --scroll-thumb-hover: #94a3b8;

  --bg-glow-1: #dcf2ee;
  --bg-glow-2: #e4e9fb;
  --bg-glow-3: #eaf5f2;

  --modal-head-1: #ffffff;
  --modal-head-2: #f8fcfb;
  --grabber: #d4dbe3;

  --ph-1: #f8fafc;
  --ph-2: #eef2f6;
  --ph-fg: #cbd5e1;

  --skeleton-1: #eef2f6;
  --skeleton-2: #f8fafc;

  --danger-ink: #9f1239;
  --danger-border: #fecdd3;
  --success-ink: #166534;
  --success-border: #bbf7d0;
  --warning-ink: #92400e;
  --info-soft: #e0f2fe;
  --info-ink: #075985;
  --info-border: #bae6fd;
  --amber-1: #fffbeb;
  --amber-2: #fefce8;
  --amber-3: #fef3c7;
  --amber-border: #fcd34d;
  --amber-ink: #78350f;
  --custody-bg: #fffdf5;

  --shadow-ink: 15, 23, 42;

  /* Login screen backdrop */
  --login-1: var(--primary-dark);
  --login-2: #0b4f4a;
  --login-3: #0e3a52;
  --login-card: rgba(255, 255, 255, 0.98);

  color-scheme: light;
}

/* ---------- Accent palettes ---------------------------------------------
   Each accent supplies the brand ramp + an rgb triplet used for glows and
   an "ink" value (primary tuned for text on light surfaces). */
:root,
html[data-accent="teal"] {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-darker: #115e59;
  --primary-light: #ccfbf1;
  --primary-50: #f0fdfa;
  --primary-rgb: 13 148 136;
  --primary-bright: #14b8a6;
  --primary-glow: #2dd4bf;
  --primary-tint: #5eead4;
  --primary-ink: var(--primary-dark);
}
html[data-accent="blue"] {
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-darker: #075985;
  --primary-light: #d8eefc;
  --primary-50: #f0f9ff;
  --primary-rgb: 2 132 199;
  --primary-bright: #0ea5e9;
  --primary-glow: #38bdf8;
  --primary-tint: #7dd3fc;
  --primary-ink: var(--primary-dark);
  --login-2: #0b3a5e;
  --login-3: #10243f;
  --border-hover: #cddfee;
}
html[data-accent="indigo"] {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-darker: #3730a3;
  --primary-light: #e0e7ff;
  --primary-50: #f5f5ff;
  --primary-rgb: 79 70 229;
  --primary-bright: #6366f1;
  --primary-glow: #818cf8;
  --primary-tint: #a5b4fc;
  --primary-ink: var(--primary-dark);
  --login-2: #29257a;
  --login-3: #1e1b4b;
  --border-hover: #d6d8f2;
}
html[data-accent="violet"] {
  --primary: #9333ea;
  --primary-dark: #7e22ce;
  --primary-darker: #6b21a8;
  --primary-light: #f3e0ff;
  --primary-50: #faf5ff;
  --primary-rgb: 147 51 234;
  --primary-bright: #a855f7;
  --primary-glow: #c084fc;
  --primary-tint: #d8b4fe;
  --primary-ink: var(--primary-dark);
  --login-2: #55217f;
  --login-3: #2e1065;
  --border-hover: #e6d4f2;
}
html[data-accent="emerald"] {
  --primary: #059669;
  --primary-dark: #047857;
  --primary-darker: #065f46;
  --primary-light: #d1fae5;
  --primary-50: #ecfdf5;
  --primary-rgb: 5 150 105;
  --primary-bright: #10b981;
  --primary-glow: #34d399;
  --primary-tint: #6ee7b7;
  --primary-ink: var(--primary-dark);
  --login-2: #064e3b;
  --login-3: #0b3b48;
  --border-hover: #cbe8da;
}
html[data-accent="amber"] {
  --primary: #d97706;
  --primary-dark: #b45309;
  --primary-darker: #92400e;
  --primary-light: #fef0c7;
  --primary-50: #fffbeb;
  --primary-rgb: 217 119 6;
  --primary-bright: #f59e0b;
  --primary-glow: #fbbf24;
  --primary-tint: #fcd34d;
  --primary-ink: var(--primary-dark);
  --login-2: #7c3d0a;
  --login-3: #3f2a12;
  --border-hover: #f0e1c2;
}
html[data-accent="rose"] {
  --primary: #e11d48;
  --primary-dark: #be123c;
  --primary-darker: #9f1239;
  --primary-light: #ffe4e6;
  --primary-50: #fff1f2;
  --primary-rgb: 225 29 72;
  --primary-bright: #f43f5e;
  --primary-glow: #fb7185;
  --primary-tint: #fda4af;
  --primary-ink: var(--primary-dark);
  --login-2: #86163a;
  --login-3: #4c1130;
  --border-hover: #f5d3d9;
}

/* Accent-derived shadows / glows (were hard-coded teal). */
:root {
  --shadow-primary: 0 8px 20px rgb(var(--primary-rgb) / 0.28);
  --glow-primary: 0 0 0 4px rgb(var(--primary-rgb) / 0.12);
  --shadow-primary-hover: 0 10px 26px rgb(var(--primary-rgb) / 0.36);
}

/* =====================================================================
   2. RETOKENIZE — same visual result in light mode, accent-aware
   ===================================================================== */
body {
  background-image: radial-gradient(1100px 560px at 100% -10%, var(--bg-glow-1) 0%, transparent 55%),
                    radial-gradient(900px 520px at -10% 110%, var(--bg-glow-2) 0%, transparent 50%),
                    radial-gradient(700px 400px at 55% 120%, var(--bg-glow-3) 0%, transparent 45%);
}

*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); }
*::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

a { color: var(--primary-ink); }

@media (hover: hover) {
  button:hover { box-shadow: var(--shadow-primary-hover); }
  a.btn:hover { box-shadow: var(--shadow-primary-hover); }
}

/* Primary used as text/iconography on neutral surfaces */
button.ghost,
.stat .stat-icon,
.stat.accent .stat-icon,
.sel-card-sub.barcode,
.file-input .fi-icon,
.qty-stepper button,
.m-refresh,
.pw-toggle.on,
.member-topbar-title .t1 { color: var(--primary-ink); }
.cart-bar,
.tabs button.active,
.login-hint,
.m-tab.active { color: var(--primary-ink); }
@media (hover: hover) {
  .pw-toggle:hover,
  .member-row:hover .member-chevron,
  .m-bottomnav button.m-tab:hover { color: var(--primary-ink); }
}

/* Sidebar brand + active states */
.sidebar::before {
  background: radial-gradient(420px 260px at 85% -5%, rgb(var(--primary-rgb) / 0.22) 0%, transparent 60%),
              radial-gradient(360px 300px at -20% 108%, rgba(99, 102, 241, 0.16) 0%, transparent 55%);
}
.sidebar .brand .brand-logo,
.login-card .logo,
.member-topbar .brand-logo {
  background: linear-gradient(135deg, var(--primary-bright) 0%, var(--primary-dark) 100%);
}
.sidebar nav a.active {
  background: linear-gradient(135deg, rgb(var(--primary-rgb) / 0.28), rgb(var(--primary-rgb) / 0.10));
  box-shadow: inset 0 0 0 1px rgb(var(--primary-rgb) / 0.35);
}
.sidebar nav a.active .nav-icon {
  background: linear-gradient(135deg, var(--primary-bright), var(--primary-dark));
  box-shadow: 0 4px 14px rgb(var(--primary-rgb) / 0.5);
}
.sidebar nav a.active::before {
  background: linear-gradient(180deg, var(--primary-glow), var(--primary));
  box-shadow: 0 0 12px rgb(var(--primary-rgb) / 0.8);
}
@media (hover: hover) {
  .sidebar nav a:hover .nav-icon { color: var(--primary-tint); }
}
@keyframes brandGlow {
  0%, 100% { box-shadow: 0 6px 18px rgb(var(--primary-rgb) / 0.45); }
  50% { box-shadow: 0 6px 26px rgb(var(--primary-rgb) / 0.75); }
}

.tabs button.active {
  box-shadow: 0 2px 8px rgba(var(--shadow-ink), 0.10), 0 0 0 1px rgb(var(--primary-rgb) / 0.14);
}
.m-tab.active::before { box-shadow: 0 1px 6px rgb(var(--primary-rgb) / 0.5); }
.m-topbar {
  background: linear-gradient(120deg, var(--primary-dark) 0%, var(--primary-darker) 45%, var(--login-3) 100%);
  background-size: 180% 180%;
  box-shadow: 0 6px 20px rgb(var(--primary-rgb) / 0.3);
}
.login-wrap {
  background: linear-gradient(135deg, var(--login-1) 0%, var(--login-2) 55%, var(--login-3) 100%);
}
.login-wrap::before { background: var(--primary-bright); }
.login-card { background: var(--login-card); }
@media (hover: hover) {
  .item-card:hover,
  .member-row:hover { border-color: var(--border-hover); }
}

/* =====================================================================
   3. DARK MODE
   ===================================================================== */
html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #080d18;
  --card: #101a2c;
  --text: #e8eefb;
  --text-soft: #c5d1e4;
  --muted: #93a3bd;
  --muted-2: #6c7d97;
  --border: #22304a;
  --border-soft: #1a2437;
  --border-strong: #35476a;
  --border-hover: #2f4a5e;

  --surface-1: #101a2c;
  --surface-2: #16233a;
  --surface-3: #1b2942;
  --surface-4: #1f2f4b;
  --surface-track: #16233a;
  --surface: var(--surface-1);
  --th-bg: #16233a;

  --side-bg-1: #060a13;
  --side-bg-2: #0a1420;
  --side-text: #c3d0e2;
  --side-muted: #7b8ba3;
  --side-line: rgba(148, 163, 184, 0.16);
  --side-hover: rgba(148, 163, 184, 0.12);

  --topbar-bg: rgba(16, 26, 44, 0.86);
  --topbar-inset: rgba(255, 255, 255, 0.04);
  --glass: rgba(16, 26, 44, 0.95);
  --glass-soft: rgba(255, 255, 255, 0.06);
  --overlay: rgba(3, 7, 16, 0.7);
  --backdrop: rgba(3, 7, 16, 0.62);
  --scroll-thumb: #2a3b58;
  --scroll-thumb-hover: #3d5379;

  --bg-glow-1: rgb(var(--primary-rgb) / 0.16);
  --bg-glow-2: rgba(99, 102, 241, 0.14);
  --bg-glow-3: rgb(var(--primary-rgb) / 0.10);

  --primary-light: rgb(var(--primary-rgb) / 0.28);
  --primary-50: rgb(var(--primary-rgb) / 0.12);
  --primary-ink: var(--primary-tint);

  --modal-head-1: #142139;
  --modal-head-2: #101a2c;
  --grabber: #35476a;

  --ph-1: #16233a;
  --ph-2: #101a2c;
  --ph-fg: #46597a;
  --skeleton-1: #16233a;
  --skeleton-2: #1f2f4b;

  --danger: #fb7185;
  --danger-soft: rgba(244, 63, 94, 0.16);
  --danger-ink: #fecdd3;
  --danger-border: rgba(244, 63, 94, 0.35);
  --success: #34d399;
  --success-soft: rgba(16, 185, 129, 0.16);
  --success-ink: #a7f3d0;
  --success-border: rgba(16, 185, 129, 0.35);
  --warning: #fbbf24;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --warning-ink: #fde68a;
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.16);
  --info-ink: #bae6fd;
  --info-border: rgba(56, 189, 248, 0.35);
  --amber-1: rgba(245, 158, 11, 0.12);
  --amber-2: rgba(245, 158, 11, 0.18);
  --amber-3: rgba(245, 158, 11, 0.22);
  --amber-border: rgba(251, 191, 36, 0.45);
  --amber-ink: #fde68a;
  --custody-bg: rgba(245, 158, 11, 0.10);

  --shadow-ink: 0, 0, 0;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.55), 0 4px 8px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 22px 50px rgba(0, 0, 0, 0.65);

  --login-1: #060a13;
  --login-2: #0d1a2b;
  --login-3: #101a2c;
  --login-card: rgba(16, 26, 44, 0.96);
}

/* --- Surfaces that were literal white/grey in app.css --- */
html[data-theme="dark"] button.secondary,
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .topbar .menu-btn,
html[data-theme="dark"] .stat,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .toolbar,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .modal-foot,
html[data-theme="dark"] .select-row,
html[data-theme="dark"] .sel-card,
html[data-theme="dark"] .qty-stepper button,
html[data-theme="dark"] .member-row,
html[data-theme="dark"] .issued-item,
html[data-theme="dark"] .qr-preview,
html[data-theme="dark"] .receipt-card,
html[data-theme="dark"] .m-filters,
html[data-theme="dark"] .m-chip,
html[data-theme="dark"] .m-refresh,
html[data-theme="dark"] .file-input .fi-icon,
html[data-theme="dark"] .tabs button.active,
html[data-theme="dark"] .responsive-table tr { background: var(--surface-1); }

html[data-theme="dark"] .file-input,
html[data-theme="dark"] .detail-rows > div { background: var(--surface-2); }

html[data-theme="dark"] .item-img,
html[data-theme="dark"] .modal-head .x,
html[data-theme="dark"] .select-row .sr-check,
html[data-theme="dark"] .pill { background: var(--surface-3); }

html[data-theme="dark"] .tabs {
  background: var(--surface-track);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}
html[data-theme="dark"] .topbar {
  background: var(--topbar-bg);
  box-shadow: 0 1px 0 var(--topbar-inset) inset;
}
html[data-theme="dark"] th { background: var(--th-bg); }
html[data-theme="dark"] .modal-head { background: linear-gradient(180deg, var(--modal-head-1), var(--modal-head-2)); }
html[data-theme="dark"] .modal { box-shadow: 0 30px 70px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.06) inset; }
html[data-theme="dark"] .modal-overlay { background: var(--overlay); }
html[data-theme="dark"] .modal-grabber { background: var(--grabber); }
html[data-theme="dark"] .backdrop.show { background: var(--backdrop); }
html[data-theme="dark"] .m-bottomnav { background: var(--glass); }
html[data-theme="dark"] .member-topbar { background: var(--glass); }
html[data-theme="dark"] .m-shell { box-shadow: 0 0 60px rgba(0, 0, 0, 0.5); }
html[data-theme="dark"] .item-img.placeholder,
html[data-theme="dark"] .empty .empty-icon { background: linear-gradient(135deg, var(--ph-1), var(--ph-2)); color: var(--ph-fg); }
html[data-theme="dark"] .skeleton { background: linear-gradient(90deg, var(--skeleton-1) 25%, var(--skeleton-2) 50%, var(--skeleton-1) 75%); background-size: 200% 100%; }
html[data-theme="dark"] .m-tab-badge { box-shadow: 0 0 0 2px var(--surface-1); }
html[data-theme="dark"] .issued-item.custody { background: var(--custody-bg); border-color: var(--amber-border); }
html[data-theme="dark"] .file-input { border-color: var(--border-strong); }
html[data-theme="dark"] .file-input.has-file { border-color: var(--success); background: var(--success-soft); }
html[data-theme="dark"] .file-input.has-file .fi-icon { color: var(--success); }
html[data-theme="dark"] .damage-toggle { background: var(--surface-1); border-color: var(--border); }
html[data-theme="dark"] .damage-toggle.on { background: rgba(251, 113, 133, 0.12); }

@media (hover: hover) {
  html[data-theme="dark"] button.secondary:hover { background: var(--surface-2); }
  html[data-theme="dark"] .tabs button:hover { background: var(--glass-soft); }
  html[data-theme="dark"] .pw-toggle:hover { background: var(--surface-3); }
  html[data-theme="dark"] .modal-head .x:hover { background: var(--danger-soft); color: var(--danger); }
  html[data-theme="dark"] input:hover,
  html[data-theme="dark"] select:hover,
  html[data-theme="dark"] textarea:hover { border-color: var(--border-strong); }
  html[data-theme="dark"] tbody tr:hover { background: var(--primary-50); }
}
@media (max-width: 640px) {
  html[data-theme="dark"] .responsive-table tr:hover { background: var(--surface-1); }
}

/* --- Status text colors need lifting on dark surfaces --- */
html[data-theme="dark"] .alert.error { background: var(--danger-soft); color: var(--danger-ink); border-color: var(--danger-border); }
html[data-theme="dark"] .alert.success { background: var(--success-soft); color: var(--success-ink); border-color: var(--success-border); }
html[data-theme="dark"] .alert.info { background: var(--info-soft); color: var(--info-ink); border-color: var(--info-border); }
html[data-theme="dark"] .badge.available { background: var(--success-soft); color: var(--success-ink); }
html[data-theme="dark"] .badge.in_use { background: var(--warning-soft); color: var(--warning-ink); }
html[data-theme="dark"] .badge.maintenance { background: var(--danger-soft); color: var(--danger-ink); }
html[data-theme="dark"] .badge.pending { background: rgba(99, 102, 241, 0.2); color: #c7d2fe; }
html[data-theme="dark"] .stat.warn .stat-icon { background: var(--warning-soft); color: var(--warning); }
html[data-theme="dark"] .stat.danger .stat-icon { background: var(--danger-soft); color: var(--danger); }
html[data-theme="dark"] .stat.ok .stat-icon { background: var(--success-soft); color: var(--success); }
html[data-theme="dark"] .m-chip.warn .n { color: var(--warning); }
html[data-theme="dark"] .note-chip { background: var(--amber-1); border-color: var(--amber-border); color: var(--amber-ink); }
html[data-theme="dark"] .note-chip.on { background: var(--amber-2); }
html[data-theme="dark"] .m-banner {
  background: linear-gradient(135deg, var(--amber-1), var(--amber-3));
  border-color: var(--amber-border);
  color: var(--amber-ink);
}
html[data-theme="dark"] .member-login .login-hint { background: rgba(99, 102, 241, 0.16); border-color: rgba(129, 140, 248, 0.4); color: #c7d2fe; }
html[data-theme="dark"] .cart-bar { background: var(--primary-50); border-color: var(--primary-light); }
html[data-theme="dark"] ::selection { background: var(--primary-light); }
html[data-theme="dark"] .login-wrap::before,
html[data-theme="dark"] .login-wrap::after { opacity: 0.28; }

/* Printing is always on white paper, whatever the screen theme is. */
@media print {
  html[data-theme="dark"] { --bg: #fff; --card: #fff; --surface-1: #fff; --surface-2: #fff; --text: #0f172a; --muted: #475569; --border: #cbd5e1; }
  html[data-theme="dark"] body { background: #fff; color: #0f172a; }
  html[data-theme="dark"] .table-wrap, html[data-theme="dark"] th, html[data-theme="dark"] td { background: #fff; color: #0f172a; }
}

/* =====================================================================
   4. UI refinements (both modes)
   ===================================================================== */

/* --- Sidebar: section labels + collapsible rail on desktop --- */
.sidebar nav .nav-group {
  position: relative;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--side-muted);
  padding: 0.85rem 0.85rem 0.35rem;
  text-transform: uppercase;
  white-space: nowrap;
}
.sidebar .brand { justify-content: space-between; }
.sidebar .brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar .brand-text .b1 { font-size: 1rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .brand-text .b2 { font-size: 0.68rem; font-weight: 600; color: var(--side-muted); }

.rail-btn {
  display: none;
  background: transparent;
  color: var(--side-muted);
  box-shadow: none;
  padding: 0.35rem;
  border-radius: 9px;
  flex: 0 0 auto;
}
@media (hover: hover) {
  .rail-btn:hover { background: var(--side-hover); color: #fff; transform: none; filter: none; box-shadow: none; }
}
@media (min-width: 861px) {
  .rail-btn { display: inline-flex; }
  html[data-rail="1"] { --sidebar-width: 76px; }
  html[data-rail="1"] .sidebar .brand-text,
  html[data-rail="1"] .sidebar nav a > span:not(.nav-icon),
  html[data-rail="1"] .sidebar .foot span,
  html[data-rail="1"] .sidebar nav .nav-group { display: none; }
  html[data-rail="1"] .sidebar .brand { justify-content: center; padding-inline: 0.5rem; }
  html[data-rail="1"] .sidebar nav a { justify-content: center; padding-inline: 0.5rem; }
  html[data-rail="1"] .sidebar nav a .nav-count {
    position: absolute; top: 2px; inset-inline-end: 2px; margin: 0;
    min-width: 17px; height: 17px; font-size: 0.62rem;
  }
  html[data-rail="1"] .sidebar nav a.active::before { inset-inline-start: -0.6rem; }
  /* Tooltip for the collapsed rail */
  html[data-rail="1"] .sidebar nav a::after {
    content: attr(data-label);
    position: absolute;
    inset-inline-start: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) scale(0.94);
    background: var(--side-bg-1);
    color: #f1f5f9;
    border: 1px solid var(--side-line);
    padding: 0.35rem 0.65rem;
    border-radius: 9px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: var(--shadow-md);
    transition: opacity var(--t-fast), transform var(--t-fast);
    z-index: 60;
  }
  html[data-rail="1"] .sidebar nav a:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }
}
.sidebar .foot { display: flex; align-items: center; gap: 0.4rem; justify-content: center; }

/* --- Topbar: page identity + icon buttons --- */
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.topbar-title .tt1 { font-weight: 800; font-size: 0.95rem; line-height: 1.2; }
.topbar-title .tt2 { font-size: 0.72rem; color: var(--muted); font-weight: 600; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; flex: 0 0 auto;
  border-radius: 11px;
  background: var(--surface-1);
  color: var(--text-soft);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
@media (hover: hover) {
  .icon-btn:hover { background: var(--primary-50); color: var(--primary-ink); border-color: var(--primary); transform: none; filter: none; box-shadow: var(--shadow-sm); }
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn .i-moon { display: none; }
html[data-theme="dark"] .icon-btn .i-moon { display: inline-flex; }
html[data-theme="dark"] .icon-btn .i-sun { display: none; }
.topbar .user-chip { padding-inline-start: 0.4rem; border-inline-start: 1px solid var(--border); }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }

/* --- Appearance picker (settings page) --- */
.theme-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.7rem; }
.theme-mode {
  display: flex; align-items: center; gap: 0.7rem; text-align: start;
  padding: 0.75rem 0.85rem; border-radius: var(--radius);
  background: var(--surface-1); color: var(--text);
  border: 1.5px solid var(--border); box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
@media (hover: hover) {
  .theme-mode:hover { border-color: var(--primary); transform: translateY(-2px); filter: none; box-shadow: var(--shadow-sm); }
}
.theme-mode.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.theme-mode .tm-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.theme-mode.on .tm-icon { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: var(--on-primary); }
.theme-mode .tm-text { display: flex; flex-direction: column; min-width: 0; }
.theme-mode .tm-title { font-weight: 700; font-size: 0.9rem; }
.theme-mode .tm-sub { font-size: 0.74rem; color: var(--muted); }

.accent-row { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.accent-dot {
  width: 44px; height: 44px; padding: 0; border-radius: 50%;
  border: 2px solid var(--border); box-shadow: var(--shadow-xs);
  display: grid; place-items: center; color: #fff;
  transition: transform var(--t-spring), box-shadow var(--t-fast), border-color var(--t-fast);
}
.accent-dot::after { content: none; }
@media (hover: hover) { .accent-dot:hover { transform: scale(1.1); filter: none; box-shadow: var(--shadow-sm); } }
.accent-dot.on { border-color: var(--text); box-shadow: 0 0 0 3px var(--primary-light); }
.accent-dot.a-teal { background: linear-gradient(135deg, #14b8a6, #0f766e); }
.accent-dot.a-blue { background: linear-gradient(135deg, #0ea5e9, #0369a1); }
.accent-dot.a-indigo { background: linear-gradient(135deg, #6366f1, #4338ca); }
.accent-dot.a-violet { background: linear-gradient(135deg, #a855f7, #7e22ce); }
.accent-dot.a-emerald { background: linear-gradient(135deg, #10b981, #047857); }
.accent-dot.a-amber { background: linear-gradient(135deg, #f59e0b, #b45309); }
.accent-dot.a-rose { background: linear-gradient(135deg, #f43f5e, #be123c); }

/* --- Small shared helpers used by the refreshed pages --- */
.section-title { display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; font-weight: 800; margin: 0 0 0.9rem; }
.section-title .st-icon {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--primary-50); color: var(--primary-ink);
}
.hint-line { font-size: 0.8rem; color: var(--muted); margin: 0.35rem 0 0; }
.card.soft { background: var(--surface-2); }
.divider { height: 1px; background: var(--border-soft); margin: 1.1rem 0; }

/* =====================================================================
   5. Refreshed application shell
   ===================================================================== */
.topbar-start { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar .user-meta { min-width: 0; line-height: 1.25; }
.topbar .user-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .user-role { font-size: 0.72rem; }

a.btn.secondary {
  background: var(--surface-1);
  color: var(--text-soft);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
@media (hover: hover) {
  a.btn.secondary:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
    filter: none;
  }
}

/* Modern stat cards: neutral surface with a small semantic status rail. */
.stat,
.stat.accent,
.stat.warn,
.stat.danger,
.stat.ok {
  border-width: 1px;
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.stat::before {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 4px;
  background: var(--primary);
}
.stat.warn::before { background: var(--warning); }
.stat.danger::before { background: var(--danger); }
.stat.ok::before { background: var(--success); }

/* =====================================================================
   6. Dashboard refresh
   ===================================================================== */
.dashboard-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(250px, 0.75fr);
  align-items: center;
  gap: 1.5rem;
  overflow: hidden;
  padding: clamp(1.35rem, 3vw, 2.25rem);
  margin-bottom: 1.5rem;
  border-radius: calc(var(--radius-xl) + 2px);
  color: #f8fafc;
  background:
    radial-gradient(560px 260px at 8% 5%, rgb(var(--primary-rgb) / 0.34), transparent 68%),
    linear-gradient(135deg, var(--side-bg-1), var(--side-bg-2));
  border: 1px solid var(--side-line);
  box-shadow: var(--shadow-md);
}
.dashboard-hero::after {
  content: '';
  position: absolute;
  width: 280px;
  height: 280px;
  border: 1px solid rgb(var(--primary-rgb) / 0.32);
  border-radius: 50%;
  inset-inline-end: -120px;
  inset-block-start: -145px;
  pointer-events: none;
}
.hero-copy, .readiness-card { position: relative; z-index: 1; }
.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  color: var(--primary-tint);
  background: rgb(var(--primary-rgb) / 0.14);
  border: 1px solid rgb(var(--primary-rgb) / 0.26);
  font-size: 0.76rem;
  font-weight: 800;
}
.hero-copy h1 {
  max-width: 700px;
  margin: 0.8rem 0 0.45rem;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  line-height: 1.35;
  letter-spacing: -0.025em;
}
.hero-copy p { max-width: 670px; margin: 0; color: #bdc9da; line-height: 1.8; font-size: 0.94rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1.2rem; }
.hero-actions a.btn { min-height: 44px; }
.hero-actions a.btn.secondary { background: rgba(255,255,255,0.08); color: #f8fafc; border-color: rgba(255,255,255,0.18); }
@media (hover: hover) { .hero-actions a.btn.secondary:hover { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.28); } }

.readiness-card {
  padding: 1.1rem;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.13);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(12px);
}
.readiness-head, .readiness-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.readiness-head { font-size: 0.85rem; color: #cbd5e1; }
.readiness-head strong { color: #fff; font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.readiness-track { height: 9px; margin: 0.8rem 0; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,0.12); }
.readiness-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary-bright), var(--primary-tint)); }
.readiness-meta { font-size: 0.73rem; color: #aebbd0; }
.readiness-meta b { color: #fff; font-size: 0.86rem; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 0 0.9rem; }
.section-heading.compact { margin-bottom: 0.8rem; }
.section-heading h2 { margin: 0; font-size: 1.08rem; }
.section-heading p { margin: 0.18rem 0 0; color: var(--muted); font-size: 0.78rem; }
.section-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  color: var(--success-ink); background: var(--success-soft); border: 1px solid var(--success-border);
  border-radius: 999px; padding: 0.28rem 0.6rem; font-size: 0.72rem; font-weight: 700;
}
.quick-panel { margin-top: 1.4rem; padding: 1.1rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-1); box-shadow: var(--shadow-xs); }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.quick-action {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  min-height: 78px;
  padding: 0.75rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.quick-action .qa-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; color: var(--primary-ink); background: var(--primary-50); }
.quick-action > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
.quick-action b { font-size: 0.86rem; }
.quick-action small { color: var(--muted); font-size: 0.72rem; margin-top: 0.12rem; }
.quick-action > svg { color: var(--muted-2); transform: scaleX(-1); }
.quick-action.primary { border-color: var(--primary-light); background: var(--primary-50); }
@media (hover: hover) {
  .quick-action:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: var(--shadow-sm); }
}

/* =====================================================================
   7. Appearance settings and theme previews
   ===================================================================== */
.appearance-card {
  max-width: 1000px;
  margin-bottom: 1.2rem;
  padding: 1.2rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.appearance-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.appearance-title { display: flex; align-items: flex-start; gap: 0.75rem; }
.appearance-icon { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 12px; background: var(--primary-50); color: var(--primary-ink); }
.appearance-head h2 { margin: 0; font-size: 1.12rem; }
.appearance-head p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.82rem; }
.live-preview { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; padding: 0.3rem 0.6rem; border-radius: 999px; background: var(--success-soft); color: var(--success-ink); border: 1px solid var(--success-border); font-size: 0.7rem; font-weight: 700; }
.live-preview > span { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }

.theme-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; }
.theme-preset {
  position: relative;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 0.7rem;
  min-height: 86px;
  padding: 0.65rem;
  text-align: start;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.theme-preset::after { content: none; }
.theme-preset.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
@media (hover: hover) { .theme-preset:hover { transform: translateY(-2px); filter: none; border-color: var(--primary); box-shadow: var(--shadow-sm); } }
.theme-preview {
  --pv-accent: #059669; --pv-bg: #f8fafc; --pv-side: #0f172a; --pv-card: #ffffff;
  position: relative; display: block; width: 92px; height: 62px; overflow: hidden;
  border-radius: 9px; background: var(--pv-bg); border: 1px solid rgba(100,116,139,0.28); box-shadow: var(--shadow-xs);
}
.theme-preview .tp-side { position: absolute; inset-block: 0; inset-inline-start: 0; width: 24%; background: var(--pv-side); }
.theme-preview .tp-top { position: absolute; inset-block-start: 0; inset-inline: 24% 0; height: 18%; background: var(--pv-card); border-bottom: 1px solid rgba(100,116,139,0.18); }
.theme-preview .tp-card { position: absolute; inset-block-start: 31%; width: 27%; height: 38%; border-radius: 4px; background: var(--pv-card); border: 1px solid rgba(100,116,139,0.18); border-block-start: 3px solid var(--pv-accent); }
.theme-preview .tp-card.one { inset-inline-start: 34%; }
.theme-preview .tp-card.two { inset-inline-start: 67%; }
.preset-warehouse { --pv-accent:#059669; --pv-bg:#f8fafc; --pv-side:#0f2f2a; --pv-card:#fff; }
.preset-classic { --pv-accent:#0d9488; --pv-bg:#f8fafc; --pv-side:#102f35; --pv-card:#fff; }
.preset-ocean { --pv-accent:#0284c7; --pv-bg:#f0f9ff; --pv-side:#0c2740; --pv-card:#fff; }
.preset-rose { --pv-accent:#e11d48; --pv-bg:#fff7f9; --pv-side:#42212d; --pv-card:#fff; }
.preset-indigo { --pv-accent:#818cf8; --pv-bg:#080d18; --pv-side:#111827; --pv-card:#17213a; }
.preset-violet { --pv-accent:#c084fc; --pv-bg:#0f0b18; --pv-side:#211233; --pv-card:#211a32; }
.preset-tealnight { --pv-accent:#2dd4bf; --pv-bg:#0a1420; --pv-side:#0d262c; --pv-card:#172632; }
.preset-sand { --pv-accent:#d97706; --pv-bg:#fffaf0; --pv-side:#342313; --pv-card:#fff; }
.preset-adaptive { --pv-accent:#14b8a6; --pv-bg:linear-gradient(90deg,#f8fafc 0 50%,#101a2c 50%); --pv-side:#0c1424; --pv-card:#fff; }
.preset-copy { display: flex; flex-direction: column; min-width: 0; }
.preset-name { font-weight: 800; font-size: 0.84rem; }
.preset-desc { margin-top: 0.16rem; color: var(--muted); font-size: 0.7rem; line-height: 1.5; }
.preset-check { position: absolute; inset-block-start: 0.45rem; inset-inline-end: 0.45rem; width: 22px; height: 22px; display: none; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; }
.theme-preset.on .preset-check { display: grid; }

.appearance-custom { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(230px, 0.8fr); gap: 1rem; padding-top: 1.1rem; margin-top: 1.1rem; border-top: 1px solid var(--border-soft); }
.mini-title { margin: 0 0 0.65rem; font-size: 0.83rem; color: var(--text-soft); }
.appearance-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 54px; padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--border-soft); }
.appearance-foot .alert { margin: 0; }
.appearance-actions { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; }
.theme-preset:active { transform: scale(0.985); }

/* Fixed assets: make identification and filtering quick without changing the established card layout. */
.asset-toolbar { align-items: end; }
.asset-toolbar .asset-search-field { flex: 1 1 210px; min-width: 180px; }
.asset-toolbar .asset-search-field label { margin-bottom: 0.3rem; }
.asset-toolbar .asset-search-field input { min-width: 0; width: 100%; }
.asset-toolbar select { flex: 0.75 1 160px; }
.asset-results { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; margin: -0.35rem 0 1rem; color: var(--muted); font-size: 0.82rem; }
.asset-results button { min-height: 38px; }
.asset-serial { display: inline-flex; align-items: center; gap: 0.35rem; max-width: 100%; margin-bottom: 0.55rem; padding: 0.25rem 0.55rem; border-radius: 7px; color: var(--primary-ink); background: var(--primary-50); border: 1px solid var(--primary-light); font-size: 0.76rem; font-weight: 700; }
.asset-serial bdi { direction: ltr; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.item-card[role="button"]:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.field-hint { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.76rem; line-height: 1.55; }
.field-error { margin: 0.35rem 0 0; color: var(--danger-ink); font-size: 0.78rem; font-weight: 700; }
input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

@media (max-width: 980px) {
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .dashboard-hero { grid-template-columns: 1fr; }
  .readiness-card { max-width: 100%; }
  .appearance-custom { grid-template-columns: 1fr; }
  .topbar-title .tt2 { display: none; }
}
@media (max-width: 560px) {
  .dashboard-hero { padding: 1.15rem; border-radius: var(--radius-lg); }
  .hero-copy h1 { font-size: 1.45rem; }
  .hero-actions a.btn { flex: 1 1 100%; }
  .quick-grid, .theme-presets { grid-template-columns: 1fr; }
  .section-chip, .live-preview { display: none; }
  .appearance-card { padding: 0.9rem; border-radius: var(--radius-lg); }
  .appearance-head p { font-size: 0.76rem; }
  .appearance-foot { align-items: stretch; flex-direction: column; }
  .appearance-foot > button { width: 100%; }
  .topbar-title { display: none; }
  .topbar .user-chip { gap: 0.4rem; }
  .topbar .user-meta { display: none; }
  .logout-btn span { display: none; }
  .logout-btn { width: 40px; padding-inline: 0; }
}

@media (max-width: 560px) {
  .theme-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .theme-preset { grid-template-columns: 1fr; align-content: start; gap: 0.45rem; min-height: 128px; padding: 0.55rem; }
  .theme-preview { width: 100%; height: 60px; }
  .preset-name { font-size: 0.8rem; }
  .preset-desc { font-size: 0.67rem; }
  .appearance-actions { width: 100%; }
  .appearance-actions button { flex: 1 1 140px; min-height: 44px; }
  .asset-toolbar .asset-search-field { flex-basis: 100%; }
  .asset-toolbar select { flex: 1 1 calc(50% - 0.3rem); min-width: 130px; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-preset, .asset-serial { animation: none; transition: none; }
}
