/* Scadenze – stile. Blu petrolio e turchese, schede arrotondate, icone lineari. */
:root {
  --petrol: #0E4F5C;
  --accent: #14B8A6;
  --accent-text: #0F766E;
  --on-accent: #06343B;
  --bg: #F3F8F8;
  --card: #FFFFFF;
  --ink: #0F2A30;
  --muted: #4A6670;
  --line: #E3EEEE;
  --danger: #B4400F;
  --danger-bg: #FDEEE6;
  --danger-line: #F3C9B3;
  --shadow: 0 2px 10px rgba(14, 79, 92, .08);
  --mint: color-mix(in srgb, var(--accent) 16%, var(--card));
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0B1B1F;
  --card: #12272D;
  --ink: #E8F3F4;
  --muted: #9DB5BA;
  --line: #1F3A40;
  --danger: #FDBA74;
  --danger-bg: #33211A;
  --danger-line: #5A3A2A;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}
body {
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
  line-height: 1.35;
}
body.lock { overflow: hidden; }
input, select, textarea { -webkit-user-select: text; user-select: text; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; text-decoration: none; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }
small { font-size: 13px; }

#app {
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}
@media (min-width: 760px) {
  body { background: color-mix(in srgb, var(--bg) 70%, #000 8%); }
  #app { box-shadow: 0 0 40px rgba(0, 0, 0, .10); }
}
#view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: calc(16px + var(--safe-t)) 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
#view > * { flex: none; }

/* ---------- Intestazioni ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top .when { font-size: 14px; font-weight: 500; color: var(--muted); }
.top h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.page-head { display: flex; align-items: center; gap: 10px; }
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; flex: none;
  background: var(--card); color: var(--petrol); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center; position: relative;
}
:root[data-theme="dark"] .icon-btn { color: var(--accent); }
.icon-btn.accent { background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 40%, transparent); }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
:root[data-theme="dark"] .badge { color: #2A160B; }
.sec-head { display: flex; align-items: center; justify-content: space-between; }
.sec-head h2, .sec h2 { font-size: 18px; font-weight: 800; }
.sec { display: flex; flex-direction: column; gap: 12px; }
.link-btn { border: 0; background: none; color: var(--accent-text); font-weight: 700; font-size: 14px; min-height: 44px; padding: 0 2px; }

/* ---------- Riepilogo ---------- */
.hero {
  background: var(--petrol); color: #fff; border-radius: 24px; padding: 20px;
  box-shadow: 0 8px 24px rgba(14, 79, 92, .22); display: flex; flex-direction: column; gap: 18px;
}
.hero .eyebrow { font-size: 13px; font-weight: 700; color: #9FE3DA; letter-spacing: .04em; text-transform: uppercase; }
.hero .big { font-size: 22px; font-weight: 700; line-height: 1.25; margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: rgba(255, 255, 255, .10); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 26px; font-weight: 800; }
.stat span { font-size: 12px; font-weight: 600; color: #D4EEEB; }
.stat.warn { background: #fff; }
.stat.warn b { color: #B4400F; }
.stat.warn span { color: #0F2A30; font-weight: 700; }

/* ---------- Schede ---------- */
.card {
  background: var(--card); border-radius: 20px; padding: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px; width: 100%; border: 0; text-align: left; color: inherit;
}
button.card, a.card { cursor: pointer; }
.card.alert { background: var(--danger-bg); box-shadow: none; border: 1px solid var(--danger-line); }
.card.alert .tile { background: var(--card); color: var(--danger); }
.card.alert small { color: var(--danger); font-weight: 600; }
.card.static { cursor: default; }
.tile {
  width: 44px; height: 44px; border-radius: 14px; flex: none; background: var(--mint); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
}
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.grow b { font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.grow small, small.muted { color: var(--muted); font-weight: 500; }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.right b { font-size: 15px; font-weight: 800; }
.pill { font-size: 12px; font-weight: 700; color: var(--accent-text); background: var(--mint); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.pill.bad { color: var(--danger); background: var(--danger-bg); }
.pill.ok { color: var(--muted); background: var(--line); }
.chev { color: var(--muted); flex: none; }
.list { display: flex; flex-direction: column; gap: 10px; }
.group { background: var(--card); border-radius: 20px; padding: 4px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.group > .line { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.group > .line:last-child { border-bottom: 0; }
.group > button.line, .group > a.line { background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; color: inherit; }

.date-block { width: 52px; border-radius: 14px; background: var(--petrol); color: #fff; display: flex; flex-direction: column; align-items: center; padding: 8px 0; flex: none; }
.date-block span { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: #9FE3DA; }
.date-block b { font-size: 20px; font-weight: 800; line-height: 1.1; }
.date-block.off { background: var(--line); color: var(--muted); }
.date-block.off span { color: var(--muted); }
.meta { display: flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }

.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.qa {
  background: var(--card); border-radius: 20px; padding: 14px 4px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--accent-text); border: 0;
  font-size: 12px; font-weight: 700;
}
.qa span { color: var(--ink); }
@media (min-width: 560px) { .grid4 .qa { padding: 18px 4px 16px; } }

.empty { background: var(--card); border-radius: 24px; padding: 28px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.empty .tile { width: 56px; height: 56px; border-radius: 18px; }
.empty b { font-size: 17px; font-weight: 800; }
.empty p { color: var(--muted); font-size: 14px; font-weight: 500; }
.note { background: var(--mint); color: var(--ink); border-radius: 16px; padding: 12px 14px; font-size: 13px; font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.note svg { flex: none; color: var(--accent-text); margin-top: 1px; }

/* ---------- Chip e controlli ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; margin: 0 -20px; padding-left: 20px; padding-right: 20px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 14px; font-weight: 700; white-space: nowrap;
}
.chip.on { background: var(--petrol); border-color: var(--petrol); color: #fff; }
.chip.add { color: var(--accent-text); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--line); border-radius: 14px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; min-height: 40px; border-radius: 11px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 16px; border: 0; font-weight: 800; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--mint); color: var(--accent-text);
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.dark { background: var(--petrol); color: #fff; }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.ghost { background: var(--line); color: var(--ink); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.switch { width: 52px; height: 32px; border-radius: 16px; border: 0; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 2px var(--line); position: relative; }
.swatch.on { box-shadow: 0 0 0 3px var(--ink); }

/* ---------- Ricerca ---------- */
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 44px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; font-weight: 600; color: var(--muted); }
.crumbs a { color: var(--accent-text); min-height: 28px; display: inline-flex; align-items: center; }

/* ---------- Calendario ---------- */
.cal { background: var(--card); border-radius: 24px; padding: 14px 10px 10px; box-shadow: var(--shadow); }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px; }
.cal-head b { font-size: 17px; font-weight: 800; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 800; color: var(--muted); padding: 6px 0; letter-spacing: .04em; }
.cal-day { aspect-ratio: 1 / 1.05; border: 0; background: none; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 15px; font-weight: 600; min-height: 44px; }
.cal-day.out { color: var(--muted); opacity: .45; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day.sel { background: var(--petrol); color: #fff; }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.d { background: var(--petrol); }
.dot.a { background: var(--accent); }
.dot.o { background: var(--danger); }
.cal-day.sel .dot.d { background: #fff; }
:root[data-theme="dark"] .dot.d { background: #9FE3DA; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 6px 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Navigazione ---------- */
#nav {
  background: var(--card); border-radius: 28px 28px 0 0; box-shadow: 0 -4px 20px rgba(14, 79, 92, .10);
  padding: 10px 12px calc(10px + var(--safe-b)); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; flex: none;
}
.nav-item { border: 0; background: none; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
.nav-item.on { color: var(--accent-text); font-weight: 800; }
.nav-item svg { stroke-width: 1.8; }
.nav-item.on svg { stroke-width: 2; }
.fab-wrap { display: flex; justify-content: center; }
.fab {
  width: 56px; height: 56px; border-radius: 20px; border: 0; background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent); display: flex; align-items: center; justify-content: center; margin-top: -22px;
}

/* ---------- Schede a comparsa ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
.sheet-wrap.open { pointer-events: auto; }
.sheet-back { position: absolute; inset: 0; background: rgba(8, 24, 28, .5); opacity: 0; transition: opacity .2s; }
.sheet-wrap.open .sheet-back { opacity: 1; }
.sheet {
  position: relative; width: 100%; max-width: 720px; max-height: 92vh; max-height: 92dvh; background: var(--bg);
  border-radius: 28px 28px 0 0; transform: translateY(100%); transition: transform .22s ease; display: flex; flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .25);
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 20px 6px; flex: none; }
.sheet-head h2 { font-size: 20px; font-weight: 800; overflow-wrap: anywhere; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 20px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; }
.sheet-body > * { flex: none; }
.p { font-size: 15px; font-weight: 500; line-height: 1.5; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); font-weight: 500; flex: none; }
.kv b { font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.detail { background: var(--card); border-radius: 20px; padding: 4px 16px; box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; gap: 14px; background: var(--card); border: 0; border-radius: 18px; padding: 12px 14px; width: 100%; text-align: left; font-weight: 700; font-size: 15px; box-shadow: var(--shadow); min-height: 56px; }
.menu-item .tile { width: 40px; height: 40px; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .tile { background: var(--danger-bg); color: var(--danger); }

/* ---------- Moduli ---------- */
form { display: flex; flex-direction: column; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.fld small { color: var(--muted); }
.fld input, .fld select, .fld textarea, .search input {
  width: 100%; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  padding: 10px 14px; font-size: 16px; color: var(--ink); -webkit-appearance: none; appearance: none; outline: none;
}
.search input { border-radius: 16px; box-shadow: var(--shadow); border-color: transparent; }
.fld select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 14px) 21px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.fld textarea { min-height: 88px; resize: vertical; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.fld input[type="file"] { padding: 10px; font-size: 14px; }
.fld input[type="date"], .fld input[type="time"] { min-height: 48px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 600; min-height: 44px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.setting { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .grow small { white-space: normal; }

/* ---------- Avvisi ---------- */
#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); background: #0F2A30; color: #fff; padding: 12px 18px; border-radius: 16px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 80; max-width: calc(100vw - 40px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
:root[data-theme="dark"] #toast { background: #E8F3F4; color: #0B1B1F; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-back, #toast, .switch, .switch::after { transition: none; }
}
