/* TFauto — sistem de design.
   Principii: tipografie de sistem (SF Pro pe iOS), ierarhie prin spațiere, UN singur accent.
   Verdele și roșul sunt REZERVATE pentru win/loss — o stare „bună" folosește accentul, nu verde.
   Mobile-first: telefonul primește tab bar jos (tiparul iOS), desktopul bara de sus.
   Fără build, fără framework — un singur fișier, citibil de sus în jos. */

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

:root {
  color-scheme: light dark;

  /* spațiere: o scară de 4, ca totul să se alinieze fără valori inventate pe loc */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  /* tipografie */
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 15px;
  --fs-md: 17px; --fs-lg: 22px; --fs-xl: 28px; --fs-2xl: 34px;

  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-full: 999px;

  /* ținta minimă de atingere (Apple HIG) — nu coborî sub ea pe niciun control */
  --tap: 44px;

  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-sunken: #f0f0f2;
  --text: #1d1d1f;
  /* Cele două tonuri secundare poartă TEXT MIC — titlurile de card la 12px, antetele de tabel la
     11px, rolul timeframe-ului — deci trebuie să treacă pragul WCAG AA de 4,5:1 pe FIECARE
     suprafață a temei, inclusiv pe cea scufundată. Valorile de dinainte (#6e6e73 / #8e8e93) dădeau
     4,46:1 și 2,86:1 acolo: cifre alese din ochi. Cele de acum sunt calculate, iar
     `tests/unit/test_panel_markup.py` reface calculul la fiecare rulare. */
  --text-dim: #5c5c61;
  --text-faint: #6c6c71;
  --accent: #0071e3;
  --ok: #0071e3;
  --warn: #b25000;
  --win: #1d9a4e;   /* REZERVATE strict pentru win/loss (regula operatorului) */
  --loss: #d92d20;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --blur: saturate(180%) blur(20px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --surface: #1c1c1e;
    --surface-sunken: #2c2c2e;
    --text: #f5f5f7;
    /* Aceeași regulă ca în tema deschisă, doar în cealaltă direcție. Pe `--surface-sunken`
       (#2c2c2e), vechiul #636366 dădea 2,33:1 — cel mai slab contrast din tot panoul. */
    --text-dim: #b4b4b9;
    --text-faint: #939398;
    --accent: #0a84ff;
    --ok: #0a84ff;
    --warn: #ff9f0a;
    --win: #30d158;
    --loss: #ff453a;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

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

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.47;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Un singur inel de focus, vizibil pe orice fundal — accesibilitatea la tastatură nu e opțională */
: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. Fără ea, navigarea
   la tastatură trece prin toată bara de sus înainte de a ajunge la pagină, pe fiecare încărcare. */
.skip-link {
  position: absolute;
  left: var(--s4);
  top: -100%;
  z-index: 40;
  padding: var(--s2) var(--s4);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: var(--s2); }

.brand { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.6px; }
.brand span { color: var(--accent); }
.brand.small { font-size: var(--fs-md); letter-spacing: -0.3px; }

.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: var(--fs-xs); }
.detail { color: var(--text-dim); font-size: var(--fs-sm); margin-top: var(--s1); }
.tf-role { color: var(--text-faint); font-size: 0.9em; }
.msg-preview { color: var(--text-faint); margin-bottom: var(--s2); }

/* ============================================================ 3. Navigație */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s4);
  padding-top: max(var(--s3), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;   /* fără el, conținutul trecea peste bară la derulare */
}
.topbar .brand { margin-right: auto; }

.mainnav { display: none; }   /* pe telefon navigația e jos, în tab bar */

.topnav { display: flex; align-items: center; gap: var(--s2); }
.whoami { color: var(--text-dim); font-size: var(--fs-sm); }

/* Comutatorul de instrument: e în bară pe TOATE paginile instanței, deci trebuie să rămână
   discret și, pe telefon, la fel de ușor de atins ca restul controalelor. */
.instance-switch {
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

/* --- tab bar (telefon): tiparul iOS, la îndemâna degetului mare --- */
.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);   /* deasupra home indicator-ului */
}
.tabbar a, .tabbar summary {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap);
  padding: var(--s2) var(--s1) var(--s1);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1px;
  list-style: none;
  cursor: pointer;
}
.tabbar summary::-webkit-details-marker { display: none; }
/* Dimensiunea iconului stă pe ELEMENT (`width`/`height` în `shell.html`), nu aici: un `<svg>` cu
   `viewBox` dar fără dimensiune intrinsecă nu urmează fontul, ci cade pe dimensiunea implicită a
   obiectului. Aici a fost `font-size`, rămășiță de pe vremea când iconurile erau emoji — pe un
   element înlocuit nu decide nimic, deci bara ajunsese să ocupe jumătate de ecran pe telefon.
   `flex: none` îl ține la dimensiunea lui: fără el, iconul e element flex și s-ar putea strânge. */
