:root {
  --bg: #000;
  --card: rgba(28, 28, 30, 0.58);
  --card-2: rgba(44, 44, 46, 0.6);
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --txt: #f5f5f7;
  --muted: rgba(235, 235, 245, 0.55);
  --faint: rgba(235, 235, 245, 0.3);
  --accent: #ff8a1f;
  --accent-2: #ff5e1a;
  --red: #ff453a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --dock-h: 84px;
  --r: 22px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Inter, system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); }
body { overflow-x: hidden; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.bg-glow {
  position: fixed; inset: -20% -10% auto -10%; height: 70vh; pointer-events: none; z-index: 0;
  background:
    radial-gradient(40% 45% at 20% 10%, rgba(255, 138, 31, 0.16), transparent 70%),
    radial-gradient(35% 40% at 85% 0%, rgba(255, 94, 26, 0.10), transparent 70%);
  filter: blur(10px);
}

.glass {
  background: var(--card);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  backdrop-filter: blur(28px) saturate(170%);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 40px rgba(0, 0, 0, 0.45);
}

/* ---------- PIN ---------- */
.pin { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; padding: 24px; }
.pin-card { width: min(360px, 100%); border-radius: 28px; padding: 32px 26px; text-align: center; }
.pin-logo { width: 72px; height: 72px; border-radius: 18px; }
.pin-card h1 { font-size: 22px; margin: 14px 0 4px; letter-spacing: -0.02em; }
.pin-card p { margin: 0 0 18px; color: var(--muted); }
#pin-input {
  width: 100%; text-align: center; font-size: 28px; letter-spacing: 0.4em; padding: 14px; border-radius: 16px;
  background: rgba(118, 118, 128, 0.18); border: 1px solid var(--line); outline: none; margin-bottom: 12px;
}
#pin-input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 14px; border-radius: 16px; font-weight: 600; font-size: 17px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff;
}
.err { color: var(--red); min-height: 20px; margin: 12px 0 0 !important; }

/* ---------- top ---------- */
#app { position: relative; z-index: 1; min-height: 100%; padding: calc(var(--safe-t) + 14px) 16px calc(var(--dock-h) + var(--safe-b) + 24px); }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 4px 14px; }
.month-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.month-title h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.03em; }
.month-title span { color: var(--accent); font-size: 20px; font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.pill {
  padding: 7px 14px; border-radius: 999px; font-size: 15px; font-weight: 600;
  background: rgba(118, 118, 128, 0.22); border: 1px solid var(--line);
}
.pill.small { padding: 7px 12px; font-size: 14px; }
.pill.accent { background: var(--accent); color: #fff; border-color: transparent; }
.pill.ghost { background: transparent; border-color: var(--line-2); color: var(--muted); }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: rgba(118, 118, 128, 0.22); border: 1px solid var(--line); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 2.4; }

/* ---------- calendario ---------- */
.layout { display: grid; gap: 18px; }
.cal { border-radius: var(--r); padding: 10px 8px 8px; touch-action: pan-y; }
.dow { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; font-weight: 600; color: var(--faint); padding: 2px 0 6px; }
.dow span:nth-child(7) { color: rgba(255, 69, 58, 0.6); }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 52px; gap: 2px; }
.cell { position: relative; border-radius: 14px; display: flex; flex-direction: column; align-items: center; padding-top: 6px; transition: background 0.15s; }
.cell:active { background: rgba(255, 255, 255, 0.06); }
.cell .n { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; }
.cell.out .n { color: var(--faint); }
.cell.dom .n { color: rgba(255, 105, 97, 0.9); }
.cell.out.dom .n { color: rgba(255, 105, 97, 0.35); }
.cell.today .n { background: var(--accent); color: #fff; font-weight: 700; }
.cell.sel:not(.today) .n { background: rgba(255, 255, 255, 0.92); color: #000; font-weight: 700; }
.cell.sel.today .n { box-shadow: 0 0 0 3px rgba(255, 138, 31, 0.35); }
.dots { display: flex; gap: 3px; margin-top: 4px; height: 6px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.chips { display: none; }

/* ---------- giorno ---------- */
.side { display: grid; gap: 18px; align-content: start; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 6px 10px; gap: 10px; }
.day-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; text-transform: capitalize; }
.list { display: grid; gap: 8px; }
.ev {
  display: grid; grid-template-columns: 4px 64px 1fr; gap: 12px; align-items: center; text-align: left; width: 100%;
  padding: 12px 14px 12px 10px; border-radius: 16px; background: var(--card); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); animation: pop 0.25s ease;
}
.ev:active { transform: scale(0.985); }
.ev .bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--c, var(--accent)); }
.ev .t { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; line-height: 1.25; }
.ev .t small { display: block; color: var(--muted); font-weight: 500; font-size: 13px; }
.ev .tit { font-size: 16px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.ev .tit small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.new { box-shadow: 0 0 0 2px var(--accent); }
.empty { padding: 26px 18px; border-radius: 16px; border: 1px dashed var(--line-2); color: var(--muted); text-align: center; line-height: 1.5; font-size: 15px; }
.next h3 { margin: 0 6px 10px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.list.compact .ev { grid-template-columns: 4px 1fr; padding: 10px 12px 10px 10px; }
.list.compact .ev .t { display: none; }
.hint { color: var(--faint); font-size: 12px; margin: 0 6px; }
.desk-only { display: none; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- dock + microfono ---------- */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 12px); z-index: 3;
  width: min(420px, calc(100% - 24px)); height: 68px; border-radius: 34px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 18px;
}
.dock-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }
.dock-btn svg { width: 24px; height: 24px; }
.dock-btn:active { color: var(--txt); }
.mic {
  position: relative; width: 84px; height: 84px; margin-top: -34px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 28%, #ffb15c, var(--accent) 45%, var(--accent-2) 100%); color: #fff;
  box-shadow: 0 10px 30px rgba(255, 110, 20, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 0 0 6px rgba(0, 0, 0, 0.6);
  transition: transform 0.15s;
}
.mic:active { transform: scale(0.93); }
.mic svg { width: 36px; height: 36px; stroke-width: 2.2; }
.mic-ring { position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(255, 138, 31, 0.5); animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1); opacity: 0.6; } 50% { transform: scale(1.12); opacity: 0; } }

