/* ---------- Tema: chiaro di default, scuro via sistema o scelta manuale ---------- */
:root {
  color-scheme: light;
  --bg: #f2f2f7;
  --bg-glow-1: rgba(10, 132, 255, 0.10);
  --bg-glow-2: rgba(255, 159, 10, 0.08);
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-2: #f2f2f7;
  --border: rgba(0, 0, 0, 0.06);
  --text: #1c1c1e;
  --text-2: #6e6e73;
  --text-3: #aeaeb2;
  --accent: #0a84ff;
  --ok: #34c759;
  --warn: #ff9f0a;
  --bad: #ff3b30;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.05), 0 16px 40px rgba(0, 0, 0, 0.10);
  --radius: 24px;
  --series-1: #2a78d6;
  --series-muted: #d1d1d6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0b0e;
    --bg-glow-1: rgba(10, 132, 255, 0.14);
    --bg-glow-2: rgba(191, 90, 242, 0.10);
    --surface: rgba(28, 28, 32, 0.78);
    --surface-solid: #1c1c20;
    --surface-2: #2c2c30;
    --border: rgba(255, 255, 255, 0.07);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #636366;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.5);
    --series-1: #3987e5;
    --series-muted: #48484e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0e;
  --bg-glow-1: rgba(10, 132, 255, 0.14);
  --bg-glow-2: rgba(191, 90, 242, 0.10);
  --surface: rgba(28, 28, 32, 0.78);
  --surface-solid: #1c1c20;
  --surface-2: #2c2c30;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #636366;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.5);
  --series-1: #3987e5;
  --series-muted: #48484e;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(60vw 50vh at 10% -10%, var(--bg-glow-1), transparent 70%),
    radial-gradient(50vw 50vh at 100% 0%, var(--bg-glow-2), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s, color .3s;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ---------- Barra in alto ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1120px;
  margin: 12px auto 0;
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
body > .topbar { margin-inline: max(16px, calc((100% - 1120px) / 2)); }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand-logo { width: 34px; height: 34px; border-radius: 50%; display: block; }

nav { display: flex; gap: 4px; flex: 1; justify-content: center; }
nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  transition: background .2s, color .2s;
}
nav a .icon { font-size: 15px; }
nav a:hover { color: var(--text); }
nav a.active { background: var(--surface-2); color: var(--text); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  transition: transform .2s;
}
.icon-btn:hover { transform: rotate(15deg); }

/* ---------- Pagina ---------- */
.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 16px 64px;
}
.page.narrow { max-width: 720px; }
.page-head { margin: 0 4px 28px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 12px -4px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  transition: background .2s;
}
.back:hover { background: var(--surface-2); }
.page-head h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 44px);
  font-weight: 700;
  letter-spacing: -0.025em;
}
.sub { margin: 4px 0 0; color: var(--text-2); font-size: 18px; }

/* ---------- Riquadri (Home) ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.tiles-group { display: contents; }

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 168px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  animation: rise .5s cubic-bezier(.2, .8, .2, 1) both;
}
.tile.wide { grid-column: span 2; }
.tiles > :nth-child(2) { animation-delay: .04s; }
.tiles > :nth-child(4) { animation-delay: .12s; }
.tiles-group > :nth-child(1) { animation-delay: .06s; }
.tiles-group > :nth-child(2) { animation-delay: .08s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.tile-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}
.tile-foot { margin-top: auto; font-size: 14px; color: var(--text-2); }

.clock {
  margin: 8px 0 12px;
  font-size: clamp(64px, 9vw, 96px);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Meteo: riquadro colorato in base al tempo */
