:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --soft: #eeece7;
  --text: #1d1d1b;
  --muted: #6f6e69;
  --faint: #a7a6a0;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #2f6fde;
  --accent-bg: #e8effc;
  --ok: #3d8a37;
  --danger: #c0392b;
  --danger-bg: #fbeaea;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --card: #1f1f1d;
    --soft: #2a2a27;
    --text: #f1f0ec;
    --muted: #a3a29c;
    --faint: #6f6e69;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #7ba8f6;
    --accent-bg: #1e2a42;
    --ok: #7dc46f;
    --danger: #ef7b6e;
    --danger-bg: #3a1f1c;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle { fill: currentColor; stroke: none; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 18px calc(env(safe-area-inset-bottom) + 110px);
}

/* Intestazione */
.top { display: flex; justify-content: space-between; align-items: flex-start; }
.weekday { margin: 0; font-size: 14px; color: var(--muted); }
.date { margin: 2px 0 0; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.top-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--muted);
}
.icon-btn:hover { background: var(--soft); }
.icon-btn.small { width: 32px; height: 32px; flex: none; }

.pill {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--soft);
  font-size: 14px;
  font-weight: 500;
}

/* Striscia settimana */
.week { display: flex; align-items: center; gap: 2px; margin: 18px -6px 16px; }
.days { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0 7px;
  border-radius: 12px;
  color: var(--muted);
  position: relative;
}
.day .dl { font-size: 12px; }
.day .dn { font-size: 16px; font-weight: 500; color: var(--text); }
.day.today .dn { color: var(--accent); }
.day.selected { background: var(--text); color: var(--bg); }
.day.selected .dn { color: var(--bg); }
.day .dot { width: 4px; height: 4px; border-radius: 50%; background: transparent; }
.day.full .dot { background: var(--ok); }
.day.selected.full .dot { background: var(--bg); }

/* Avanzamento */
.progress-card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pct { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.summary { font-size: 13px; color: var(--muted); text-align: right; }
.bar { height: 6px; border-radius: 3px; background: var(--soft); margin-top: 10px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--ok); border-radius: 3px; transition: width 0.35s ease; }

.reorder-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px; padding: 8px 8px 8px 14px;
  background: var(--accent-bg); color: var(--accent);
  border-radius: 12px; font-size: 14px;
}
.reorder-bar[hidden] { display: none; }

/* Lista */
.list { margin-top: 14px; }
.group-label { margin: 18px 4px 6px; font-size: 13px; color: var(--muted); }

.item {
  display: flex; align-items: center;
  border-radius: 12px;
  transition: background 0.2s ease;
}
.item + .item { margin-top: 2px; }

.toggle {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px 12px 8px;
  text-align: left;
  border-radius: 12px;
}
.check {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--faint);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.check svg { width: 14px; height: 14px; stroke-width: 3; opacity: 0; color: #fff; }
.time { flex: none; width: 50px; display: flex; flex-direction: column; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); line-height: 1.25; }
.time .end { font-size: 12px; color: var(--faint); }
.name { flex: 1; min-width: 0; font-size: 16px; overflow-wrap: anywhere; }
.badge { flex: none; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--accent); color: var(--card); }

.edit { flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--faint); }
.edit:hover { background: var(--soft); color: var(--muted); }
.edit svg { width: 18px; height: 18px; }
.move { flex: none; display: flex; }
.move button { width: 36px; height: 40px; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); border-radius: 10px; }
.move button:disabled { color: var(--faint); opacity: 0.35; cursor: default; }

/* Stati */
.item.done .check { background: var(--ok); border-color: var(--ok); }
.item.done .check svg { opacity: 1; }
.item.done .name { color: var(--faint); text-decoration: line-through; }
.item.done .time { opacity: 0.6; }

.item.now { background: var(--accent-bg); }
.item.now .check { border-color: var(--accent); }
.item.now .name { font-weight: 600; color: var(--accent); }
.item.now .time { color: var(--accent); }

@media (hover: hover) {
  .item:not(.now) .toggle:hover { background: var(--soft); }
}

/* Stato vuoto */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; color: var(--text); }
.empty p { margin: 0 0 18px; font-size: 14px; }

/* Pulsante aggiungi */
.fab {
  position: fixed;
  right: max(20px, calc(50% - 260px));
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(0.95); }

/* Pulsanti */
.btn { padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.danger { color: var(--danger); }
.btn.danger.confirm { background: var(--danger-bg); }
.btn.wide { width: 100%; }

/* Pannelli (dialog) */
.sheet {
  width: 100%; max-width: 560px;
  margin: auto auto 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--card); color: var(--text);
  max-height: 92vh; overflow-y: auto;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet[open] { animation: up 0.22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 22px; max-width: 440px; padding-bottom: 18px; }
}

.sheet-head { display: flex; justify-content: space-between; align-items: center; margin: -4px -6px 10px 0; }
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 600; }

.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"], .field input[type="time"] {
  width: 100%; height: 46px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.field input:disabled { opacity: 0.4; }
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.time-row[hidden] { display: none; }

.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; font-size: 15px; }
.switch {
  -webkit-appearance: none; appearance: none; flex: none;
  width: 46px; height: 28px; border-radius: 14px; margin: 0;
  background: var(--soft); position: relative; cursor: pointer; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(18px); }

.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.chip {
  height: 40px; border-radius: 10px; background: var(--soft);
  font-size: 14px; font-weight: 500; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.chip:disabled { opacity: 0.3; cursor: default; }

.hint { margin: 8px 0 0; font-size: 12px; color: var(--faint); }
.hint[hidden] { display: none; }
.error { min-height: 18px; margin: 12px 0 0; font-size: 13px; color: var(--danger); }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; }
.sheet-actions .primary { margin-left: auto; min-width: 120px; }

.menu { display: flex; flex-direction: column; }
.menu-item { text-align: left; padding: 14px 4px; font-size: 16px; border-bottom: 1px solid var(--line); }
.menu-item:last-of-type { border-bottom: 0; }
.menu-hint { margin-top: 10px; }

/* Avvisi */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 40px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Desktop */
@media (min-width: 640px) {
  .app { padding-top: 48px; }
  .date { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
