/* ==========================================================================
   Admin Console — design system
   --------------------------------------------------------------------------
   One accent colour, hairline borders, a 4px spacing scale and a real type
   ramp. Motion is short and purposeful (120–180ms); nothing floats, glows or
   lifts on hover. Data is set in tabular figures so columns line up.
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------- */
:root {
  /* Neutral ramp (dark is the default surface) */
  --gray-0:  #0b0d10;
  --gray-1:  #101317;
  --gray-2:  #15191e;
  --gray-3:  #1b2027;
  --gray-4:  #232931;
  --gray-5:  #2d353f;
  --gray-6:  #3d4854;
  --gray-7:  #6b7686;
  --gray-8:  #98a2b0;
  --gray-9:  #ced4dc;
  --gray-10: #eef1f5;

  --accent:       #4c8dff;
  --accent-hover: #6ba0ff;
  --accent-quiet: rgba(76, 141, 255, 0.12);
  --accent-line:  rgba(76, 141, 255, 0.35);

  --positive: #34c77b;
  --positive-quiet: rgba(52, 199, 123, 0.12);
  --caution:  #e5a03c;
  --caution-quiet: rgba(229, 160, 60, 0.12);
  --critical: #f0616d;
  --critical-quiet: rgba(240, 97, 109, 0.12);

  --bg:        var(--gray-0);
  --surface:   var(--gray-1);
  --surface-2: var(--gray-2);
  --surface-3: var(--gray-3);
  --border:    var(--gray-4);
  --border-strong: var(--gray-5);
  --text:      var(--gray-10);
  --muted:     var(--gray-8);
  --faint:     var(--gray-7);

  /* Legacy aliases so existing markup keeps working */
  --primary: var(--accent);
  --secondary: var(--accent);
  --success: var(--positive);
  --warning: var(--caution);
  --danger: var(--critical);

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 48px;

  --radius:    8px;
  --radius-sm: 6px;
  --radius-lg: 12px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, .28), 0 1px 3px rgba(0, 0, 0, .2);
  --shadow-3: 0 16px 48px rgba(0, 0, 0, .45);

  --sidebar-w: 240px;
  --topbar-h: 56px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --ease: cubic-bezier(.2, 0, 0, 1);
  --dur: 150ms;
}

/* Alternate accents — the shell stays neutral, only the accent shifts. */
[data-theme="luxury-gold"] { --accent:#d9a441; --accent-hover:#e8b962; --accent-quiet:rgba(217,164,65,.12); --accent-line:rgba(217,164,65,.35); }
[data-theme="ocean-wave"]  { --accent:#2bb3a3; --accent-hover:#42c9b9; --accent-quiet:rgba(43,179,163,.12); --accent-line:rgba(43,179,163,.35); }
[data-theme="sunset-bliss"]{ --accent:#f0724a; --accent-hover:#ff8b66; --accent-quiet:rgba(240,114,74,.12); --accent-line:rgba(240,114,74,.35); }

[data-mode="light"] {
  --bg:        #f7f8fa;
  --surface:   #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e9edf2;
  --border:    #e2e6ec;
  --border-strong: #cfd6df;
  --text:      #10141a;
  --muted:     #5b6472;
  --faint:     #8b95a4;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 4px 12px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-3: 0 16px 48px rgba(16, 24, 40, .16);
}

/* --- Reset -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv05' 1, 'ss01' 1;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.014em; line-height: 1.3; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
svg { flex-shrink: 0; }

::selection { background: var(--accent-quiet); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-6); background-clip: content-box; }

/* --- Shell -------------------------------------------------------------- */
#app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
  transition: transform var(--dur) var(--ease);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--topbar-h);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}
.brand-glow {
  width: 22px; height: 22px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav {
  display: flex; flex-direction: column; gap: 1px;
  flex: 1; padding: var(--space-3) var(--space-2);
  overflow-y: auto;
}
.nav-section {
  padding: var(--space-4) var(--space-3) var(--space-1);
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--faint);
}
.nav-section:first-child { padding-top: var(--space-1); }

.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 7px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13.5px; font-weight: 450;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item svg { width: 16px; height: 16px; opacity: .75; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-quiet); color: var(--accent); font-weight: 550; }
.nav-item.active svg { opacity: 1; }
.nav-count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted);
}
.nav-item.active .nav-count { background: var(--accent); color: #fff; }

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--faint); font-size: 11.5px;
  display: flex; align-items: center; gap: var(--space-2);
  flex-shrink: 0;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--space-4);
  height: var(--topbar-h); padding: 0 var(--space-6);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 3px var(--positive-quiet);
}
.admin-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 500; color: var(--muted);
}

.content {
  padding: var(--space-6);
  max-width: 1440px; width: 100%; margin: 0 auto;
  animation: enter 180ms var(--ease);
}

.icon-btn {
  display: none; background: transparent; border: none;
  color: var(--muted); cursor: pointer; padding: 6px;
  border-radius: var(--radius-sm); line-height: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* --- Surfaces ----------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
}
.card > h3 { margin-bottom: var(--space-4); }
.glass { background: var(--surface); border: 1px solid var(--border); }

.grid { display: grid; gap: var(--space-4); }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: var(--space-5); }

.stat-card { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-4) var(--space-5); }
.stat-icon { font-size: 15px; opacity: .6; line-height: 1; }
.stat-label {
  color: var(--muted); font-size: 12px; font-weight: 500;
  text-transform: none; letter-spacing: 0;
}
.stat-value {
  font-size: 24px; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.stat-change { font-size: 12px; font-weight: 500; }
.stat-change.positive { color: var(--positive); }
.stat-change.warn { color: var(--caution); }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
  margin: 0 0 var(--space-5);
}
.section-head h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
.section-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* --- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; white-space: nowrap;
  cursor: pointer; color: var(--text);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:active { transform: translateY(0.5px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--positive); color: #06210f; font-weight: 600; }
.btn-success:hover { filter: brightness(1.08); }
.btn-danger { background: var(--critical); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--accent); }
.btn-ghost:disabled:hover { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }

