/* ============================================================================
   PANEL DESIGN SYSTEM  —  premium Monochrome Black & White, light + dark
   ----------------------------------------------------------------------------
   Retheme strategy: every page in this panel uses hardcoded Tailwind literals
   (bg-[#F9F9F9], border-[#E8E8E8], text-red-600, ...). Instead of editing all
   of them, they are remapped here onto CSS variables. Change a token below and
   the whole panel — light AND dark — follows.

   Geometry: the panel is deliberately SQUARE. All border-radius utilities are
   collapsed onto the --r-* tokens in the "SQUARE GEOMETRY" block.
   ============================================================================ */

/* ── Tokens ───────────────────────────────────────────────────────────────── */
:root,
[data-theme="light"] {
  --background:   #FFFFFF;   /* app canvas — clean crisp white */
  --surface:      #FFFFFF;   /* cards / panels / table bodies */
  --surface-2:    #F4F4F5;   /* insets, table headers, hover fills */
  --surface-3:    #E4E4E7;   /* pressed / stronger inset */
  --foreground:   #09090B;   /* pure near-black */
  --primary:      #09090B;
  --secondary:    #71717A;   /* body-secondary text */
  --muted:        #A1A1AA;   /* meta text, placeholders */

  --accent:       #09090B;   /* solid black */
  --accent-hover: #27272A;   /* dark gray hover */
  --accent-active:#000000;
  --accent-soft:  rgba(9, 9, 11, 0.06);
  --accent-line:  rgba(9, 9, 11, 0.20);
  --accent-2:     #18181B;
  --on-accent:    #FFFFFF;   /* white text on black */

  --border:       #E4E4E7;   /* default hairline */
  --border-strong:#D4D4D8;   /* inputs, emphasised edges */
  --hover:        #F4F4F5;

  --success:      #0E7C4A;
  --success-soft: rgba(14, 124, 74, 0.10);
  --success-line: rgba(14, 124, 74, 0.24);
  --warning:      #9A5B00;
  --warning-soft: rgba(154, 91, 0, 0.10);
  --warning-line: rgba(154, 91, 0, 0.24);
  --error:        #EF4444;
  --error-soft:   rgba(239, 68, 68, 0.08);
  --error-line:   rgba(239, 68, 68, 0.24);
  --info:         #1D4ED8;
  --info-soft:    rgba(29, 78, 216, 0.08);
  --info-line:    rgba(29, 78, 216, 0.22);
  --violet:       #6D28D9;
  --violet-soft:  rgba(109, 40, 217, 0.08);
  --violet-line:  rgba(109, 40, 217, 0.20);

  --shadow-xs:    0 1px 1px rgba(0, 0, 0, 0.04);
  --shadow:       0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow-md:    0 4px 10px -2px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg:    0 16px 32px -12px rgba(0, 0, 0, 0.16), 0 4px 10px -6px rgba(0, 0, 0, 0.08);
  --overlay:      rgba(0, 0, 0, 0.50);

  --font-body:    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: Outfit, Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light;
}

[data-theme="dark"] {
  --background:   #09090B;   /* deep pitch black */
  --surface:      #121214;   /* dark card surface */
  --surface-2:    #18181B;
  --surface-3:    #27272A;
  --foreground:   #FAFAFA;   /* crisp white */
  --primary:      #FAFAFA;
  --secondary:    #A1A1AA;
  --muted:        #71717A;

  --accent:       #FAFAFA;   /* crisp white on dark */
  --accent-hover: #E4E4E7;
  --accent-active:#D4D4D8;
  --accent-soft:  rgba(250, 250, 250, 0.12);
  --accent-line:  rgba(250, 250, 250, 0.28);
  --accent-2:     #F4F4F5;
  --on-accent:    #09090B;   /* black text on white */

  --border:       #27272A;
  --border-strong:#3F3F46;
  --hover:        #18181B;

  --success:      #34D399;
  --success-soft: rgba(52, 211, 153, 0.13);
  --success-line: rgba(52, 211, 153, 0.30);
  --warning:      #F0B429;
  --warning-soft: rgba(240, 180, 41, 0.13);
  --warning-line: rgba(240, 180, 41, 0.30);
  --error:        #F87171;
  --error-soft:   rgba(248, 113, 113, 0.13);
  --error-line:   rgba(248, 113, 113, 0.30);
  --info:         #60A5FA;
  --info-soft:    rgba(96, 165, 250, 0.13);
  --info-line:    rgba(96, 165, 250, 0.30);
  --violet:       #A78BFA;
  --violet-soft:  rgba(167, 139, 250, 0.13);
  --violet-line:  rgba(167, 139, 250, 0.30);

  --shadow-xs:    0 1px 1px rgba(0, 0, 0, 0.4);
  --shadow:       0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md:    0 4px 12px -2px rgba(0, 0, 0, 0.55);
  --shadow-lg:    0 20px 40px -14px rgba(0, 0, 0, 0.72), 0 6px 14px -8px rgba(0, 0, 0, 0.5);
  --overlay:      rgba(0, 0, 0, 0.65);

  color-scheme: dark;
}

