:root {
  --bg: #06070b; --panel: rgba(18, 21, 30, .68); --panel-2: rgba(30, 34, 46, .8); --line: rgba(140, 155, 210, .16);
  --gold: #e8b64c; --gold-dim: #7d6128; --gold-soft: rgba(232, 182, 76, .12);
  --text: #f1efe9; --muted: #9296a1; --ok: #58d08a; --bad: #ff7466;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pad: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: #06070b;
  color: var(--text); font: 16px/1.45 var(--font);
  display: flex; flex-direction: column; height: 100dvh; overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ testata */
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px var(--pad) 4px; }
.brand { font: 700 13px var(--mono); letter-spacing: .3em; color: var(--gold); display: flex; gap: 8px; align-items: center; }
.mark { font-size: 17px; transition: color .2s, text-shadow .2s; }
.mark.thinking { animation: blink 1s infinite; }
.mark.listening { color: var(--ok); }
.mark.speaking { text-shadow: 0 0 12px var(--gold); }
@keyframes blink { 50% { opacity: .3; } }
.top-actions { display: flex; gap: 4px; }
.icon { width: 44px; height: 44px; border-radius: 50%; color: var(--muted); display: grid; place-items: center; }
.icon:active { background: var(--panel); }
#btnVoice[aria-pressed="true"] { color: var(--gold); }
#btnVoice[aria-pressed="false"] .wave { display: none; }

/* ------------------------------------------------------------ viste */
main { flex: 1; min-height: 0; }
.view { display: none; height: 100%; overflow-y: auto; flex-direction: column; }
.view.on { display: flex; }

/* ------------------------------------------------------------ OGGI */
#view-home { padding: 6px var(--pad) 18px; align-items: stretch; }
.date { font: 600 11px var(--mono); letter-spacing: .2em; color: var(--muted); text-transform: uppercase; }
.hero h1 { font-size: 30px; line-height: 1.12; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 4px; text-wrap: balance; }
.summary { margin: 0; color: var(--muted); font-size: 15px; }