.tabbar .tab-icon { flex: none; }
.tabbar a.active, .tabbar details[open] > summary { color: var(--accent); }

/* „Mai mult" — foaie care urcă peste tab bar; pur HTML/CSS, fără JavaScript */
.tabbar details { flex: 1; display: flex; position: relative; }
.tabbar details > summary { width: 100%; }
.tabbar .more-sheet {
  position: absolute;
  bottom: 100%;
  right: var(--s2);
  min-width: 200px;
  margin-bottom: var(--s2);
  padding: var(--s2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
}
.tabbar .more-sheet a {
  flex: none;
  flex-direction: row;
  justify-content: flex-start;
  gap: var(--s3);
  font-size: var(--fs-base);
  padding: 0 var(--s3);
  border-radius: var(--r-sm);
  color: var(--text);
}
.tabbar .more-sheet a.active { color: var(--accent); font-weight: 600; }

/* ============================================================ 4. Pagină */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--s5) var(--s4);
  /* loc pentru tab bar + home indicator, ca ultimul card să nu rămână sub el */
  padding-bottom: calc(var(--tap) + var(--s6) + env(safe-area-inset-bottom));
}
.page h1 { font-size: var(--fs-lg); letter-spacing: -0.4px; line-height: 1.2; }
.page > h1 { margin-bottom: var(--s2); }
.page-note { color: var(--text-dim); font-size: var(--fs-sm); margin: var(--s2) 0 var(--s4); }

.flash {
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  font-size: var(--fs-sm);
  margin-bottom: var(--s4);
  border: 1px solid var(--border);
  background: var(--surface);
}
.flash-ok { color: var(--accent); }
.flash-warn { color: var(--warn); }

/* ============================================================ 5. Carduri */

.cards { display: grid; grid-template-columns: 1fr; gap: var(--s3); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: var(--s4);
}
.card h2 {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--s3);
}
.card h3 { font-size: var(--fs-base); font-weight: 600; }
.card.wide { grid-column: 1 / -1; }

/* --- card-erou: „ce face botul acum", singurul lucru citit de la distanță --- */
.hero { grid-column: 1 / -1; padding: var(--s5) var(--s4); }
.hero-state {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  flex-wrap: wrap;
}
.hero-headline {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.15;
}
.hero-dot { font-size: var(--fs-lg); line-height: 1; }
.hero[data-state="ready"] .hero-dot, .hero[data-state="ready"] .hero-headline { color: var(--accent); }
.hero[data-state="blocked"] .hero-dot, .hero[data-state="blocked"] .hero-headline { color: var(--warn); }
.hero[data-state="paused"] .hero-dot { color: var(--text-faint); }
.hero-detail { color: var(--text-dim); font-size: var(--fs-base); margin-top: var(--s2); }
.hero-actions { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; margin-top: var(--s4); }

/* rând compact de indicatori (infrastructură, contoare) */
.metrics { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }
.metric { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); }
.metric-label { color: var(--text-dim); }

.stat-big { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.8px; line-height: 1.1; }
.stat-big .stat-label { font-size: var(--fs-sm); color: var(--text-dim); font-weight: 500; margin-left: 2px; }
.pl-live { font-size: var(--fs-md); font-weight: 600; margin: var(--s2) 0; font-variant-numeric: tabular-nums; }

/* ============================================================ 6. Stări */

.status { font-size: var(--fs-md); font-weight: 600; display: flex; align-items: center; gap: var(--s2); }
.status.ok { color: var(--ok); }
.status.bad { color: var(--warn); }
.status.muted { color: var(--text-dim); }
.status-inline.ok { color: var(--ok); }
.status-inline.bad { color: var(--warn); }
.status-inline.muted { color: var(--text-dim); }
.badge-pending { color: var(--warn); font-weight: 600; margin-top: var(--s2); }
/* Modificator de culoare pentru un text care rămâne altfel obișnuit („`detail warn`"). Trebuie să
   vină DUPĂ `.detail`: ambele sunt selectori de o clasă, deci ordinea din fișier decide. A fost
   folosit în șabloane fără să existe aici, iar avertismentele coordonatorului se scriau în gri —
   exact ca textul pe lângă care trebuiau să iasă în evidență. */
.warn { color: var(--warn); }

.pill {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  vertical-align: middle;
}
.pill-win { color: var(--win); border-color: color-mix(in srgb, var(--win) 40%, transparent); }
.pill-loss { color: var(--loss); border-color: color-mix(in srgb, var(--loss) 40%, transparent); }

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

