:root {
  --bg: #f3f4f6; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --primary: #1d4ed8; --primary-soft: #dbeafe;
  --milano: #3b82f6; --milano-bg: #dbeafe; --milano-text: #1e40af;
  --lago: #10b981; --lago-bg: #d1fae5; --lago-text: #065f46;
  --trip: #f59e0b; --trip-bg: #fef3c7; --trip-text: #92400e;
  --visita: #ef4444; --evento: #8b5cf6; --altro: #6b7280;
  --danger: #dc2626;
  --nav-h: 60px; --top-h: 52px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #1e293b; --text: #f1f5f9; --muted: #94a3b8; --line: #334155;
    --primary: #60a5fa; --primary-soft: #1e3a8a;
    --milano-bg: #1e3a8a; --milano-text: #bfdbfe;
    --lago-bg: #064e3b; --lago-text: #a7f3d0;
    --trip-bg: #78350f; --trip-text: #fde68a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.35;
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; min-height: 18px; margin-top: 8px; }

/* ── login ── */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.login-card { background: var(--card); border-radius: 20px; padding: 28px 22px; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.12); text-align: center; }
.login-logo { font-size: 48px; }
.login-card h1 { margin: 6px 0 0; font-size: 26px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 12px; }
.who-btn { padding: 16px 8px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); font-size: 17px; font-weight: 600; }
.who-btn.active { border-color: var(--primary); background: var(--primary-soft); }
.login-card input[type=password] { width: 100%; padding: 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); font-size: 17px; margin-bottom: 12px; }

/* ── buttons ── */
.btn { padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.milano { background: var(--milano); border-color: var(--milano); color: #fff; }
.btn.lago { background: var(--lago); border-color: var(--lago); color: #fff; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn.block { width: 100%; display: block; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.icon-btn { background: transparent; border: 0; font-size: 22px; padding: 6px 10px; border-radius: 10px; color: var(--text); line-height: 1; }
.icon-btn:active { background: var(--line); }
.chip-btn { padding: 7px 12px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; }
.chip-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── layout ── */
#app { min-height: 100%; padding-top: calc(var(--top-h) + var(--sat)); padding-bottom: calc(var(--nav-h) + var(--sab) + 8px); }
.top {
  position: fixed; top: 0; left: 0; right: 0; height: calc(var(--top-h) + var(--sat)); padding-top: var(--sat);
  display: flex; align-items: center; gap: 4px; padding-left: 6px; padding-right: 10px;
  background: var(--card); border-bottom: 1px solid var(--line); z-index: 20;
}
.month-title { flex: 1; text-align: center; font-weight: 700; font-size: 18px; text-transform: capitalize; }
main { padding: 10px 8px; }
.view { max-width: 640px; margin: 0 auto; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--sab)); padding-bottom: var(--sab);
  display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 20;
}
.bottom-nav button { flex: 1; border: 0; background: transparent; font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding-top: 6px; }
.bottom-nav button span { font-size: 22px; }
.bottom-nav button.active { color: var(--primary); }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--sab) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--primary); color: #fff;
  font-size: 32px; line-height: 1; box-shadow: 0 6px 20px rgba(29,78,216,.4); z-index: 25;
}

