/* Trading Platform — pannello di configurazione.
   Tema light deliberato: e' una form densa di campi numerici, dove la
   leggibilita' di molti valori piccoli conta piu' di tutto. Palette
   "restrained": neutri freddi + un solo accento indaco. OKLCH, contrasto AA. */

:root {
  /* superfici */
  --bg:        oklch(0.972 0.005 260);
  --surface:   oklch(1 0 0);
  --surface-2: oklch(0.984 0.004 260);

  /* testo */
  --ink:    oklch(0.27 0.02 265);   /* corpo forte, ~11:1 su surface */
  --ink-2:  oklch(0.44 0.02 265);   /* secondario, ~6:1 */
  --muted:  oklch(0.50 0.018 265);  /* etichette/aiuto, ~5.2:1 */

  /* linee */
  --line:   oklch(0.90 0.006 265);
  --line-2: oklch(0.94 0.005 265);

  /* accento (indaco) */
  --accent:        oklch(0.50 0.16 274);
  --accent-strong: oklch(0.43 0.17 274);
  --accent-soft:   oklch(0.95 0.03 274);
  --on-accent:     oklch(0.99 0.01 274);

  /* stati */
  --ok:        oklch(0.50 0.12 155);
  --ok-ink:    oklch(0.40 0.10 155);
  --ok-soft:   oklch(0.96 0.035 155);
  --danger:    oklch(0.52 0.18 27);
  --danger-ink:oklch(0.44 0.17 27);
  --danger-soft:oklch(0.965 0.035 27);

  /* header scuro */
  --head-bg:    oklch(0.24 0.022 266);
  --head-ink:   oklch(0.97 0.008 266);
  --head-muted: oklch(0.74 0.02 266);
  --head-line:  oklch(0.34 0.02 266);

  --r: 12px;
  --r-sm: 8px;
  --r-xs: 6px;
  --shadow: 0 1px 2px oklch(0.27 0.02 265 / 0.06), 0 10px 26px -12px oklch(0.27 0.02 265 / 0.18);
  --ring: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

  /* scala z semantica */
  --z-topbar: 100;
  --z-toast: 600;

  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quint */
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.5rem;
  background: var(--head-bg);
  color: var(--head-ink);
  border-bottom: 1px solid var(--head-line);
}

.brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }

.brand__mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.25);
}

.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__title { font-size: 1.02rem; font-weight: 650; letter-spacing: -0.01em; }
.brand__sub { font-size: 0.8rem; color: var(--head-muted); }

.topnav { display: flex; gap: 0.4rem; align-items: center; }

.topnav button {
  background: transparent;
  color: var(--head-ink);
  border: 1px solid transparent;
  padding: 0.45rem 0.8rem;
  border-radius: var(--r-sm);
  font: inherit;
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.topnav button:hover { background: oklch(1 0 0 / 0.10); }
.topnav button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--head-bg), 0 0 0 4px var(--accent);
}
.topnav__logout { color: var(--head-muted); border-color: var(--head-line) !important; }
.topnav__logout:hover { color: var(--head-ink); }

/* ---------- layout ---------- */
.shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1.5rem 1.5rem 1.65rem;
  box-shadow: var(--shadow);
}

h2 {
  margin: 0 0 1.1rem;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
h3 {
  margin: 1.75rem 0 0.75rem;
  font-size: 1rem;
  font-weight: 620;
  color: var(--ink);
}

/* ---------- fieldset / sezioni parametri ---------- */
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  margin: 1.1rem 0 0;
  padding: 0.4rem 1.1rem 0.9rem;
  background: var(--surface);
}
fieldset > legend {
  padding: 0 0.5rem;
  margin-left: -0.25rem;
  font-weight: 620;
  font-size: 0.95rem;
  color: var(--ink);
  text-transform: capitalize;
}
/* finestra annidata: piu' leggera, mai una "card dentro card" */
fieldset fieldset {
  background: var(--surface-2);
  border-color: var(--line-2);
  margin-top: 0.7rem;
}
fieldset fieldset > legend { font-size: 0.85rem; color: var(--ink-2); text-transform: none; }

/* riga campo: etichetta a sinistra, controllo a destra, allineati */
label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink-2);
  font-size: 0.92rem;
}
fieldset > label:last-of-type,
fieldset fieldset > label:last-of-type { border-bottom: 0; }

/* ---------- controlli ---------- */
input, select {
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 0.4rem 0.55rem;
  min-width: 9rem;
  max-width: 14rem;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
input[type="number"], input[inputmode="numeric"] {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  text-align: right;
}
input[type="checkbox"] {
  min-width: 0;
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  justify-self: end;
}
input:hover, select:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
::placeholder { color: var(--muted); opacity: 1; }

/* ---------- bottoni ---------- */
button {
  font: inherit;
  font-weight: 560;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 0.55rem 1.05rem;
  cursor: pointer;
  transition: background 0.16s var(--ease), transform 0.08s var(--ease), box-shadow 0.16s var(--ease);
}
button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--ring); }

/* bottone primario d'azione: respiro sopra */
#save, #login button, #nu button { margin-top: 1.4rem; }

/* azioni di riga in tabella: secondarie, compatte */
td button {
  color: var(--ink-2);
  background: var(--surface);
  border-color: var(--line);
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 520;
  margin-left: 0.35rem;
}
td button:hover { background: var(--surface-2); border-color: var(--muted); color: var(--ink); }

/* ---------- form login / nuovo utente ---------- */
#login { max-width: 24rem; margin: 4rem auto 0; }
#login label { grid-template-columns: 1fr; gap: 0.3rem; border-bottom: 0; padding: 0.5rem 0 0; }
#login input { max-width: none; width: 100%; text-align: left; font-family: var(--font); }
#login button { width: 100%; }

#nu { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
#nu input { max-width: 12rem; }
#nu button { margin-top: 0; }

/* ---------- tabella utenti ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 0.25rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line-2); }
th {
  font-size: 0.76rem;
  font-weight: 620;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
  border-bottom-color: var(--line);
}
tbody tr:last-child td, table tr:last-child td { border-bottom: 0; }
td { color: var(--ink-2); font-variant-numeric: tabular-nums; }
td:first-child { font-family: var(--mono); color: var(--ink); }

/* ---------- feedback (success / errore) ---------- */
.feedback {
  margin: 0.25rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.9rem;
}
.feedback:empty { display: none; }
.feedback--ok  { color: var(--ok-ink);     background: var(--ok-soft);     border-color: oklch(0.85 0.06 155); }
.feedback--err { color: var(--danger-ink); background: var(--danger-soft); border-color: oklch(0.86 0.07 27); }

/* ---------- toolbar / hint (utenti) ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin: 0.5rem 0 1rem; }
.hint { color: var(--muted); font-size: 0.82rem; max-width: 46ch; }
td button { margin-top: 0.2rem; }

/* ---------- responsive ---------- */
@media (max-width: 600px) {
  .shell { padding: 1.25rem 0.9rem 3rem; }
  .card { padding: 1.15rem; }
  label { grid-template-columns: 1fr; gap: 0.3rem; align-items: start; }
  input, select { max-width: none; width: 100%; text-align: left; }
  input[type="number"], input[inputmode="numeric"] { text-align: left; }
  input[type="checkbox"] { justify-self: start; }
  .brand__sub { display: none; }
}

/* ---------- motion ridotto ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