.btn-primary, .btn-ghost {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);           /* ținta de atingere, peste tot */
  padding: var(--s2) var(--s5);
  border-radius: var(--r-sm);
  cursor: pointer;
  border: none;
  transition: filter 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { color: #fff; background: var(--accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.btn-ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.btn-primary:disabled, .btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }
.btn-link {
  display: inline-flex;
  align-items: center;
  width: auto;
  text-decoration: none;
  margin-top: var(--s3);
}
.inline-form { display: inline-block; margin: 0; }
.actions { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
/* acțiuni dintr-un tabel: compacte, dar tot cu ținta de atingere pe verticală */
.table .actions .btn-ghost { padding: var(--s1) var(--s3); font-size: var(--fs-sm); }

.field { display: block; margin-bottom: var(--s3); }
.field > span {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-bottom: var(--s1);
}
/* Nota de sub un câmp: referința instrumentului lângă override-ul operatorului. `--text-dim`,
   nu `--text-faint` — acela cade sub 4.5:1 pe suprafețele scufundate, tocmai la text mic. */
.field-note {
  display: block;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  margin-top: var(--s1);
}
.field input, .field select, .config-form select {
  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;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.field select, .config-form select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--s6);
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field input:disabled { opacity: 0.5; }
.config-form { max-width: 460px; }
.config-form .btn-primary { margin-top: var(--s2); }

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

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--s1)); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left;
  color: var(--text-faint);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: var(--s3); border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table a { color: var(--accent); text-decoration: none; }

/* Pe telefon, tabelele MARCATE cu `.table-stack` devin rânduri-card: fiecare celulă pe linia ei,
   cu eticheta din `data-label`. Se aplică doar celor două citite efectiv pe telefon (pozițiile
   semnalului și lista de tranzacții); tabelele dense de pe /stats, /ml, /system rămân cu derulare
   orizontală, fiindcă acolo comparația pe coloane e chiar rostul lor. */
@media (max-width: 767px) {
  /* antetul rămâne în DOM pentru cititoarele de ecran, dar iese din pagină; `clip-path`, nu
     `clip`, care e depreciat de ani. */
  .table-stack thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
  .table-stack tr {
    display: block;
    padding: var(--s3) 0;
    border-bottom: 1px solid var(--border);
  }
  .table-stack 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-weight: 600; font-size: var(--fs-md); }
  .table-stack td:first-child::before { content: none; }
}

/* ============================================================ 9. Secțiuni pliabile */

.knobs { border-top: 1px solid var(--border); }
.knobs:first-of-type { border-top: none; }
.knobs > summary {
  cursor: pointer;
  font-size: var(--fs-base);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) 0;
  color: var(--text);
  list-style: none;
}
.knobs > summary::-webkit-details-marker { display: none; }
.knobs > summary::before {
  content: "›";
  color: var(--text-faint);
  font-size: var(--fs-md);
  transition: transform 0.15s;
}
.knobs[open] > summary::before { transform: rotate(90deg); }
.knobs .config-form { margin-top: var(--s3); }
.knobs .detail { margin-bottom: var(--s2); }
/* Reset: formular separat (HTML nu permite formulare imbricate), vizual subordonat salvării */
.reset-form {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  margin: var(--s4) 0 var(--s4);
  padding-top: var(--s3);
  border-top: 1px dashed var(--border);
}
.reset-form .detail { margin: 0; flex: 1 1 240px; }

.strategy-block { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border); }
.strategy-block:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
.strategy-block h3 .detail { display: inline; font-weight: 400; margin: 0; }

/* ============================================================ 10. Grafic */

/* Graficul e singurul SVG RESPONSIV din panou: dimensiunea îi vine de aici, nu de pe element, unde
   niște atribute fixe ar strica exact întinderea. Clasa e pe `<svg>`, nu un selector descendent
   (`.chart svg`), ca intenția să fie scrisă acolo unde se aplică — și verificabilă. */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-zero { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-dot { fill: var(--accent); }
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: color-mix(in srgb, var(--accent) 18%, transparent); }
.chart-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart-axis { fill: var(--text-faint); font-size: 11px; }

/* ============================================================ 11. Login */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--s6) var(--s5) var(--s5);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card .field { text-align: left; }
.login-card .btn-primary { width: 100%; }
.subtitle { color: var(--text-dim); font-size: var(--fs-base); margin: var(--s1) 0 var(--s5); }
.form-error { color: var(--warn); font-size: var(--fs-sm); margin-bottom: var(--s3); }

/* ============================================================ 12. Praguri */

/* tabletă și peste: navigația urcă în bară, cardurile trec pe două coloane */
@media (min-width: 768px) {
  .tabbar { display: none; }
  .mainnav { display: flex; gap: 2px; flex-wrap: wrap; }
  .mainnav a {
    display: flex;
    align-items: center;
    min-height: 36px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: var(--fs-sm);
    font-weight: 500;
    padding: 0 var(--s3);
    border-radius: var(--r-sm);
    transition: background 0.15s, color 0.15s;
  }
  .mainnav a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
  .mainnav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
  .page { padding: var(--s6) var(--s5); padding-bottom: var(--s7); }
  .page h1 { font-size: var(--fs-xl); }
  .cards { grid-template-columns: repeat(2, 1fr); gap: var(--s4); }
  .card { padding: var(--s5); }
}

/* desktop: trei coloane */
@media (min-width: 1060px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  .hero-headline { font-size: var(--fs-2xl); }
}
