:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --text: #121211;
  --text-2: #52514e;
  --muted: #7a7974;
  --border: #e2e1dc;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fb;
  --good: #0b7a3e;
  --good-soft: #e3f4ea;
  --warn: #a35f00;
  --warn-soft: #fdf1dc;
  --bad: #c0392b;
  --bad-soft: #fbe7e5;
  --series-1: #2a78d6;
  --grid: #e8e7e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --border: #2e2e2b;
    --accent: #3987e5;
    --accent-soft: #1b2c42;
    --good: #4cc983;
    --good-soft: #15301f;
    --warn: #f0a83a;
    --warn-soft: #33260f;
    --bad: #f07a6e;
    --bad-soft: #3a1b18;
    --series-1: #3987e5;
    --grid: #2a2a28;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --text: #f0efec; --text-2: #c3c2b7;
  --muted: #8f8e88; --border: #2e2e2b; --accent: #3987e5; --accent-soft: #1b2c42; --good: #4cc983;
  --good-soft: #15301f; --warn: #f0a83a; --warn-soft: #33260f; --bad: #f07a6e; --bad-soft: #3a1b18;
  --series-1: #3987e5; --grid: #2a2a28;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }

header.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 12px;
}
header.top h1 { flex: 1; }
main { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.stack > * + * { margin-top: 12px; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.72rem; color: var(--muted); text-decoration: none; padding: 4px 0;
}
nav.tabs a svg { width: 24px; height: 24px; }
nav.tabs a.on { color: var(--accent); font-weight: 600; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; border: 1px solid var(--border);
}
.card.flat { box-shadow: none; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
a.item { display: block; color: inherit; text-decoration: none; }

.hero { display: flex; align-items: baseline; gap: 8px; }
.hero .big { font-size: 3rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stats b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: 0.78rem; color: var(--muted); }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; cursor: pointer;
  padding: 12px 16px; background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; min-height: 44px;
}
button:disabled { opacity: 0.45; cursor: default; }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--text); }
button.danger { background: var(--bad-soft); color: var(--bad); }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; min-height: 36px; }
button.small { padding: 6px 12px; min-height: 34px; font-size: 0.875rem; border-radius: 10px; }
button.block, .btn.block { width: 100%; }
button.icon { background: transparent; color: var(--text-2); padding: 6px; min-height: 36px; min-width: 36px; }

label { display: block; font-size: 0.875rem; color: var(--text-2); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border-radius: 12px; padding: 8px 12px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text); font-weight: 500; text-align: center; min-width: 58px;
}
.chip small { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 400; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on small { color: inherit; opacity: 0.85; }

.slot { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.slot:last-child { border-bottom: 0; }
.slot .time { font-size: 1.15rem; font-weight: 700; width: 58px; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.notice { border-radius: 12px; padding: 12px 14px; background: var(--accent-soft); color: var(--text); font-size: 0.9rem; }
.notice.warn { background: var(--warn-soft); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

dialog {
  border: 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text); max-height: 92vh;
}
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog form { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
dialog .head { display: flex; align-items: center; margin-bottom: 14px; }
dialog .head h2 { flex: 1; }
.form-error { margin: 4px 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--bad); color: #fff; font-weight: 500; }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.actions > * { flex: 1; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 50;
  margin: 0 auto; max-width: 480px; padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 500; text-align: center;
  opacity: 0; transform: translateY(8px); transition: 0.2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--bad); color: #fff; }

.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) 16px 32px; }
.auth .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; margin-bottom: 16px; }

/* grafici */
.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.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); stroke-width: 2; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: 0.35; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 6px 9px; border-radius: 8px; font-size: 0.8rem; white-space: nowrap; transform: translate(-50%, -100%);
  margin-top: -8px; font-variant-numeric: tabular-nums;
}
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
details summary { cursor: pointer; color: var(--accent); font-size: 0.875rem; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
td.r, th.r { text-align: right; }
