:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #0f1420;
  --line: #232b3d;
  --text: #e8ecf3;
  --muted: #8a94a7;
  --accent: #c9a96e;
  --accent-ink: #14110a;
  --error: #f08a8a;
  --ok: #8fd0a8;
  --warn: #e7c66b;
  --info: #8db4f0;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* --- Barra in alto ------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(11,15,23,.92); backdrop-filter: blur(6px); z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .3em; color: var(--text); text-decoration: none; }
.brand-sub { color: var(--muted); font-size: 14px; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.nav a.on, .nav a:hover { color: var(--text); background: var(--panel); }
.logout { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.logout .who { color: var(--muted); font-size: 14px; }

/* --- Struttura ------------------------------------------------------------ */
.page { max-width: 1100px; margin: 0 auto; padding: 32px 16px 64px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin-bottom: 16px;
}
.card.narrow { max-width: 420px; margin: 24px auto; padding: 32px; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin-bottom: 0; }
.cols + .card { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.grid3.tight { grid-template-columns: 2fr 1fr 1fr; gap: 0 10px; }

h1 { font-size: 24px; margin: 0 0 4px; font-weight: 600; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 13px; margin: 0 0 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.card h2:not(:first-child) { margin-top: 24px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; margin-top: 12px; }
.eyebrow { color: var(--muted); font-size: 13px; margin: 0 0 4px; letter-spacing: .04em; }
.prewrap { white-space: pre-wrap; margin: 0; }

/* --- Form ------------------------------------------------------------------ */
form { display: grid; gap: 6px; }
form.stack { gap: 6px; }
fieldset { border: 0; padding: 0; margin: 0 0 20px; }
legend { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
label { font-size: 14px; color: var(--muted); margin-top: 8px; display: block; }
input, select, textarea {
  width: 100%; padding: 11px 13px; font-size: 16px; font-family: inherit;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input.code { font-size: 26px; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.plate-input { font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 4px; }
.segmented label { margin: 0; padding: 8px 14px; cursor: pointer; display: flex; gap: 8px; align-items: center; color: var(--text); }
.segmented label + label { border-left: 1px solid var(--line); }
.segmented input { width: auto; }

button, .button {
  display: inline-block; margin-top: 14px; padding: 11px 18px; font-size: 15px; font-weight: 600; font-family: inherit;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; text-align: center;
  border: 1px solid var(--accent); border-radius: 8px; cursor: pointer;
}
.head .button { margin-top: 0; white-space: nowrap; }
button:hover, .button:hover { filter: brightness(1.08); }
button.ghost, .button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { background: transparent; color: var(--error); border-color: rgba(240,138,138,.5); }
button.small { margin: 0; padding: 6px 12px; font-size: 14px; }

.error, .notice { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 15px; }
.error { background: rgba(240,138,138,.1); border: 1px solid rgba(240,138,138,.4); color: var(--error); }
.notice { background: rgba(143,208,168,.08); border: 1px solid rgba(143,208,168,.35); color: var(--ok); }

/* --- Elenchi --------------------------------------------------------------- */
.search { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chips a {
  font-size: 14px; color: var(--muted); text-decoration: none;
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px;
}
.chips a span { color: var(--text); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chips a.on { border-color: var(--accent); color: var(--text); }

.list { display: grid; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.list.compact { border: 0; background: none; }
.list-row {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 16px;
  padding: 14px 18px; color: var(--text); text-decoration: none; border-top: 1px solid var(--line);
}
.list-row:first-child { border-top: 0; }
.list-row:hover { background: var(--panel-2); }
.list-row .main { display: grid; min-width: 0; }
.list-row .main small, .list-row .date, .list-row .count { color: var(--muted); font-size: 13px; }
.list-row .main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list.compact .list-row { grid-template-columns: auto 1fr auto; padding: 10px 0; }
.empty { padding: 40px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.plate {
  font-family: ui-monospace, Menlo, monospace; font-weight: 600; letter-spacing: .1em;
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-size: 14px;
}
.plate.big { font-size: 20px; padding: 2px 10px; }

.badge {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap;
  background: rgba(141,180,240,.12); color: var(--info); border: 1px solid rgba(141,180,240,.3);
}
.badge.large { font-size: 14px; padding: 6px 14px; }
.badge.s-richiesta, .badge.s-mandato { background: rgba(231,198,107,.1); color: var(--warn); border-color: rgba(231,198,107,.35); }
.badge.s-chiusa { background: rgba(143,208,168,.1); color: var(--ok); border-color: rgba(143,208,168,.35); }
.badge.s-sospesa, .badge.s-annullata { background: transparent; color: var(--muted); border-color: var(--line); }

/* --- Scheda pratica -------------------------------------------------------- */
.progress { list-style: none; padding: 0; margin: 0 0 20px; display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.progress li { height: 6px; border-radius: 3px; background: var(--line); position: relative; }
.progress li.done { background: var(--accent); opacity: .55; }
.progress li.current { background: var(--accent); }
.progress li span { position: absolute; top: 12px; left: 0; font-size: 11px; color: var(--muted); white-space: nowrap; display: none; }
.progress li.current span { display: block; color: var(--text); }

.facts { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

details.more { margin-top: 20px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details.more form { margin-top: 12px; }
.card > details.more:first-child { margin-top: 0; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 140px 1fr auto; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.timeline li:first-child { border-top: 0; }
.timeline .when, .timeline .who { color: var(--muted); font-size: 13px; }

/* --- Accesso e 2FA ---------------------------------------------------------- */
.steps { padding-left: 20px; margin: 16px 0 24px; }
.steps li { margin-bottom: 6px; }
.qr-wrap { display: grid; justify-items: center; gap: 12px; margin-bottom: 8px; }
.qr { width: 220px; height: 220px; background: #fff; border-radius: 8px; padding: 6px; }
.qr svg { width: 100%; height: 100%; display: block; }
.manual { color: var(--muted); font-size: 14px; text-align: center; }
.manual summary { cursor: pointer; }
.secret { display: block; margin-top: 8px; font-size: 16px; letter-spacing: .1em; color: var(--text); word-break: break-all; }
.card.narrow .muted { margin-bottom: 20px; }

/* --- Telefono --------------------------------------------------------------- */
@media (max-width: 760px) {
  .topbar { gap: 12px; padding: 12px 16px; }
  .logout .who { display: none; }
  .cols, .grid2, .grid3 { grid-template-columns: 1fr; }
  .head { flex-direction: column; }
  .list-row { grid-template-columns: auto 1fr; gap: 6px 12px; }
  .list-row .badge { justify-self: start; }
  .list-row .date, .list-row .count { display: none; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .progress li.current span { font-size: 10px; }
  .card { padding: 18px; }
}

/* Diario operativo */
.journal-form { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.journal { list-style: none; padding: 0; margin: 0; }
.journal li { padding: 12px 0 12px 14px; border-top: 1px solid var(--line); border-left: 3px solid var(--line); margin-left: 2px; }
.journal li:first-child { border-top: 0; }
.journal li.o-risposto, .journal li.o-completato { border-left-color: var(--ok); }
.journal li.o-non_risponde, .journal li.o-occupato, .journal li.o-ufficio_chiuso { border-left-color: var(--error); }
.journal li.o-richiamare, .journal li.o-rimandato { border-left-color: var(--accent); }
.j-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.j-head .when { margin-left: auto; color: var(--muted); font-size: 13px; }
.j-who { color: var(--muted); font-size: 14px; margin-top: 2px; }
.journal p { margin: 6px 0 0; }
.journal .next { color: var(--accent); font-size: 14px; }
.tag { font-size: 12px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
@media (max-width: 640px) { .j-head .when { margin-left: 0; width: 100%; } }