.orb { position: relative; width: 148px; height: 148px; margin: 26px auto 10px; flex: none; display: grid; place-items: center; }
.orb .core {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; color: #1a1408;
  background: radial-gradient(circle at 35% 30%, #ffe1a0, var(--gold) 55%, #b98a2c);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .15) inset, 0 10px 40px rgba(232, 182, 76, .35);
  transition: transform .15s, background .25s, box-shadow .25s;
}
.orb .core svg { width: 34px; height: 34px; stroke-width: 2; }
.orb:active .core { transform: scale(.94); }
.ring { position: absolute; inset: 0; border-radius: 50%; border: 1px solid var(--gold-dim); opacity: .55; }
.ring.r1 { inset: 12px; border-style: dashed; animation: spin 40s linear infinite; }
.ring.r2 { border-color: transparent; border-top-color: var(--gold); border-bottom-color: var(--gold-dim); animation: spin 14s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
.orb.thinking .ring.r2 { animation-duration: 1.4s; opacity: 1; }
.orb.listening .core { background: radial-gradient(circle at 35% 30%, #c6ffe0, var(--ok) 55%, #2f9c61); box-shadow: 0 0 0 10px rgba(88, 208, 138, .12), 0 10px 44px rgba(88, 208, 138, .45); animation: breathe 1.3s ease-in-out infinite; }
.orb.listening .ring { border-color: rgba(88, 208, 138, .5); }
.orb.speaking .core { animation: breathe .9s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.07); } }
.orb-hint { text-align: center; margin: 0 0 22px; color: var(--muted); font-size: 14px; min-height: 20px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 12px 12px; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.stat b { font: 700 28px/1 var(--font); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.bad.hot { border-color: rgba(255, 116, 102, .45); background: rgba(255, 116, 102, .08); }
.stat.bad.hot b { color: var(--bad); }
.stat:active { background: var(--panel-2); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 14px 8px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 650; }
.link { color: var(--gold); font-size: 13.5px; padding: 6px 0; }
.card .task { background: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; margin: 0; padding: 12px 0; }
.card .task:first-child { border-top: 0; }
.card .empty { padding: 14px 0 16px; text-align: left; }

/* ------------------------------------------------------------ attività (home + agenda) */
.task { display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; transition: opacity .3s; }
.task .chk { width: 26px; height: 26px; flex: none; border: 2px solid var(--gold-dim); border-radius: 50%; margin-top: -1px; position: relative; }
.task .chk::after { content: ""; position: absolute; inset: -9px; }       /* area di tocco più grande */
.task.done { opacity: .35; }
.task.done .tx { text-decoration: line-through; }
.task.done .chk { background: var(--gold); border-color: var(--gold); }
.task .tx { line-height: 1.3; overflow-wrap: anywhere; }
.task .meta { font: 12px var(--mono); color: var(--muted); margin-top: 3px; }
.task.late .meta { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 34px 10px; font-size: 14.5px; }

/* ------------------------------------------------------------ CHAT */
.log { flex: 1; padding: 10px var(--pad) 8px; display: flex; flex-direction: column; gap: 10px; }
.log::before { content: ""; flex: 1; }                        /* i messaggi si appoggiano in basso */
.msg { max-width: 86%; padding: 11px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--gold); color: #1a1408; border-bottom-right-radius: 6px; }
.msg.j { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.err { border-color: rgba(255, 116, 102, .5); color: var(--bad); }
.msg.sys { align-self: center; color: var(--muted); font-size: 14px; text-align: center; max-width: 100%; padding: 30px 10px; }
.msg.typing { color: var(--muted); letter-spacing: .25em; animation: blink 1.1s infinite; }
.acts { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
.act { font-size: 13px; color: var(--ok); }

/* ------------------------------------------------------------ AGENDA */
#view-agenda { padding: 10px var(--pad) 18px; }
.add { display: grid; grid-template-columns: 1fr auto; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px; margin-bottom: 6px; }
.add input { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font: inherit; min-width: 0; color-scheme: dark; }
#addText { grid-column: 1 / -1; }
.add button { background: var(--gold); color: #1a1408; border-radius: 10px; padding: 0 16px; font-weight: 650; }
.group h3 { font: 700 11px var(--mono); letter-spacing: .18em; color: var(--muted); margin: 18px 2px 8px; }
.group.overdue h3 { color: var(--bad); }

/* ------------------------------------------------------------ dock: suggerimenti + scrittura */
.dock { background: linear-gradient(to bottom, transparent, var(--bg) 22px); padding-top: 4px; }
.dock[hidden] { display: none; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 4px var(--pad) 10px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 14px; color: var(--text); }
.quick button:active { border-color: var(--gold); color: var(--gold); }
.bar { display: flex; gap: 6px; align-items: flex-end; margin: 0 12px 8px; padding: 5px; background: var(--panel); border: 1px solid var(--line); border-radius: 26px; }
.bar:focus-within { border-color: var(--gold-dim); }
.bar textarea { flex: 1; resize: none; max-height: 120px; background: none; color: var(--text); border: 0; outline: 0; padding: 10px 6px 10px 14px; font: inherit; }
.bar button { width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; }
#send { background: var(--gold); color: #1a1408; }
#send:disabled { opacity: .4; }
.mic { color: var(--muted); }
.mic.on { color: #0d2417; background: var(--ok); }
.mic[hidden] { display: none; }

/* ------------------------------------------------------------ navigazione in basso */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: rgba(11, 12, 16, .92); backdrop-filter: blur(12px); padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px; color: var(--muted); font-size: 11.5px; font-weight: 600; border-radius: 12px; }
.tab.on { color: var(--gold); }
.tab.on svg { fill: var(--gold-soft); }
.badge { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 10px; font: 700 10.5px var(--mono); font-style: normal; padding: 1px 6px; }

/* ------------------------------------------------------------ impostazioni */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; width: min(92vw, 420px); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.sheet { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet h2 { margin: 0; font-size: 19px; }
.sheet label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.sheet input { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 15px var(--mono); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.row button { border-radius: 10px; padding: 10px 18px; font-weight: 650; }
#saveToken { background: var(--gold); color: #1a1408; }
.btn-ghost { border: 1px solid var(--line); color: var(--muted); }

@media (max-height: 640px) { .orb { width: 116px; height: 116px; margin-top: 14px; } .orb .core { width: 78px; height: 78px; } .hero h1 { font-size: 25px; } }
@media (min-width: 620px) { body { max-width: 520px; margin: 0 auto; border-inline: 1px solid var(--line); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------ sfondo vivo (space.js) */
#space { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.stat, .card, .add, .bar, .msg.j, .quick button, #view-agenda .task { -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.card .task { -webkit-backdrop-filter: none; backdrop-filter: none; }
.dock { background: linear-gradient(to bottom, transparent, rgba(6, 7, 11, .82) 26px); }
.add input { background: rgba(6, 7, 11, .6); }
.orb .ring { border-color: rgba(232, 182, 76, .35); }
dialog { background: #14161c; }

/* ------------------------------------------------------------ accesso */
.login { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(6, 7, 11, .55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.login[hidden] { display: none; }
.login-box { width: min(100%, 380px); text-align: center; }
.login-mark { color: var(--gold); font-size: 34px; }
.login-box h1 { font: 700 15px var(--mono); letter-spacing: .4em; text-transform: uppercase; color: var(--gold); margin: 6px 0 14px; }
.login form { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 12px; }
.login input { background: rgba(18, 21, 30, .8); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font: inherit; }
.login input[hidden] { display: none; }
.login form button { background: var(--gold); color: #1a1408; border-radius: 12px; padding: 14px; font-weight: 700; margin-top: 4px; }
.login form button:disabled { opacity: .5; }
.login-msg { min-height: 20px; margin: 0; font-size: 14px; color: var(--bad); }
.login-msg.ok { color: var(--ok); }
body.locked > header, body.locked > main, body.locked > .dock, body.locked > nav { visibility: hidden; }
.btn-ghost.danger { color: var(--bad); margin-right: auto; }