/* --- Tables ------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: left; padding: 9px var(--space-4);
  color: var(--muted); font-weight: 500; font-size: 12px;
  letter-spacing: 0; text-transform: none;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px var(--space-4);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:first-child td { border-top: none; }
tbody tr { transition: background var(--dur) var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody td .num, tbody td.num { font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; line-height: 18px;
  border: 1px solid transparent;
}
.badge.green  { background: var(--positive-quiet); color: var(--positive); border-color: rgba(52,199,123,.22); }
.badge.orange { background: var(--caution-quiet);  color: var(--caution);  border-color: rgba(229,160,60,.22); }
.badge.red    { background: var(--critical-quiet); color: var(--critical); border-color: rgba(240,97,109,.22); }
.badge.blue   { background: var(--accent-quiet);   color: var(--accent);   border-color: var(--accent-line); }
.badge.gray   { background: var(--surface-3);      color: var(--muted);    border-color: var(--border); }

/* --- Forms -------------------------------------------------------------- */
label {
  display: block; margin-bottom: 5px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
}
input, select, textarea {
  width: 100%; height: 34px; padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text); font-size: 13.5px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none; background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-quiet);
}
textarea { height: auto; min-height: 84px; padding: 9px 10px; resize: vertical; line-height: 1.55; }
select {
  appearance: none; padding-right: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a929c' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
input[type="checkbox"] {
  width: 15px; height: 15px; padding: 0; cursor: pointer;
  accent-color: var(--accent); vertical-align: -2px;
}
.form-row { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: var(--space-3); }
.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }
.switch {
  display: flex; align-items: center; gap: var(--space-2);
  cursor: pointer; margin-bottom: 0;
  font-size: 13.5px; font-weight: 450; color: var(--text);
}
.switch input { width: auto; height: auto; }
.hint { color: var(--faint); font-size: 12.5px; margin-top: 5px; line-height: 1.5; }

details > summary {
  cursor: pointer; color: var(--accent);
  font-size: 13px; font-weight: 500;
  list-style: none; padding: 4px 0;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '▸ '; display: inline-block; transition: transform var(--dur) var(--ease); }
details[open] > summary::before { content: '▾ '; }

/* --- Modal -------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center;
  padding: var(--space-5);
}
.modal-overlay.open { display: flex; animation: fade 120ms var(--ease); }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  width: 100%; max-width: 520px; max-height: 88vh;
  display: flex; flex-direction: column;
  animation: rise 180ms var(--ease);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: var(--space-5); overflow-y: auto; }
.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex; gap: var(--space-2); justify-content: flex-end;
  flex-shrink: 0;
}
.modal-close {
  background: transparent; border: none; color: var(--faint);
  font-size: 18px; cursor: pointer; line-height: 1;
  padding: 4px 6px; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* --- Login -------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5); }
.login-card {
  width: 100%; max-width: 360px;
  padding: var(--space-7);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}
.login-card .brand {
  height: auto; padding: 0; border: none;
  justify-content: flex-start; margin-bottom: var(--space-5);
}
.login-card h2 { font-size: 18px; margin-bottom: var(--space-1); }
.login-card p.sub { color: var(--muted); font-size: 13px; margin-bottom: var(--space-6); }

/* --- Toasts ------------------------------------------------------------- */
#toast-container {
  position: fixed; bottom: var(--space-5); right: var(--space-5); z-index: 200;
  display: flex; flex-direction: column-reverse; gap: var(--space-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 260px; max-width: 380px;
  padding: 10px var(--space-4);
  border-radius: var(--radius);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  display: flex; align-items: flex-start; gap: var(--space-2);
  font-size: 13.5px; line-height: 1.45;
  animation: toast-in 180ms var(--ease);
}
.toast.success { border-left: 2px solid var(--positive); }
.toast.error   { border-left: 2px solid var(--critical); }
.toast.info    { border-left: 2px solid var(--accent); }
.toast.fade-out { animation: toast-out 140ms var(--ease) forwards; }

/* --- Utilities ---------------------------------------------------------- */
.empty { text-align: center; color: var(--faint); padding: var(--space-8) var(--space-5); font-size: 13.5px; }
.muted { color: var(--muted); }
.chart-card { padding: var(--space-5); }
.chart-card canvas { max-height: 280px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
}

.tabbar {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tab {
  height: 28px; padding: 0 var(--space-3);
  background: transparent; border: none;
  border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* --- Motion ------------------------------------------------------------- */
@keyframes enter     { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes fade      { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise      { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }
@keyframes shimmer   { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 960px) {
  .sidebar { position: fixed; transform: translateX(-100%); box-shadow: var(--shadow-3); }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: block; }
  .content { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); }
  #toast-container { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); }
  .toast { max-width: none; }
}


/* ── Generated-password banner ────────────────────────────
   Caution, not danger: nothing is broken, something is unfinished. */
#pw-banner {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 11px 16px;
  font-size: 14px;
  line-height: 1.45;
  color: #2c1d00;
  background: linear-gradient(90deg, #f6c455, #f0aa2c);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
#pw-banner a,
#pw-banner button {
  flex-shrink: 0;
  padding: 5px 13px;
  border: 1px solid rgba(44, 29, 0, .32);
  border-radius: 7px;
  background: rgba(255, 255, 255, .5);
  color: #2c1d00;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
#pw-banner a:hover,
#pw-banner button:hover { background: rgba(255, 255, 255, .78); }