/* ---------- ascolto ---------- */
.listen {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.62); -webkit-backdrop-filter: blur(30px) saturate(150%); backdrop-filter: blur(30px) saturate(150%);
  animation: fade 0.2s ease;
}
.listen-inner { display: flex; flex-direction: column; align-items: center; gap: 26px; padding: 24px; text-align: center; }
.listen-state { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.listen-hint { margin: 0; color: var(--muted); max-width: 300px; line-height: 1.45; font-size: 15px; }
.orb { position: relative; width: 220px; height: 220px; display: grid; place-items: center; }
.orb-core {
  position: relative; z-index: 2; width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 35% 28%, #ffbe73, var(--accent) 45%, var(--accent-2) 100%);
  box-shadow: 0 0 60px rgba(255, 120, 30, 0.55), inset 0 3px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.08s linear;
}
.orb-core svg { width: 52px; height: 52px; }
.orb-ring { position: absolute; inset: 44px; border-radius: 50%; border: 2px solid rgba(255, 138, 31, 0.55); animation: ripple 1.8s ease-out infinite; }
.orb-ring.r2 { animation-delay: 0.6s; } .orb-ring.r3 { animation-delay: 1.2s; }
@keyframes ripple { from { transform: scale(1); opacity: 0.8; } to { transform: scale(1.75); opacity: 0; } }
.listen.thinking .orb-ring { animation: none; opacity: 0; }
.listen.thinking .orb-core { animation: spinGlow 1.1s linear infinite; }
.listen.thinking .orb-core svg { opacity: 0.5; }
@keyframes spinGlow { 0% { box-shadow: 0 0 40px rgba(255, 120, 30, 0.4); transform: scale(0.94); } 50% { box-shadow: 0 0 80px rgba(255, 120, 30, 0.8); transform: scale(1); } 100% { box-shadow: 0 0 40px rgba(255, 120, 30, 0.4); transform: scale(0.94); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 96px); z-index: 11;
  width: min(440px, calc(100% - 24px)); border-radius: 22px; padding: 14px; display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center;
  animation: up 0.3s cubic-bezier(.2, .9, .3, 1.2);
}
.toast-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #30d158; color: #000; font-weight: 800; font-size: 20px; }
.toast.err .toast-icon { background: var(--red); color: #fff; }
.toast-body { display: grid; gap: 2px; min-width: 0; }
.toast-body strong { font-size: 16px; overflow-wrap: anywhere; }
.toast-body span { color: var(--muted); font-size: 14px; text-transform: none; }
.toast-body em { color: var(--faint); font-size: 12px; font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
@keyframes up { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- schede ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 12; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); animation: fade 0.2s; }
.sheet {
  position: relative; width: min(560px, 100%); max-height: 92vh; overflow: auto; border-radius: 26px 26px 0 0;
  padding: 8px 18px calc(var(--safe-b) + 22px); background: rgba(28, 28, 30, 0.92); animation: sheetUp 0.32s cubic-bezier(.2, .9, .3, 1);
  display: grid; gap: 14px;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 4px auto 0; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-head .link:last-child { justify-self: end; }
.link { color: var(--accent); font-size: 17px; }
.link.strong { font-weight: 700; }
.field { display: grid; gap: 6px; flex: 1; min-width: 0; }
.field > span, .switch > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field textarea, #type-text {
  width: 100%; padding: 12px 14px; border-radius: 14px; background: rgba(118, 118, 128, 0.18); border: 1px solid var(--line); outline: none; font-size: 17px;
  min-height: 48px;
}
.field input:focus, .field textarea:focus, #type-text:focus { border-color: var(--accent); }
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; }
textarea { resize: none; }
.row { display: flex; gap: 12px; align-items: flex-end; }
.switch { display: grid; gap: 6px; justify-items: start; padding-bottom: 8px; }
.switch input { display: none; }
.switch i { width: 51px; height: 31px; border-radius: 16px; background: rgba(120, 120, 128, 0.32); position: relative; transition: background 0.2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.switch input:checked + i { background: #30d158; }
.switch input:checked + i::after { transform: translateX(20px); }
.colors { display: flex; gap: 12px; flex-wrap: wrap; padding: 4px 0; }
.colors button { width: 30px; height: 30px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px rgba(0,0,0,.25); }
.colors button.on { box-shadow: 0 0 0 3px #000, 0 0 0 5px var(--c); }
.btn-danger { padding: 14px; border-radius: 14px; color: var(--red); background: rgba(255, 69, 58, 0.12); font-weight: 600; font-size: 16px; }
.frase { font-size: 13px; margin: -4px 2px 0; }
.frase:empty { display: none; }
.preview { min-height: 22px; margin: 0 4px; font-size: 15px; }

/* ---------- computer ---------- */
@media (min-width: 900px) {
  :root { --dock-h: 96px; }
  #app { max-width: 1320px; margin: 0 auto; padding: 28px 32px calc(var(--dock-h) + 24px); }
  .top { margin: 0 6px 18px; }
  .month-title h1 { font-size: 44px; }
  .layout { grid-template-columns: minmax(0, 1fr) 360px; gap: 26px; align-items: start; }
  .cal { padding: 14px; }
  .dow { font-size: 13px; padding-bottom: 10px; text-align: left; padding-left: 10px; }
  .grid { grid-auto-rows: minmax(108px, 1fr); gap: 4px; }
  .cell { align-items: stretch; padding: 6px; border-radius: 14px; border: 1px solid transparent; cursor: pointer; overflow: hidden; }
  .cell:hover { background: rgba(255, 255, 255, 0.04); }
  .cell.sel { border-color: var(--line-2); background: rgba(255, 255, 255, 0.05); }
  .cell .n { width: 28px; height: 28px; font-size: 15px; }
  .cell.sel:not(.today) .n { background: transparent; color: var(--txt); }
  .dots { display: none; }
  .chips { display: grid; gap: 3px; margin-top: 4px; min-width: 0; }
  .chips b { display: block; font-size: 12px; font-weight: 600; padding: 3px 6px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: color-mix(in srgb, var(--c, var(--accent)) 24%, transparent); color: color-mix(in srgb, var(--c, var(--accent)) 35%, #fff); }
  .chips b small { opacity: 0.75; font-weight: 500; margin-right: 4px; }
  .chips em { font-size: 11px; color: var(--muted); font-style: normal; padding-left: 6px; }
  .desk-only { display: block; }
  .side { position: sticky; top: 24px; }
  .dock { width: 380px; }
  .toast { bottom: 110px; }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 26px; padding-bottom: 22px; }
}

/* ---------- ritocchi ---------- */
@media (max-width: 899px) {
  .month-title { flex-direction: column-reverse; align-items: flex-start; gap: 0; }
  .month-title span { font-size: 15px; letter-spacing: 0.02em; }
  .month-title h1 { line-height: 1.05; }
}
@media (min-width: 900px) {
  .grid { grid-auto-rows: minmax(84px, calc((100vh - 300px) / 6)); }
  .side { max-height: calc(100vh - 48px); overflow-y: auto; scrollbar-width: none; padding-bottom: 110px; }
  .side::-webkit-scrollbar { display: none; }
}
