/* BTCscan — același sistem de design ca panoul TFauto, în culorile TraderFolks.
   Inter local, ierarhie prin spațiere și greutate, suprafețe calme, culoare doar unde poartă sens:
   albastrul mărcii = accentul interfeței; chihlimbar = atenție; carmin = eroare.
   Culoarea nu e niciodată singurul purtător de sens: starea are mereu și cuvântul.
   Mobile-first: telefonul primește bara de sus + tab bar jos, desktopul (≥1024 px) bara laterală.
   Fără build, fără framework — un singur fișier, citibil de sus în jos. */

/* ============================================================ 0. Font */

/* Inter (OFL, `static/fonts/LICENSE.txt`), variabil: o descărcare pentru toate greutățile.
   Local fiindcă CSP-ul permite doar `'self'`. */
@font-face {
  font-family: "Inter";
  src: url("fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ============================================================ 1. Token-uri */

/* Tema DESCHISĂ. Fiecare token de text trece WCAG AA (4,5:1) pe fiecare suprafață — testul
   `tests/unit/test_panel_markup.py` reface calculul la fiecare rulare. Culorile exacte ale mărcii
   (`--brand-*`) nu trec pragul ca text mic, deci colorează doar semnul și dunga de sus. */
:root {
  color-scheme: light;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 15px;
  --fs-md: 17px; --fs-lg: 22px; --fs-xl: 28px; --fs-2xl: 34px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 999px;

  /* ținta minimă de atingere — nu coborî sub ea pe niciun control */
  --tap: 44px;
  --sidebar: 252px;

  --brand-blue: #0087f6;
  --brand-orange: #dd390d;

  --bg: #f4f6fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-sunken: #eceff4;
  --text: #141a24;
  --text-dim: #4d5666;
  --text-faint: #5f6878;
  --accent: #0067c7;
  --on-accent: #ffffff;
  --warn: #855a00;
  --danger: #c0174a;
  --border: rgba(20, 26, 36, 0.09);
  --border-strong: rgba(20, 26, 36, 0.16);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 8px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --blur: saturate(180%) blur(18px);
}

/* Tema ÎNTUNECATĂ, scrisă de două ori cu ACELEAȘI valori: pentru „auto" pe un sistem întunecat și
   pentru alegerea explicită. Testul cere ca cele două blocuri să fie identice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0d13;
    --bg-elevated: #1a2030;
    --surface: #131823;
    --surface-sunken: #212838;
    --text: #eef1f6;
    --text-dim: #b3bccb;
    --text-faint: #959fb0;
    --accent: #4aa6ff;
    --on-accent: #06121f;
    --warn: #f2c14e;
    --danger: #ff5f8d;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0d13;
    --bg-elevated: #1a2030;
    --surface: #131823;
    --surface-sunken: #212838;
    --text: #eef1f6;
    --text-dim: #b3bccb;
    --text-faint: #959fb0;
    --accent: #4aa6ff;
    --on-accent: #06121f;
    --warn: #f2c14e;
    --danger: #ff5f8d;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
}

/* ============================================================ 2. Bază */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
/* Un link în mijlocul unui text se recunoaște după subliniere, nu doar după culoare (WCAG 1.4.1). */
.detail a, .page-note a, .kpi-sub a {
  text-decoration: underline;
  text-underline-offset: 3px;
}
code { font-family: var(--font-mono); font-size: 0.9em; }
strong { font-weight: 650; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* „Sari la conținut": prima oprire a tabulării, invizibilă până primește focus. */
.skip-link {
  position: absolute;
  left: var(--s4);
  top: -100%;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--s4);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.skip-link:focus { top: var(--s2); }

.mono { font-family: var(--font-mono); font-size: var(--fs-xs); word-break: break-all; }
.num, .kpi-value { font-variant-numeric: tabular-nums; }
.detail { color: var(--text-dim); font-size: var(--fs-sm); margin-top: var(--s1); }
.warn { color: var(--warn); }

/* ============================================================ 3. Marca */

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text);
  font-weight: 750;
  letter-spacing: -0.4px;
  font-size: var(--fs-md);
  min-height: var(--tap);
}
.brand:hover { text-decoration: none; }
.brand-mark { display: block; flex: none; }
.brand-name span { color: var(--accent); }

/* ============================================================ 4. Cadrul aplicației */

.app { min-height: 100dvh; }
.sidebar { display: none; }
.icon { flex: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
  padding-top: max(var(--s2), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { margin-right: auto; }

.menu { position: relative; }
.menu > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--r-full);
  color: var(--text-dim);
  cursor: pointer;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.menu-sheet {
  position: absolute;
  right: 0;
  top: calc(100% + var(--s2));
  min-width: 240px;
  padding: var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}
.whoami {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.theme-switch {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
}
.theme-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
}
.theme-label { line-height: 1; }
.theme-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* --- tab bar (telefon, tabletă) --- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: var(--s2) var(--s1) var(--s1);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 550;
}
.tab:hover { text-decoration: none; }
.tab.active { color: var(--accent); }

/* --- bara laterală (desktop) --- */
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--tap);
  padding: 0 var(--s3);
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: 550;
  transition: background 0.15s, color 0.15s;
}
.side-link:hover { text-decoration: none; color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.side-link.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 650; }
.side-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding-top: var(--s4);
  border-top: 1px solid var(--border);
}
.side-user { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 0 var(--s1); }

