/* Layout: tab bar in basso su telefono, barra laterale su Mac; schede a foglio che salgono dal basso.
   Il numero guida è scritto come un timecode (monospazio), perché il lavoro si misura in ore e minuti. */
:root {
  --bg: #F3F3F8;
  --surface: #FFFFFF;
  --surface2: #ECECF4;
  --line: #DCDCE8;
  --fg: #15151F;
  --muted: #666679;
  --accent: #5636F2;
  --accent-ink: #FFFFFF;
  --accent-soft: #E8E3FF;
  --blue: #3E63DD;
  --yellow: #A67C00;
  --red: #D1292F;
  --green: #1B8F5A;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 8px 24px rgba(20, 20, 40, .06);
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D0D14; --surface: #16161F; --surface2: #1F1F2B; --line: #2B2B3A;
    --fg: #F0F0F8; --muted: #9B9BB0; --accent: #A090FF; --accent-ink: #120C33; --accent-soft: #2A2360;
    --blue: #7F9BFF; --yellow: #F2C94C; --red: #FF7A80; --green: #4BD58F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D0D14; --surface: #16161F; --surface2: #1F1F2B; --line: #2B2B3A;
  --fg: #F0F0F8; --muted: #9B9BB0; --accent: #A090FF; --accent-ink: #120C33; --accent-soft: #2A2360;
  --blue: #7F9BFF; --yellow: #F2C94C; --red: #FF7A80; --green: #4BD58F;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; text-align: inherit; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- struttura ---------- */
.app { max-width: 720px; margin: 0 auto; padding-block: 16px 112px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding-top: 8px; }
.page-head h1 { font-size: 28px; line-height: 1.1; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; gap: 4px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px max(10px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
}
.nav .brand { display: none; }
.nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px; color: var(--muted); font-size: 11px; font-weight: 600; min-width: 0;
}
.nav button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button[aria-current="page"] { color: var(--accent); }
.nav button[aria-current="page"] svg { stroke-width: 2.2; }

.fab {
  position: fixed; z-index: 19; right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: var(--shadow), 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}
.fab svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; }

@media (min-width: 900px) {
  body { padding-left: 264px; padding-right: 24px; }
  .app { max-width: 880px; padding-block: 32px 64px; }
  .nav {
    top: 0; right: auto; bottom: 0; width: 240px; flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); padding: 28px 14px;
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 18px; padding: 0 10px 20px; }
  .nav .brand svg { width: 30px; height: 30px; }
  .nav button { flex: 0 0 auto; flex-direction: row; gap: 12px; font-size: 15px; padding: 11px 12px; }
  .nav button[aria-current="page"] { background: var(--accent-soft); }
  .fab { bottom: 28px; right: 32px; }
}