/* ── legend / weekdays / grid ── */
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); padding: 2px 4px 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.milano { background: var(--milano); } .sw.lago { background: var(--lago); } .sw.trip { background: var(--trip); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.visita { background: var(--visita); } .dot.evento { background: var(--evento); } .dot.altro { background: var(--altro); } .dot.trasferta { background: var(--trip); }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 0 4px; }
.weekdays span:nth-child(6), .weekdays span:nth-child(7) { color: #b45309; }

.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cell {
  position: relative; min-height: 72px; border-radius: 9px; background: var(--card); border: 1.5px solid var(--line);
  padding: 3px 3px 12px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; user-select: none;
}
.cell.other { opacity: .42; }
.cell.milano { background: var(--milano-bg); border-color: var(--milano); }
.cell.lago { background: var(--lago-bg); border-color: var(--lago); }
.cell.today .dn { background: var(--primary); color: #fff; }
.cell.selected { outline: 3px solid #f472b6; outline-offset: -3px; }
.cell.selectable { cursor: pointer; }
.dn { font-size: 12px; font-weight: 700; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; align-self: flex-start; }
.cell.milano .dn:not(.today .dn) { color: var(--milano-text); }
.cell.lago .dn:not(.today .dn) { color: var(--lago-text); }
.chip { font-size: 9.5px; line-height: 1.2; padding: 1px 3px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; color: #fff; }
.chip.visita { background: var(--visita); } .chip.evento { background: var(--evento); } .chip.altro { background: var(--altro); }
.chip.more { background: transparent; color: var(--muted); padding: 0 2px; }
.trip-bar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: var(--trip); color: #fff;
  font-size: 9px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 2px; white-space: nowrap; overflow: hidden;
}
.trip-bar.start { border-top-left-radius: 4px; } .trip-bar.end { border-top-right-radius: 4px; }
.cell .trip-bar + .trip-bar { bottom: 12px; opacity: .85; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 6px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat small { color: var(--muted); font-size: 11px; }
.stat.milano b { color: var(--milano); } .stat.lago b { color: var(--lago); } .stat.trip b { color: var(--trip); }
.toolbar { margin: 4px 0 10px; }
.toolbar .btn { width: 100%; }

.install-banner { display: flex; align-items: center; gap: 8px; background: var(--primary-soft); border-radius: 12px; padding: 8px 8px 8px 12px; margin: 6px 0; font-size: 14px; font-weight: 600; }
.install-banner span { flex: 1; }

/* ── select bar ── */
.select-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--sab)); background: var(--card); border-top: 2px solid #f472b6;
  padding: 10px 12px; z-index: 22; box-shadow: 0 -6px 20px rgba(0,0,0,.12);
}
.select-info { font-size: 14px; margin-bottom: 8px; }
.select-actions { display: flex; gap: 6px; }
.select-actions .btn { flex: 1; padding: 10px 4px; font-size: 14px; }

/* ── sheet ── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; margin: 0 auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--sab));
  max-height: 85vh; overflow-y: auto; animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.sheet-title { font-size: 20px; font-weight: 700; text-transform: capitalize; }
.seg { display: flex; gap: 6px; margin: 6px 0 12px; }
.seg button { flex: 1; padding: 10px 3px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
#daySeg button[data-loc=milano].active { background: var(--milano); border-color: var(--milano); }
#daySeg button[data-loc=lago].active { background: var(--lago); border-color: var(--lago); }
.day-events { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.ev-item { display: flex; gap: 10px; align-items: center; background: var(--bg); border-radius: 12px; padding: 10px 12px; border-left: 5px solid var(--altro); }
.ev-item.visita { border-left-color: var(--visita); } .ev-item.evento { border-left-color: var(--evento); } .ev-item.trasferta { border-left-color: var(--trip); }
.ev-item .ev-icon { font-size: 22px; }
.ev-item .ev-body { flex: 1; min-width: 0; }
.ev-item .ev-title { font-weight: 700; }
.ev-item .ev-sub { font-size: 13px; color: var(--muted); }
.ev-item .ev-notes { font-size: 13px; margin-top: 2px; white-space: pre-wrap; }
.empty { text-align: center; color: var(--muted); padding: 16px; font-size: 14px; }

/* ── modal ── */
.modal { position: fixed; inset: 0; background: var(--card); z-index: 50; overflow-y: auto; }
.modal-card { max-width: 640px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.modal-head { position: sticky; top: 0; display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--sat)) 10px 8px; background: var(--card); border-bottom: 1px solid var(--line); z-index: 2; }
.modal-title { flex: 1; font-weight: 700; font-size: 18px; }
.modal-body { padding: 12px 16px calc(24px + var(--sab)); }
.modal-body label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.modal-body input, .modal-body textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); font-size: 16px; }
.modal-body textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#evDelete { margin-top: 20px; }
#evMeta { margin-top: 12px; }

/* ── list view ── */
.list-day { margin-bottom: 10px; }
.list-day h3 { font-size: 14px; margin: 12px 0 6px; text-transform: capitalize; display: flex; align-items: center; gap: 8px; }
.list-day h3 .tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.tag.milano { background: var(--milano-bg); color: var(--milano-text); } .tag.lago { background: var(--lago-bg); color: var(--lago-text); }
.list-day .ev-item { margin-bottom: 6px; }
.section-title { font-size: 15px; font-weight: 700; margin: 16px 0 8px; }

/* ── settings ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.card p { margin: 4px 0 10px; font-size: 14px; color: var(--muted); }
.card input { width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); font-size: 16px; margin-bottom: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 15px; background: var(--line); border: 0; flex-shrink: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch.on { background: var(--lago); } .switch.on::after { left: 23px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed .who { display: inline; margin: 0; font-weight: 700; }
.feed time { color: var(--muted); font-size: 12px; display: block; }

/* ── toast ── */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--sab) + 20px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 90vw; text-align: center; }

@media (min-width: 480px) { .cell { min-height: 84px; } .chip { font-size: 11px; } .trip-bar { font-size: 10px; height: 14px; } }