/* ============================================================ 5. Pagină */

.page {
  /* `width` NU e redundant: `.page` e element de grilă, iar marginile `auto` îl strângeau la
     lățimea conținutului (defect găsit și reparat în panoul TFauto). */
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--s5) var(--s4);
  padding-bottom: calc(52px + var(--s6) + env(safe-area-inset-bottom));
}

.page-head { margin-bottom: var(--s5); }
.eyebrow {
  color: var(--text-faint);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: var(--s1);
}
.page h1 { font-size: var(--fs-xl); font-weight: 750; letter-spacing: -0.6px; line-height: 1.15; }
.page-note { color: var(--text-dim); font-size: var(--fs-sm); margin-top: var(--s2); max-width: 75ch; }

/* ============================================================ 6. Carduri și KPI */

.cards { display: grid; grid-template-columns: 1fr; gap: var(--s4); }
.cards, .kpis { margin-bottom: var(--s4); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--s5);
  min-width: 0;
}
.card h2 {
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--s3);
}
.card.wide { grid-column: 1 / -1; }
.card-foot { margin-top: var(--s4); padding-top: var(--s2); border-top: 1px solid var(--border); display: flex; gap: var(--s4); flex-wrap: wrap; font-size: var(--fs-sm); }
.card-foot a { display: inline-flex; align-items: center; min-height: var(--tap); }

/* Cardul de stare: singurul lucru citit de la distanță. Dunga mărcii e decor, fără sens. */
.hero { grid-column: 1 / -1; position: relative; overflow: hidden; }
.hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-blue), var(--brand-orange));
}
.hero-state { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.hero-headline { font-size: var(--fs-xl); font-weight: 750; letter-spacing: -0.6px; line-height: 1.15; }
.hero-dot { font-size: var(--fs-lg); line-height: 1; }
.hero[data-state="scanning"] .hero-dot, .hero[data-state="scanning"] .hero-headline { color: var(--accent); }
.hero[data-state="idle"] .hero-dot, .hero[data-state="idle"] .hero-headline { color: var(--warn); }
.hero[data-state="no_index"] .hero-dot, .hero[data-state="no_index"] .hero-headline { color: var(--danger); }
.hero-detail { color: var(--text-dim); margin-top: var(--s2); }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  min-width: 0;
}
.kpi-label { color: var(--text-faint); font-size: 11px; font-weight: 650; letter-spacing: 0.6px; text-transform: uppercase; }
/* Un număr nu se rupe la mijloc („2,613,611,7 / 38" pe telefon): se micșorează cu ecranul. */
.kpi-value { font-size: clamp(var(--fs-md), 5vw, var(--fs-lg)); font-weight: 700; letter-spacing: -0.4px; line-height: 1.2; }
.kpi-sub { color: var(--text-dim); font-size: var(--fs-sm); }