/* Squared geometry scale + layout metrics */
:root {
  --r-xs: 2px;   /* chips, badges, small controls */
  --r-sm: 2px;   /* buttons, inputs */
  --r-md: 3px;   /* cards, tables, dropdowns */
  --r-lg: 4px;   /* modals, sheets */
  --nav-h: 56px; /* mobile bottom nav height */
  --top-h: 56px; /* top bar height */
  --side-w: 236px;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
* { -webkit-tap-highlight-color: transparent; }

html {
  background-color: var(--background);
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--background);
  color: var(--foreground);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.nav-open { overflow: hidden; }

h1, h2, h3, .font-display {
  font-family: var(--font-display);
  letter-spacing: -0.018em;
  font-optical-sizing: auto;
}

.font-mono, code, pre, kbd { font-family: var(--font-mono); }

::selection { background: var(--accent); color: var(--on-accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

a { color: inherit; }
hr { border-color: var(--border); }

/* ============================================================================
   SQUARE GEOMETRY — collapse every radius utility onto the scale
   ============================================================================ */
[class*="rounded"]      { border-radius: var(--r-md) !important; }
[class*="rounded-full"] { border-radius: var(--r-xs) !important; }
[class*="rounded-sm"],
[class*="rounded-xs"]   { border-radius: var(--r-sm) !important; }
[class*="after:rounded-full"]::after,
[class*="before:rounded-full"]::before { border-radius: var(--r-xs) !important; }

/* Directional variants keep their flat side */
[class*="rounded-t-"] { border-bottom-left-radius: 0 !important; border-bottom-right-radius: 0 !important; }
[class*="rounded-b-"] { border-top-left-radius: 0 !important;    border-top-right-radius: 0 !important; }
[class*="rounded-l-"] { border-top-right-radius: 0 !important;   border-bottom-right-radius: 0 !important; }
[class*="rounded-r-"] { border-top-left-radius: 0 !important;    border-bottom-left-radius: 0 !important; }

/* Genuinely-circular exceptions: live status pips, progress bars, spinners */
.pip, .progress-track, .progress-fill, .spinner { border-radius: 999px !important; }

input, select, textarea, button { border-radius: var(--r-sm); }

/* ============================================================================
   LITERAL REMAPPING — hardcoded Tailwind values used across the panel
   ============================================================================ */

/* Surfaces */
.bg-white,
.bg-\[\#FFFFFF\],
.bg-\[\#ffffff\]               { background-color: var(--surface) !important; }
.bg-gray-50, .bg-slate-50, .bg-neutral-50,
.bg-\[\#F9F9F9\], .bg-\[\#FAFAFA\], .bg-\[\#f6f8fa\],
.bg-\[\#F5F3EE\], .bg-\[\#F0F0F0\], .bg-\[\#f3f4f6\] { background-color: var(--surface-2) !important; }
.bg-gray-100, .bg-slate-100,
.bg-\[\#E8E8E8\], .bg-\[\#e1e4e8\] { background-color: var(--surface-3) !important; }
.bg-gray-200, .bg-gray-300      { background-color: var(--border-strong) !important; }
.bg-\[\#9CA3AF\]                { background-color: var(--muted) !important; }
.hover\:bg-gray-50:hover,
.hover\:bg-gray-100:hover,
.hover\:bg-\[\#F9F9F9\]:hover,
.hover\:bg-\[\#FAFAFA\]:hover   { background-color: var(--hover) !important; }
.active\:bg-gray-50:active,
.active\:bg-gray-100:active     { background-color: var(--surface-3) !important; }

/* Text */
.text-primary,
.text-\[\#0D0D0D\], .text-\[\#111827\], .text-\[\#24292f\] { color: var(--primary) !important; }
.text-secondary, .text-gray-600, .text-gray-700,
.text-\[\#6B6B6B\], .text-\[\#57606a\] { color: var(--secondary) !important; }
.text-gray-400, .text-gray-500,
.text-\[\#9CA3AF\], .text-\[\#9ca3af\], .text-\[\#8c959f\] { color: var(--muted) !important; }

/* Borders */
.border-border, .border-gray-200, .border-gray-300, .border-slate-200,
.border-\[\#E8E8E8\], .border-\[\#E5E5E5\], .border-\[\#F0F0F0\],
.border-\[\#d0d7de\], .border-\[\#8c959f\] { border-color: var(--border) !important; }
.divide-\[\#E8E8E8\] > * + *,
.divide-\[\#E5E5E5\] > * + *,
.divide-\[\#F0F0F0\] > * + *,
.divide-gray-100 > * + *,
.divide-gray-200 > * + *        { border-color: var(--border) !important; }
.hover\:border-\[\#8c959f\]:hover,
.hover\:border-gray-300:hover   { border-color: var(--border-strong) !important; }

/* Accent (red family + legacy blue literals all collapse here) */
.bg-accent,
.bg-\[\#DC2626\], .bg-\[\#E11D2E\], .bg-\[\#B91C1C\], .bg-\[\#B8121F\],
.bg-red-600, .bg-red-700,
.bg-\[\#1A73E8\], .bg-\[\#0969da\] { background-color: var(--accent) !important; color: var(--on-accent) !important; }
.hover\:bg-\[\#B91C1C\]:hover,
.hover\:bg-\[\#1557B0\]:hover,
.hover\:bg-red-700:hover,
.hover\:bg-accent:hover         { background-color: var(--accent-hover) !important; }
.text-accent,
.text-\[\#DC2626\], .text-\[\#1A73E8\], .text-\[\#0969da\],
.text-blue-700, .text-blue-600  { color: var(--accent) !important; }
.hover\:text-\[\#DC2626\]:hover,
.hover\:text-accent:hover       { color: var(--accent) !important; }
.border-accent, .border-\[\#DC2626\], .border-\[\#E11D2E\],
.border-\[\#0969da\], .border-\[\#1A73E8\],
.focus\:border-accent:focus,
.focus\:border-\[\#1A73E8\]:focus { border-color: var(--accent) !important; }
.hover\:border-\[\#1A73E8\]:hover,
.hover\:border-accent:hover     { border-color: var(--accent) !important; }
.bg-accent\/5, .bg-accent\/10,
.bg-\[\#1A73E8\]\/10, .bg-blue-50, .bg-\[\#DC2626\]\/10 { background-color: var(--accent-soft) !important; }
.hover\:bg-blue-50:hover,
.hover\:bg-\[\#1A73E8\]\/5:hover,
.hover\:bg-accent\/5:hover      { background-color: var(--accent-soft) !important; }
.ring-\[\#DC2626\], .ring-blue-300 { --tw-ring-color: var(--accent-line) !important; }
.group:hover .group-hover\:text-\[\#1A73E8\],
.group:hover .group-hover\:text-accent { color: var(--accent) !important; }

/* Semantic: danger */
.text-red-500, .text-red-600, .text-red-700 { color: var(--error) !important; }
.bg-red-50, .bg-red-50\/60, .bg-red-100     { background-color: var(--error-soft) !important; }
.hover\:bg-red-50:hover, .active\:bg-red-100:active,
.hover\:bg-red-100:hover                    { background-color: var(--error-soft) !important; }
.border-red-100, .border-red-200, .border-red-500,
.hover\:border-red-200:hover                { border-color: var(--error-line) !important; }
.hover\:text-red-700:hover                  { color: var(--error) !important; }

/* Semantic: success */
.text-green-500, .text-green-600, .text-green-700,
.text-emerald-500, .text-emerald-600        { color: var(--success) !important; }
.bg-green-50, .bg-green-100, .bg-emerald-50 { background-color: var(--success-soft) !important; }
.bg-green-500                               { background-color: var(--success) !important; }
.border-green-100, .border-green-200        { border-color: var(--success-line) !important; }

/* Semantic: warning */
.text-amber-500, .text-amber-600, .text-amber-700,
.text-yellow-300, .text-yellow-600          { color: var(--warning) !important; }
.bg-amber-50, .bg-amber-100, .bg-yellow-50  { background-color: var(--warning-soft) !important; }
.bg-amber-500, .bg-amber-600                { background-color: var(--warning) !important; }
.border-amber-200, .border-amber-600,
.hover\:border-amber-200:hover              { border-color: var(--warning-line) !important; }
.hover\:bg-amber-50:hover, .active\:bg-amber-50:active,
.hover\:bg-amber-100:hover                  { background-color: var(--warning-soft) !important; }
.hover\:text-amber-700:hover,
.hover\:text-amber-500:hover                { color: var(--warning) !important; }

/* Semantic: info / violet */
.text-purple-500, .text-purple-600, .text-purple-700 { color: var(--violet) !important; }
.bg-purple-50, .bg-purple-100               { background-color: var(--violet-soft) !important; }
.border-purple-200                          { border-color: var(--violet-line) !important; }
.text-blue-100                              { color: var(--info) !important; }
.bg-blue-100                                { background-color: var(--info-soft) !important; }
.border-blue-100                            { border-color: var(--info-line) !important; }

/* Gradients used on hero/stat cards */
.from-\[\#1A73E8\], .from-accent, .from-\[\#DC2626\] {
  --tw-gradient-from: var(--accent) !important;
  --tw-gradient-to: var(--accent-hover) !important;
  --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.to-\[\#0D47C2\], .to-accent, .to-\[\#B91C1C\] { --tw-gradient-to: var(--accent-active) !important; }
.shadow-\[\#1A73E8\]\/20 { box-shadow: var(--shadow-md) !important; }

/* Shadow scale — flatter, more professional */
.shadow-sm  { box-shadow: var(--shadow-xs) !important; }
.shadow     { box-shadow: var(--shadow) !important; }
.shadow-md  { box-shadow: var(--shadow-md) !important; }
.shadow-lg,
.shadow-xl,
.shadow-2xl { box-shadow: var(--shadow-lg) !important; }

/* ============================================================================
   COMPONENTS
   ============================================================================ */

/* ── Surface / card ───────────────────────────────────────────────────────── */
.card, .rounded-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  border-radius: var(--r-md);
}

.section-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--primary);
}

.eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Page header (used by every page) ─────────────────────────────────────── */
.page-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.page-head h1 {
  font-size: 20px;
  font-weight: 650;
  color: var(--primary);
  line-height: 1.2;
}
.page-head p { font-size: 13px; color: var(--secondary); margin-top: 3px; }
.page-head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (min-width: 768px) {
  .page-head { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .page-head h1 { font-size: 23px; }
  .page-head-actions { flex-wrap: nowrap; }
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--surface-2);
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--secondary);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--foreground);
  vertical-align: middle;
}

tbody tr { transition: background-color 0.12s ease; }
tbody tr:hover { background-color: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ── Badges / chips ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: var(--r-xs);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.5;
}
.badge-neutral { background: var(--surface-2); color: var(--secondary); border-color: var(--border); }
.badge-success { background: var(--success-soft); color: var(--success); border-color: var(--success-line); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-line); }
.badge-danger  { background: var(--error-soft);   color: var(--error);   border-color: var(--error-line); }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info-line); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent);  border-color: var(--accent-line); }
.badge-violet  { background: var(--violet-soft);  color: var(--violet);  border-color: var(--violet-line); }

.pip { display: inline-block; width: 6px; height: 6px; flex: none; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger,
.btn-warn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.003em;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease;
  user-select: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.btn-primary:hover  { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); border-color: var(--accent-active); }

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

.btn-ghost {
  background: transparent;
  color: var(--secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--primary); }

.btn-danger {
  background: var(--surface);
  color: var(--error);
  border-color: var(--error-line);
}
.btn-danger:hover { background: var(--error-soft); }

.btn-warn {
  background: var(--surface);
  color: var(--warning);
  border-color: var(--warning-line);
}
.btn-warn:hover { background: var(--warning-soft); }

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled,
.btn-warn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm { height: 32px; padding: 0 11px; font-size: 12px; }
.btn-block { width: 100%; }

/* Icon-only square action button */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--secondary);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}
.btn-icon:hover { background: var(--surface-2); color: var(--primary); border-color: var(--border-strong); }
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon-danger:hover { background: var(--error-soft); color: var(--error); border-color: var(--error-line); }
.btn-icon-warn:hover   { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-line); }
.btn-icon-accent:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

/* ── Form controls ────────────────────────────────────────────────────────── */
input, select, textarea {
  color: var(--foreground);
  background-color: var(--surface);
  font-family: var(--font-body);
  font-size: 14px;
  border-color: var(--border-strong);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
select { background-image: none; appearance: none; -webkit-appearance: none; }
select:not([multiple]):not([size]) { padding-right: 30px; }

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--secondary);
}

.input, .select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--foreground);
  font-size: 14px;
}
textarea.input { height: auto; padding: 10px 12px; line-height: 1.55; }

/* Search field with a leading icon slot */
.search-wrap { position: relative; width: 100%; }
.search-wrap > svg,
.search-wrap > .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-wrap input { padding-left: 34px; }

/* iOS zooms any input whose font-size < 16px — force 16px on phones */
@media (max-width: 640px) {
  input, select, textarea, .input, .select { font-size: 16px !important; }
}

/* Squared switch (paired with a `peer` checkbox) */
.switch-track {
  position: relative;
  width: 38px;
  height: 21px;
  background: var(--border-strong);
  border-radius: var(--r-xs) !important;
  transition: background-color 150ms ease;
  flex: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  background: #FFFFFF;
  border-radius: 1px !important;
  transition: transform 150ms ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.peer:checked ~ .switch-track { background: var(--accent); }
.peer:checked ~ .switch-track::after { transform: translateX(17px); }
[data-theme="dark"] .peer:checked ~ .switch-track::after { background: #09090B; }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal-backdrop.hidden { display: none; }
.modal-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal-title { font-family: var(--font-display); font-size: 15px; font-weight: 650; color: var(--primary); }
.modal-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex: none;
}

/* Phone: modals become bottom sheets */
@media (max-width: 640px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-panel {
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: 0;
    max-height: 92vh;
  }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pager { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background-color 130ms ease, color 130ms ease, border-color 130ms ease;
}
.pager-btn:hover:not(:disabled):not(.is-active) {
  background: var(--surface-2);
  color: var(--primary);
  border-color: var(--border-strong);
}
.pager-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  cursor: default;
}
.pager-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pager-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 34px;
  color: var(--muted);
  font-size: 12.5px;
}
.pager-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  padding-top: 4px;
}
.pager-bar .pager { justify-content: center; }
@media (min-width: 640px) {
  .pager-bar { flex-direction: row; align-items: center; justify-content: space-between; }
  .pager-bar .pager { justify-content: flex-end; }
}

/* ── Skeletons ────────────────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-xs);
}

/* ── Misc animations ──────────────────────────────────────────────────────── */
@keyframes dotsMove { from { background-position: 0 0; } to { background-position: 60px 60px; } }
.animate-dots { animation: dotsMove 30s linear infinite; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.animate-fade-up { animation: fadeUp 180ms ease-out both; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

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

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 0;
  border: 2px solid var(--background);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--secondary);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  color: var(--foreground);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.18s ease-out forwards;
}
@keyframes slideIn {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.toast-error   { border-left-color: var(--error); }
.toast-success { border-left-color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-mark { font-weight: 700; line-height: 1.35; flex: none; }
.toast-error   .toast-mark { color: var(--error); }
.toast-success .toast-mark { color: var(--success); }
.toast-warning .toast-mark { color: var(--warning); }

@media (max-width: 1023px) {
  #toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
    max-width: none;
  }
  .toast { width: 100%; }
}

/* ============================================================================
   APP SHELL
   ============================================================================ */
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 17px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--secondary);
  border-left: 2px solid transparent;
  transition: background-color 130ms ease, color 130ms ease, border-color 130ms ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--primary); }
.nav-link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-link svg { flex: none; }

.nav-section {
  padding: 12px 17px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: var(--top-h);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
@media (min-width: 1024px) { .app-topbar { padding: 0 26px; } }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: none;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--r-xs);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background 0.14s ease, color 0.14s ease;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--primary); }

/* Mobile bottom navigation */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.mobile-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  border-top: 2px solid transparent;
  margin-top: -1px;
  transition: color 130ms ease, border-color 130ms ease;
}
.mobile-nav a.is-active { color: var(--accent); border-top-color: var(--accent); }
@media (min-width: 1024px) { .mobile-nav { display: none; } }

/* Content area breathing room on phones (clears bottom nav) */
.app-main { padding: 16px 13px calc(var(--nav-h) + 26px); min-width: 0; }
@media (min-width: 640px)  { .app-main { padding: 20px 20px calc(var(--nav-h) + 26px); } }
@media (min-width: 1024px) { .app-main { padding: 24px 26px 40px; } }

/* ============================================================================
   RESPONSIVE / MOBILE HARDENING
   ============================================================================ */
img, svg, video, canvas { max-width: 100%; }

main, .app-main { min-width: 0; }
main pre, .app-main pre { overflow-x: auto; }

/* Long identifiers (keys, hashes, emails) must wrap instead of overflowing */
.break-anywhere { overflow-wrap: anywhere; word-break: break-word; }

/* Give every interactive control a real tap target on touch devices */
@media (pointer: coarse) {
  button, [role="button"], .btn-icon, .pager-btn { min-height: 36px; }
}

/* Stat grids collapse gracefully */
.stat-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  min-width: 0;
}
.stat-card .stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 650;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
@media (min-width: 768px) { .stat-card .stat-value { font-size: 24px; } }

/* Data list used as the phone replacement for wide tables */
.data-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px 12px;
}
.data-row + .data-row { margin-top: 8px; }
.data-kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--secondary);
}
.data-kv strong { color: var(--primary); font-weight: 600; text-align: right; }

/* Toolbar: search + actions row that reflows on phones */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toolbar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.toolbar-actions > .span-2 { grid-column: span 2; }
@media (min-width: 768px) {
  .toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
  .toolbar .search-wrap { max-width: 340px; }
  .toolbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; }
  .toolbar-actions > .span-2 { grid-column: auto; }
}

/* Empty states */
.empty-state {
  padding: 44px 16px;
  text-align: center;
  color: var(--secondary);
  font-size: 13px;
}
.empty-state .empty-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}

/* Progress bar */
.progress-track {
  width: 100%;
  height: 5px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 200ms ease; }

/* ============================================================================
   SHELL LAYOUT (sidebar drawer + content column)
   ============================================================================ */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: var(--side-w);
  max-width: 86vw;
  transform: translateX(-100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.app-sidebar.is-open { transform: none; }
@media (min-width: 1024px) { .app-sidebar { transform: none; } }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: var(--overlay);
}
@media (min-width: 1024px) { .sidebar-backdrop { display: none !important; } }

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: var(--top-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0 12px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; flex: none; }

.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
@media (min-width: 1024px) { .app-content { padding-left: var(--side-w); } }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  flex: none;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--r-xs);
}
.brand-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctx-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Key/ID cell rendered as a click-to-copy button ───────────────────────── */
.key-cell {
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--primary);
  cursor: pointer;
}
.key-cell:hover { color: var(--accent); }

/* Stacked icon-over-label button used in the phone card action grids */
.btn-stack {
  flex-direction: column;
  gap: 3px;
  height: 46px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}

/* ── Tabs (used inside the user-management modal) ─────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  flex: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 11px 13px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--secondary);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0 !important;
  cursor: pointer;
  transition: color 130ms ease, border-color 130ms ease;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Simple modals (no head/body/foot split) ──────────────────────────────── */
.modal-panel { position: relative; }

/* Panel that carries its own padding and scrolls as one block */
.modal-pad {
  padding: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 640px) {
  .modal-pad { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
}

/* Close button pinned to the panel corner */
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
}
.modal-pad > h3:first-of-type,
.modal-pad > h2:first-of-type { padding-right: 40px; }

/* ============================================================================
   PUBLIC / AUTH PAGES (login, register)
   ============================================================================ */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: 26px 22px;
}
@media (max-width: 380px) { .auth-card { padding: 22px 16px; } }

.auth-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-bottom: 18px;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: var(--r-xs);
}

.auth-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.auth-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.025em;
  color: var(--primary);
  margin-top: 5px;
}

.auth-form { margin-top: 22px; display: flex; flex-direction: column; gap: 15px; }

.auth-foot {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--secondary);
}
.auth-foot a { color: var(--accent); font-weight: 600; }
.auth-foot a:hover { text-decoration: underline; }

.alert {
  border: 1px solid var(--error-line);
  background: var(--error-soft);
  border-radius: var(--r-sm);
  padding: 11px 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--error);
}
.alert-note { color: var(--secondary); font-size: 11.5px; }

.link-muted { font-size: 11px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.link-muted:hover { text-decoration: underline; }