.weather-tile {
  color: #fff;
  border: 0;
  background: linear-gradient(160deg, #3a8dde, #6bb5ff);
}
.weather-tile[data-tone="night"] { background: linear-gradient(160deg, #1b2347, #3b4a7a); }
.weather-tile[data-tone="grey"] { background: linear-gradient(160deg, #6b7a8f, #9aa7b8); }
.weather-tile[data-tone="rain"] { background: linear-gradient(160deg, #36475e, #61758f); }
.weather-tile { cursor: pointer; transition: transform .25s cubic-bezier(.2, .8, .2, 1), box-shadow .25s; }
.weather-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.weather-tile:active { transform: scale(.98); }
.weather-tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.weather-tile .tile-label { color: rgba(255, 255, 255, .85); }
.weather-top { display: flex; justify-content: space-between; align-items: flex-start; }
.temp { font-size: clamp(56px, 8vw, 80px); font-weight: 300; letter-spacing: -0.04em; line-height: 1.05; }
.weather-icon { font-size: 56px; opacity: .95; }
.weather-icon .icon { stroke-width: 1.5; }
.weather-bottom {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 500;
}
.chips { display: flex; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  font-size: 13px;
}
.chip:empty { display: none; }
.chip .icon { font-size: 13px; }

/* Riscaldamento: arancione quando è acceso */
.heat-tile .heat-icon { font-size: 52px; color: var(--text-3); }
.heat-tile .heat-icon .icon { stroke-width: 1.5; }
.heat-tile[data-state="off"] .heat-icon { color: var(--text-2); }
.heat-tile[data-state="on"] { color: #fff; border: 0; background: linear-gradient(160deg, #ff7a18, #ffb347); }
.heat-tile[data-state="on"] .tile-label, .heat-tile[data-state="on"] .tile-foot { color: rgba(255, 255, 255, .85); }
.heat-tile[data-state="on"] .heat-icon { color: #fff; }
.heat-tile[data-state="off-line"] .temp { color: var(--text-3); }
.heat-tile { transition: background .6s, color .6s; }
.heat-ctrl { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.heat-error { margin: 10px 0 0; font-size: 13px; font-weight: 600; color: var(--bad); }
.heat-tile[data-state="on"] .heat-error { color: #fff; }

/* Interruttore in stile iOS */
.switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  background: var(--text-3);
  cursor: pointer;
  transition: background .25s;
}
.switch i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
  transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"] i { transform: translateX(20px); }
.switch:disabled { opacity: .6; cursor: progress; }
.switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* variante con fiammella: pista arancione, fiamma grigia da spento e arancione da acceso */
.switch.flame { width: 56px; height: 32px; }
.switch.flame i { width: 28px; height: 28px; display: grid; place-items: center; color: var(--text-3); font-size: 15px; transition: transform .25s cubic-bezier(.2, .8, .2, 1), color .25s; }
.switch.flame i .icon { stroke-width: 2.4; }
.switch.flame[aria-checked="true"] { background: #ff8a1f; }
.switch.flame[aria-checked="true"] i { transform: translateX(24px); color: #ff7a00; }
.heat-tile[data-state="on"] .switch.flame[aria-checked="true"] { background: rgba(255, 255, 255, .4); }

/* cambio di stato: piccolo «battito» del riquadro e della fiamma */
.heat-tile.flash { animation: heat-pulse 1.2s cubic-bezier(.2, .8, .2, 1); }
.heat-tile.flash .heat-icon { animation: heat-flame 1.2s ease; }
@keyframes heat-pulse {
  0% { transform: scale(1); }
  25% { transform: scale(1.025); box-shadow: 0 0 0 6px rgba(255, 140, 40, .25), var(--shadow-hover); }
  100% { transform: scale(1); }
}
@keyframes heat-flame { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.25) rotate(-6deg); } 60% { transform: scale(.95) rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { .heat-tile.flash, .heat-tile.flash .heat-icon { animation: none; } }
.heat-tile .tile-foot { margin-top: 0; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
}
.heat-tile[data-state="on"] .pill { background: rgba(255, 255, 255, .22); color: #fff; }
.heat-tile[data-state="off"] .pill { color: var(--text); }

/* Icona tonda colorata */
.dot-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 20px;
}
.dot-icon.sm, .tile-label .dot-icon { width: 28px; height: 28px; font-size: 14px; }

/* Sezioni */
.section-tile {
  color: var(--text);
  text-decoration: none;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), box-shadow .25s;
}
.section-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.section-tile:active { transform: scale(.98); }
.section-name { margin-top: auto; font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.section-sub { display: inline-flex; align-items: center; gap: 5px; align-self: flex-start; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.section-sub.due-ok, .section-sub.due-warn, .section-sub.due-bad { padding: 2px 10px; border-radius: 999px; }
.section-sub:empty { display: none; }
.section-sub .icon { font-size: 12px; }
.section-go {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  transition: transform .25s, color .25s;
}
.section-tile:hover .section-sub { display: inline-flex; align-items: center; gap: 5px; align-self: flex-start; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.section-sub.due-ok, .section-sub.due-warn, .section-sub.due-bad { padding: 2px 10px; border-radius: 999px; }
.section-sub:empty { display: none; }
.section-sub .icon { font-size: 12px; }
.section-go { transform: translateX(3px); color: var(--text); }

/* Note */
.tile.notes-tile { grid-column: 1 / -1; }
.notes-tile textarea {
  flex: 1;
  width: 100%;
  min-height: 110px;
  margin-top: 12px;
  padding: 0;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.notes-tile textarea::placeholder { color: var(--text-3); }

/* ---------- Popup ---------- */
.modal {
  width: min(1000px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
.modal[open] { display: flex; flex-direction: column; gap: 16px; animation: pop .3s cubic-bezier(.2, .8, .2, 1); }
.modal::backdrop { background: rgba(0, 0, 0, .35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.modal-head h2 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.modal-head .sub { font-size: 14px; }
.segmented.scroll { align-self: flex-start; max-width: 100%; overflow-x: auto; }
.segmented.scroll button { white-space: nowrap; }
.windy {
  height: min(640px, 70vh);
  border-radius: 18px;
  overflow: hidden;
  background: var(--surface-2);
}
.windy iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- Impostazioni: liste raggruppate stile iOS ---------- */
.group-title {
  margin: 28px 16px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
}
.group {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 10px 16px;
  flex-wrap: wrap;
}
.row + .row { border-top: 1px solid var(--border); }
.row-label { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.row-value { color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.row-value.ok { color: var(--ok); font-weight: 600; }
.row-value.bad { color: var(--bad); font-weight: 600; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
}
.segmented button {
  border: 0;
  padding: 6px 14px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
}
.segmented button[aria-checked="true"] {
  background: var(--surface-solid);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

/* Collegamento account Bosch */
.link-box { padding: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px; }
.link-reason { margin: 0; font-weight: 600; }
.steps { margin: 0; padding-left: 20px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; line-height: 1.45; }
.steps b { color: var(--text); font-weight: 600; }
.steps code, .steps kbd {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: 500 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.steps-alt { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.45; }
.steps-alt b { color: var(--text); font-weight: 600; }
.steps-alt code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--text); font: 500 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.link-actions { display: flex; gap: 10px; }
.link-box .field input { font-size: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.button.sm { padding: 7px 14px; font-size: 14px; }
.button.armed { background: var(--bad); color: #fff; }

/* Test di velocità */
.speed { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); }
.speed-item { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: 14px; background: var(--surface-2); }
.speed-item span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.speed-item b { font-size: 26px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.speed-item small { font-size: 12px; color: var(--text-2); }
.row-note { color: var(--text-2); font-size: 14px; flex: 1; }
.speed + .row { border-top: 1px solid var(--border); }

/* Sezioni a tendina */
.drop summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  min-height: 60px;
}
.drop summary::-webkit-details-marker { display: none; }
.drop summary .row-label { font-weight: 600; }
.drop summary::after {
  content: '';
  width: 8px;
  height: 8px;
  margin: 0 4px 3px 0;
  border-right: 2px solid var(--text-3);
  border-bottom: 2px solid var(--text-3);
  transform: rotate(45deg);
  transition: transform .25s;
}
.drop summary .row-value { margin-left: auto; }
.drop[open] summary::after { transform: rotate(-135deg); margin-bottom: -3px; }
.drop summary:hover { background: var(--surface-2); }
.drop-body { border-top: 1px solid var(--border); animation: open .25s ease; }
@keyframes open { from { opacity: 0; transform: translateY(-4px); } }

.meter-row { padding: 14px 16px; }
.meter-row, .row + .meter-row { border-top: 1px solid var(--border); }
.meter-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 500;
}
.meter-head span:last-child { color: var(--text-2); font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--ok);
  transition: width .8s cubic-bezier(.2, .8, .2, 1), background .3s;
}
.meter i.warn { background: var(--warn); }
.meter i.hot { background: var(--bad); }

/* Pagina ancora vuota */
.placeholder { align-items: center; justify-content: center; text-align: center; min-height: 260px; gap: 12px; }
.placeholder .dot-icon { width: 64px; height: 64px; font-size: 28px; }
.placeholder h2 { margin: 0; font-size: 20px; }
.placeholder p { margin: 0; color: var(--text-2); }

/* ---------- Pulsanti ---------- */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  font: inherit;
  transition: transform .15s, filter .2s;
}
.button:hover { filter: brightness(1.08); }
.button:active { transform: scale(.97); }
.button:disabled { opacity: .5; cursor: default; }
.button.ghost { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 34px; height: 34px; font-size: 14px; }
.icon-btn.sm:hover { transform: none; background: var(--border); }
.icon-btn.danger { color: var(--bad); }
.icon-btn.armed { width: auto; padding: 0 12px; border-radius: 999px; background: var(--bad); color: #fff; font: inherit; font-size: 13px; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Raccolta olive ---------- */
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.toolbar .sub { font-size: 15px; margin: 0; }
.select { position: relative; display: inline-block; }
.select select {
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 40px 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.select::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -6px;
  border-right: 2px solid var(--text-2);
  border-bottom: 2px solid var(--text-2);
  transform: rotate(45deg);
  pointer-events: none;
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 13px; color: var(--text-2); min-height: 1.2em; }

.charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.chart-card { min-height: 0; min-width: 0; animation: none; }
.chart-card.full { grid-column: 1 / -1; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.chart-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.chart-head span { font-size: 13px; color: var(--text-2); }
.chart-empty { margin: 0; padding: 4px; color: var(--text-2); }

.chart { position: relative; width: 100%; min-width: 0; overflow: visible; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--text-3); stroke-width: 1; }
.chart .tick { fill: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .value { fill: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .bar.muted { fill: var(--series-muted); }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface-solid); stroke-width: 2; }
.chart .cross { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: default; }
.chart-tip {
  position: absolute;
  z-index: 2;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-hover);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.chart-tip b { display: block; font-size: 12px; color: var(--text-2); font-weight: 600; }

.section-title { margin: 36px 4px 12px; font-size: 22px; letter-spacing: -0.02em; }
.register-year { cursor: pointer; transition: box-shadow .25s, transform .25s; }
.register-year:hover { box-shadow: var(--shadow-hover); }
.register-head {
  width: 100%;
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.register-head .row-label { font-weight: 700; }
.register-head .row-value { display: inline-flex; align-items: center; gap: 8px; }
.register-head .row-value .icon { color: var(--text-3); }
.register-head:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

/* Riepilogo (popup e stampa condividono le classi rp-*) */
.detail-modal { width: min(760px, calc(100% - 32px)); }
.detail-body { overflow-y: auto; outline: none; }
.rp-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.rp-kpi { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: 14px; background: var(--surface-2); min-width: 0; }
.rp-kpi span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.rp-kpi b { font-size: 22px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.rp-kpi small { font-size: 12px; color: var(--text-2); min-height: 1.2em; }
.rp-title { margin: 22px 0 8px; font-size: 15px; }
.rp-table-wrap { overflow-x: auto; }
.rp-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.rp-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rp-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rp-table .num { text-align: right; }
.rp-table tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--text-3); }
.rp-current td { font-weight: 700; }
.rp-delta { margin-left: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.rp-note { margin: 8px 0 0; font-size: 12px; color: var(--text-2); }
.rp-foot { margin-top: 18px; }
.report { display: none; }
.row.entry { flex-wrap: nowrap; }
.entry-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.entry-title { font-weight: 500; }
.entry-data { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.entry-actions { display: flex; gap: 6px; }

/* ---------- Veicoli ---------- */
.vehicles { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.vehicle {
  min-height: 0;
  gap: 4px;
  align-items: stretch;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), box-shadow .25s;
}
.vehicle:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.vehicle:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.vehicle-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.vehicle-name { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.vehicle-sub { color: var(--text-2); font-size: 14px; }
.vehicle-dues { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.vehicle-due { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }
.vehicle-due > span:first-child { color: var(--text-2); font-weight: 500; }

/* Targa in stile europeo */
.plate {
  display: inline-flex;
  align-items: stretch;
  height: 28px;
  border: 1.5px solid #1c1c1e;
  border-radius: 5px;
  background: #fff;
  color: #111;
  overflow: hidden;
  vertical-align: middle;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.plate i { display: grid; place-items: center; width: 18px; background: #003399; color: #fff; font: 700 11px/1 system-ui, sans-serif; font-style: normal; }
.plate b { display: grid; place-items: center; padding: 0 8px; font: 700 15px/1 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; letter-spacing: .06em; }
.card-head .sub .plate { margin-left: 6px; transform: scale(.9); transform-origin: left center; }

/* Stato delle scadenze: colore + icona + testo */
.due {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.due .icon { font-size: 12px; }
.due-ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: color-mix(in srgb, var(--ok) 70%, var(--text)); }
.due-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: color-mix(in srgb, var(--warn) 65%, var(--text)); }
.due-bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.due-none { background: var(--surface-2); color: var(--text-2); font-weight: 500; }

.due-list { margin-bottom: 20px; }
.due-row { width: 100%; border: 0; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.due-row:hover { background: var(--surface-2); }
.due-row + .due-row, .register-head + div .due-row:first-child { border-top: 1px solid var(--border); }

.card-head { display: flex; align-items: center; gap: 14px; }
.group.flat { box-shadow: none; margin-bottom: 0; }
.card-notes { margin: 0; white-space: pre-wrap; color: var(--text-2); }
.rp-table td.wrap { white-space: normal; min-width: 140px; color: var(--text-2); }
.form-actions.spread { justify-content: space-between; flex-wrap: wrap; }
.button.danger-text { color: var(--bad); }

/* Popup modulo */
.form-modal { width: min(560px, calc(100% - 32px)); }
.form-modal.wide { width: min(720px, calc(100% - 32px)); }
.form-scroll { overflow-y: auto; max-height: min(62vh, 640px); margin: 0 -4px; padding: 0 4px; }
.form-section { margin: 18px 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.form-section:first-child { margin-top: 0; }
.field.full { grid-column: 1 / -1; }
.field textarea, .field .select select { width: 100%; }
.field textarea {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  resize: vertical;
  outline: none;
}
.field textarea:focus { border-color: var(--accent); }
.select.block { display: block; }
.field .select select { box-shadow: none; background: var(--surface-2); font-weight: 500; padding: 12px 40px 12px 14px; font-size: 16px; }
.form-modal form { display: flex; flex-direction: column; gap: 18px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.field:first-child { grid-column: 1 / -1; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); }
.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 42px; }
.input-unit i { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--text-2); font-weight: 600; pointer-events: none; }
.field.note { grid-column: 1 / -1; font-weight: 500; font-size: 13px; }
.form-error { margin: 0; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-weight: 500; }
.page-error { margin-bottom: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 404 ---------- */
.center { display: grid; place-items: center; min-height: 60vh; }
.tile.empty { align-items: center; text-align: center; padding: 40px 48px; }
.tile.empty h1 { margin: 0; font-size: 64px; letter-spacing: -0.04em; }
.tile.empty .button { margin-top: 20px; }

/* ---------- Stampa / PDF: solo il riepilogo, A4, sempre chiaro ---------- */
@page { size: A4; margin: 16mm 14mm; }
@media print {
  :root, :root[data-theme="dark"] {
    color-scheme: light;
    --text: #111; --text-2: #555; --text-3: #999; --border: #ddd; --surface-2: #f3f4f1;
  }
  body { background: #fff !important; color: #111; font-size: 11pt; }
  body > *:not(.report) { display: none !important; }
  .report { display: block !important; }
  .rp-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding-bottom: 12pt;
    margin-bottom: 16pt;
    border-bottom: 2pt solid #2f6b2f;
  }
  .rp-kicker { margin: 0 0 2pt; font-size: 9pt; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #2f6b2f; }
  .rp-head h1 { margin: 0; font-size: 26pt; letter-spacing: -0.02em; }
  .rp-meta { font-size: 8.5pt; color: #555; text-align: right; line-height: 1.5; }
  .rp-kpis { gap: 8pt; }
  .rp-kpi { border: 1px solid #ddd; background: #f7f8f5; border-radius: 8pt; padding: 10pt; }
  .rp-kpi b { font-size: 15pt; }
  .rp-title { margin: 18pt 0 6pt; font-size: 11pt; text-transform: uppercase; letter-spacing: .08em; color: #2f6b2f; }
  .rp-table { font-size: 9.5pt; }
  .rp-table thead th { background: #f3f4f1; border-bottom: 1pt solid #bbb; }
  .rp-table tr { break-inside: avoid; }
  .rp-table tbody tr:nth-child(even) td { background: #fafaf8; }
  .rp-foot { margin-top: 20pt; padding-top: 8pt; border-top: 1px solid #ddd; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  nav a span { display: none; }
  nav a { padding: 10px; }
  .brand { font-size: 0; gap: 0; }
  .tiles { gap: 12px; }
  .tile { min-height: 148px; padding: 16px; }
  .page { padding-top: 28px; }
  .stats { gap: 12px; }
  .stat-value { font-size: 24px; }
  .fields { grid-template-columns: 1fr; }
  .rp-kpis { grid-template-columns: 1fr 1fr; }
  .vehicles { grid-template-columns: 1fr; }
  .due { white-space: normal; }
}