.status { font-size: var(--fs-md); font-weight: 650; display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.kpi .status { font-size: clamp(var(--fs-md), 5vw, var(--fs-lg)); }
/* o stare sănătoasă folosește accentul, ca pe Overview și în TFauto */
.status.ok { color: var(--accent); }

/* ============================================================ 7. Controale */

.btn-primary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font: inherit;
  font-weight: 650;
  min-height: var(--tap);
  padding: var(--s2) var(--s5);
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter 0.15s, background 0.15s;
  white-space: nowrap;
}
.btn-primary { color: var(--on-accent); background: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); text-decoration: none; }
.btn-ghost { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.btn-ghost:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); text-decoration: none; }
/* „mic" pe orizontală și ca text — NU pe verticală: ținta de atingere rămâne cea a casei */
.btn-sm { min-height: var(--tap); padding: 0 var(--s3); font-size: var(--fs-sm); }
.inline-form { display: inline-flex; margin: 0; }

.field { display: block; margin-bottom: var(--s4); text-align: left; }
.field > span { display: block; font-size: var(--fs-sm); font-weight: 550; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%;
  font: inherit;
  font-size: var(--fs-md);   /* ≥16px: sub asta, iOS mărește pagina la focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
  min-height: var(--tap);
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ============================================================ 8. Tabele */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--s2)); }
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left;
  color: var(--text-faint);
  font-weight: 650;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: var(--s2);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.table td { padding: var(--s3) var(--s2); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody th { border-bottom: 1px solid var(--border); padding: var(--s3) var(--s2); }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: none; }
.table .num, .table th.num { text-align: right; }
.empty { color: var(--text-dim); text-align: center; padding: var(--s5); }

/* Pe telefon, tabelele `.table-stack` devin rânduri-card: fiecare celulă pe linia ei, cu eticheta
   din `data-label`; antetul rămâne pentru cititoarele de ecran. */
@media (max-width: 767px) {
  .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-stack tr { display: block; padding: var(--s3) var(--s2); border-bottom: 1px solid var(--border); }
  .table-stack tbody tr:last-child { border-bottom: none; }
  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s4);
    padding: var(--s1) 0;
    border: none;
    text-align: right;
  }
  .table-stack td::before { content: attr(data-label); color: var(--text-dim); font-size: var(--fs-sm); text-align: left; flex: none; }
  .table-stack td:first-child { font-size: var(--fs-sm); }
  .table-stack td.empty { justify-content: center; }
  .table-stack td.empty::before { content: none; }
}

.pager { display: flex; justify-content: space-between; gap: var(--s3); margin-top: var(--s4); }

/* ============================================================ 9. Login */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
  background:
    radial-gradient(60% 50% at 15% 10%, color-mix(in srgb, var(--brand-blue) 14%, transparent), transparent 70%),
    radial-gradient(50% 45% at 90% 95%, color-mix(in srgb, var(--brand-orange) 12%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s6) var(--s5) var(--s5);
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card .brand { flex-direction: column; gap: var(--s3); font-size: var(--fs-xl); }
.login-card .btn-primary { width: 100%; }
.subtitle { color: var(--text-dim); margin: var(--s1) 0 var(--s5); }
.form-error { color: var(--danger); font-size: var(--fs-sm); margin-bottom: var(--s3); }

/* ============================================================ 10. Praguri */

@media (min-width: 768px) {
  .page { padding: var(--s6) var(--s5); padding-bottom: calc(52px + var(--s7)); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .page h1 { font-size: var(--fs-2xl); }
}

/* desktop: bara laterală înlocuiește bara de sus și tab bar-ul */
@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .topbar, .tabbar { display: none; }
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--s5);
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    padding: var(--s5) var(--s3) var(--s4);
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 0 var(--s2); }
  .page { padding: var(--s6) var(--s6) var(--s7); }
}