/* ---------- componenti ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-t { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 12px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 14px; font-weight: 700; background: var(--surface2); min-height: 46px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.wide { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.chip.acc { background: var(--accent-soft); color: var(--accent); }
.chip.blue { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.chip.yellow { background: color-mix(in srgb, var(--yellow) 18%, transparent); color: var(--yellow); }
.chip.red { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.chip.green { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--accent-soft); color: var(--fg); border-radius: 16px; padding: 12px 14px; font-size: 13.5px; }
.banner b { color: var(--accent); }

/* anno */
.yearsel { display: inline-flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.yearsel button { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; color: var(--muted); }
.yearsel b { font-family: var(--font-mono); padding: 0 8px; font-size: 15px; }

/* hero riepilogo */
.hero { padding: 20px; }
.hero .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hero .big { font-family: var(--font-mono); font-weight: 600; font-size: clamp(34px, 9vw, 48px); line-height: 1.1; letter-spacing: -.03em; margin: 6px 0 14px; font-variant-numeric: tabular-nums; }
.hero .big small { font-size: .5em; color: var(--muted); letter-spacing: 0; }
.split { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; background: var(--surface2); }
.split i { display: block; min-width: 3px; }
.legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.legend div { min-width: 0; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend span i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend b { display: block; font-family: var(--font-mono); font-size: 15px; font-weight: 600; margin-top: 2px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; min-width: 0; }
.stat .t { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .v { font-family: var(--font-mono); font-weight: 600; font-size: 19px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.stato-blue .t { color: var(--blue); } .stat.stato-yellow .t { color: var(--yellow); }
.stat.stato-red .t { color: var(--red); } .stat.stato-green .t { color: var(--green); }
@media (min-width: 560px) { .stat-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.rows { display: flex; flex-direction: column; }
.rows .r { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.rows .r:first-child { border-top: 0; }
.rows .r span:first-child { color: var(--muted); min-width: 0; }
.rows .r b { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .r.strong span:first-child { color: var(--fg); font-weight: 700; }
.rows .r.strong b { font-size: 17px; }
.rows .r.neg b { color: var(--muted); }
.rows .r s { color: var(--muted); font-family: var(--font-mono); margin-right: 8px; }

.meter { height: 10px; border-radius: 5px; background: var(--surface2); overflow: hidden; margin: 8px 0 4px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font-mono); fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--accent); opacity: .5; }
.chart .bar.cur { opacity: 1; }
.chart .val { fill: var(--fg); font-size: 10.5px; }

/* giornate */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.fchip { flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 13.5px; }
.fchip[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.fchip i { width: 9px; height: 9px; border-radius: 50%; background: var(--pc, var(--muted)); }
.month-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 8px 4px 0; }
.month-h h2 { font-size: 17px; }
.month-h span { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); }
.daylist { display: flex; flex-direction: column; gap: 8px; }
.day { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px 12px 18px; overflow: hidden; }
.day::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--pc, var(--line)); }
.day .dd { text-align: center; line-height: 1.05; }
.day .dd b { display: block; font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.day .dd i { font-style: normal; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.day.fest .dd i { color: var(--red); }
.day .dm { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.day .dp { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .tc { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.day .tc em { font-style: normal; color: var(--fg); }
.day .da { font-family: var(--font-mono); font-weight: 600; font-size: 16px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.day.nc { opacity: .6; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty h3 { color: var(--fg); margin-bottom: 6px; font-size: 18px; }

/* progetti */
.proj { position: relative; width: 100%; display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 14px 16px 14px 20px; overflow: hidden; box-shadow: var(--shadow); }
.proj::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; background: var(--pc); }
.proj .ph { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.proj h3 { font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.proj .who { color: var(--muted); font-size: 13px; }
.proj .nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.proj .nums div span { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.proj .nums div b { font-family: var(--font-mono); font-weight: 600; font-size: 14.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* impostazioni */
.set-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; }
.set-row label { min-width: 0; }
.set-row small { display: block; color: var(--muted); font-size: 12px; }
.set-row .in { width: 112px; flex: none; text-align: right; font-family: var(--font-mono); }
.hint { font-size: 12.5px; color: var(--muted); }

/* ---------- campi ---------- */
.in, select.in, textarea.in {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface2); font-size: 16px; /* 16px evita lo zoom di Safari su iPhone */
}
textarea.in { min-height: 76px; resize: vertical; }
.in:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type="time"].in, input[type="date"].in { font-family: var(--font-mono); }
.fl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fl > span { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.g2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.g3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.seg { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px; font-size: 13.5px; font-weight: 700; color: var(--muted); min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; min-height: 46px; }
.switch .tg { width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch .tg::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch[aria-checked="true"] .tg { background: var(--accent); }
.switch[aria-checked="true"] .tg::after { transform: translateX(20px); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 46px; height: 46px; border-radius: 12px; background: var(--surface2); font-size: 22px; font-weight: 700; display: grid; place-items: center; text-align: center; }
.stepper output { flex: 1; text-align: center; font-family: var(--font-mono); font-size: 18px; font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches button { width: 38px; height: 38px; border-radius: 50%; background: var(--c); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--fg); }
.err { color: var(--red); font-size: 13px; font-weight: 600; }

/* ---------- scheda (foglio) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bd { position: absolute; inset: 0; background: rgba(8, 8, 20, .5); }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 94dvh; max-height: 94svh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 26px 26px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .3);
}
.sheet.anim { animation: up .24s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet.anim { animation: none; } .switch .tg, .switch .tg::after { transition: none; } }
.sheet-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px max(18px, env(safe-area-inset-left, 0px)) 8px max(18px, env(safe-area-inset-left, 0px)); }
.sheet-h h2 { font-size: 20px; }
.x { width: 38px; height: 38px; border-radius: 50%; background: var(--surface2); display: grid; place-items: center; text-align: center; font-size: 18px; flex: none; }
.sheet-b { overflow-y: auto; overscroll-behavior: contain; padding: 8px max(18px, env(safe-area-inset-left, 0px)) 20px; display: flex; flex-direction: column; gap: 14px; }
.sheet-f {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 12px max(18px, env(safe-area-inset-left, 0px)) calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 10px;
}
.sheet-f .btns { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.pv-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.pv-top .l { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pv-top .b { font-family: var(--font-mono); font-weight: 600; font-size: 28px; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pv-top .n { text-align: right; font-family: var(--font-mono); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pv-top .n b { color: var(--fg); font-size: 15px; display: block; }
.warn { background: color-mix(in srgb, var(--yellow) 16%, transparent); color: var(--fg); border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 600; }
.warn::before { content: "⚠ "; }
.note { color: var(--muted); font-size: 12.5px; }
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.sec > h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-family: var(--font-body); font-weight: 700; }
.datechip { font-size: 13px; font-weight: 600; }

.toast { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
textarea.mono-ta { font-family: var(--font-mono); font-size: 12px; min-height: 90px; }
