:root {
  --bg: #F6EEE3; --card: #FFFDF9; --ink: #2E2622; --muted: #7A6E66; --line: #E8DDD0;
  --accent: #C4655B; --accent-2: #E7A79B; --ok: #5E9C78; --warn: #D09A3A; --shadow: 0 6px 20px rgba(60,40,20,.10);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg:#1E1A18; --card:#2A2421; --ink:#F3EBE3; --muted:#B5A79C; --line:#3B322D; --shadow: 0 6px 20px rgba(0,0,0,.35); }
}
:root[data-theme="dark"] { --bg:#1E1A18; --card:#2A2421; --ink:#F3EBE3; --muted:#B5A79C; --line:#3B322D; }

* { box-sizing: border-box; }
html, body { margin:0; height:100%; }
body { background: var(--bg); color: var(--ink); font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; font-size: 16px; display:flex; flex-direction:column; min-height:100dvh; overflow-x:hidden; }
header { display:flex; align-items:center; gap:10px; padding: 12px 16px 8px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.brand { font-weight: 700; font-size: 20px; letter-spacing: .3px; flex:1; }
.chip { background: var(--card); border:1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.chip.who { color: var(--accent); font-weight:600; }
main { flex:1; padding: 0 16px; padding-bottom: calc(76px + var(--safe-b)); }
.view { display:none; }
.view.active { display:block; }
nav { position: fixed; bottom:0; left:0; right:0; display:flex; background: var(--card); border-top:1px solid var(--line); padding-bottom: var(--safe-b); z-index: 5; }
nav button { flex:1; border:0; background:none; padding: 12px 0 10px; font-size: 14px; color: var(--muted); font-weight:600; }
nav button.active { color: var(--accent); }

.card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; margin: 12px 0; }
.card.center { text-align:center; max-width: 320px; margin: 0 auto; }
h2, h3 { margin: 0 0 10px; font-size: 18px; }
label { display:block; font-size: 13px; color: var(--muted); margin: 8px 0; }
input, select, textarea { width:100%; margin-top:4px; padding: 10px 12px; border:1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font-size: 16px; font-family: inherit; }
textarea { resize: vertical; }
button { font-family: inherit; cursor:pointer; }
button.primary { width:100%; margin-top:10px; padding: 12px; border:0; border-radius: 14px; background: var(--accent); color:#fff; font-size:16px; font-weight:600; }
button.small { padding: 6px 12px; border:1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink); font-size: 13px; }
.row-between { display:flex; justify-content:space-between; align-items:center; gap:8px; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0; }
.err { color: var(--accent); font-size: 13px; min-height: 1em; }
.hidden { display:none !important; }
.overlay { position: fixed; inset:0; background: rgba(40,30,25,.55); display:flex; align-items:center; justify-content:center; padding: 20px; z-index: 20; }
.overlay .card { width:100%; max-width: 420px; max-height: 90dvh; overflow:auto; }

/* ---- avatar (chico en el tablero, grande cuando escucha o habla) ---- */
.avatar { position: relative; width: 96px; height: 96px; margin: 0 auto 4px; border-radius: 50%; overflow: hidden; background: radial-gradient(circle at 50% 35%, rgba(231,167,155,.35), rgba(231,167,155,0) 70%); transition: width .35s, height .35s; }
.avatar.listening, .avatar.speaking, .avatar.thinking { width: 170px; height: 170px; }
.avatar svg { width:100%; height:100%; display:block; position:relative; z-index:1; }
#avatar3d { position:absolute; inset:0; z-index:1; display:none; }
#avatar3d.on { display:block; }
#avatar3d canvas { width:100% !important; height:100% !important; display:block; }
.avatar .ring { position:absolute; inset:0; border-radius:50%; border: 3px solid transparent; transition: border-color .3s; z-index:2; pointer-events:none; }
.avatar.listening .ring { border-color: var(--ok); animation: pulse 1.2s ease-in-out infinite; }
.avatar.speaking .ring { border-color: var(--accent-2); }
.avatar.thinking .ring { border-color: var(--warn); }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.06); opacity: .5; } }
#head { transform-origin: 100px 120px; animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-2px) rotate(.6deg); } }
.avatar.thinking #head { animation: think 1.6s ease-in-out infinite; }
@keyframes think { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
.eye { transform-origin: center; transform-box: fill-box; }
.dots { position:absolute; bottom: 8px; right: 6px; display:none; gap:4px; z-index:2; }
.avatar.thinking .dots { display:flex; }
.dots span { width:8px; height:8px; border-radius:50%; background: var(--warn); animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay:.2s } .dots span:nth-child(3) { animation-delay:.4s }
@keyframes blink { 0%,80%,100% { opacity:.2 } 40% { opacity:1 } }

/* ---- tablero ---- */
.headline { text-align:center; margin: 2px 0 6px; }
.headline b { display:block; font-size: 24px; font-weight: 700; letter-spacing:-.2px; }
.headline span { display:block; font-size: 13px; color: var(--muted); }
.headline.asleep b { color: var(--ok); }
.alerts { display:flex; flex-direction:column; gap:6px; margin-bottom: 6px; }
.alerts:empty { display:none; }
.alerts div { font-size: 13px; padding: 8px 12px; border-radius: 12px; background: rgba(208,154,58,.15); color: var(--warn); }
.alerts div.warn { background: rgba(196,101,91,.15); color: var(--accent); font-weight:600; }
.status-row { display:flex; gap:10px; margin: 6px 0 10px; }
.mini { flex:1; background: var(--card); border-radius: 14px; padding: 8px 12px; box-shadow: var(--shadow); }
.mini b { display:block; font-size: 11px; text-transform: uppercase; letter-spacing:.5px; color: var(--muted); }
.mini span { font-size: 17px; font-weight: 700; display:block; }
.mini small { display:block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.mini .bar { display:block; height: 5px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow:hidden; }
.mini .bar em { display:block; height:100%; width:0; background: var(--ok); border-radius: 3px; transition: width .6s; }
.mini.due .bar em { background: var(--accent); }
.mini.asleep span { color: var(--ok); }
.mini.due span { color: var(--accent); }
.dayrow { display:flex; gap:10px; align-items:center; margin: 8px 0; }
.counts { flex:1; font-size: 13px; color: var(--muted); line-height: 1.4; }
.counts b { color: var(--ink); font-size: 15px; }
.meds { display:flex; gap:6px; flex-wrap:wrap; justify-content:flex-end; }
.meds button { border:1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 10px; font-size: 12px; }
.meds button.done { background: var(--ok); border-color: var(--ok); color:#fff; }
.actions { display:grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 4px; }
.actions button { border:0; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); color: var(--ink); padding: 12px 6px 10px; font-size: 14px; font-weight: 600; display:flex; flex-direction:column; align-items:center; gap:4px; min-height: 76px; }
.actions button .ico { font-size: 26px; line-height:1; }
.actions button:active { transform: scale(.96); }
.actions button.on { background: var(--ok); color:#fff; }
.actions button.on .ico { filter: grayscale(1) brightness(3); }
.sheet { position: fixed; inset:0; background: rgba(40,30,25,.5); display:flex; align-items:flex-end; z-index: 25; }
.sheet-card { background: var(--card); width:100%; border-radius: 22px 22px 0 0; padding: 18px 16px calc(16px + var(--safe-b)); box-shadow: var(--shadow); }
.sheet-card .opts { display:grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
.sheet-card .opts button { border:1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 14px; padding: 16px 0; font-size: 18px; font-weight: 700; }
.sheet-card .opts button.big { grid-column: span 2; font-size: 16px; }
.sheet-card .fine { display:flex; align-items:center; justify-content:center; gap: 14px; margin: 6px 0 12px; }
.sheet-card .fine button { width: 48px; height: 48px; border-radius: 50%; border:1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 22px; }
.sheet-card .fine b { font-size: 28px; min-width: 110px; text-align:center; }
.sheet-card .go { width:100%; margin-top: 4px; padding: 14px; border:0; border-radius: 14px; background: var(--accent); color:#fff; font-size: 17px; font-weight: 700; }
.sheet-card .small { margin-top: 8px; width:100%; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(70px + var(--safe-b)); background: var(--ink); color: var(--bg); border-radius: 14px; padding: 12px 14px; display:flex; align-items:center; gap: 10px; z-index: 30; box-shadow: var(--shadow); font-size: 14px; }
.toast span { flex:1; }
.toast button { border:0; background: var(--accent-2); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-weight: 700; }
.insight p { white-space: pre-line; }

/* ---- modo noche: oscuro y cálido, poca luz ---- */
:root.night { --bg:#160f0c; --card:#211613; --ink:#E8C9B8; --muted:#A8887A; --line:#332420; --accent:#B8574D; --accent-2:#8C4A42; --ok:#6E8F78; --warn:#A87A33; }
:root.night body { background: var(--bg); }
:root.night .avatar { filter: brightness(.75) sepia(.25); }
:root.night button.mic, :root.night .actions button { box-shadow: none; }

/* ---- transcript ---- */
.transcript { display:flex; flex-direction:column; gap:8px; max-height: 32dvh; overflow-y:auto; padding: 4px 2px; scroll-behavior: smooth; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.35; white-space: pre-wrap; }
.bubble.user { align-self:flex-end; background: var(--accent); color:#fff; border-bottom-right-radius: 4px; }
.bubble.model { align-self:flex-start; background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.bubble.sys { align-self:center; background:none; color: var(--muted); font-size: 12px; }
.bubble .acts { display:block; margin-top:6px; font-size: 12px; color: var(--ok); }

.chips { display:flex; gap:8px; overflow-x:auto; padding: 8px 0; -webkit-overflow-scrolling: touch; scrollbar-width:none; }
.chips::-webkit-scrollbar { display:none; }
.chips button { flex: 0 0 auto; border:1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 999px; font-size: 14px; }
button.live { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--ok); background: var(--card); color: var(--ok); display:flex; flex-direction:column; align-items:center; justify-content:center; gap:0; padding:0; flex: 0 0 auto; }
button.live .live-ico { font-size: 22px; line-height: 1; }
button.live small { font-size: 10px; font-weight: 700; letter-spacing:.3px; }
button.live.on { background: var(--ok); color: #fff; box-shadow: 0 6px 16px rgba(94,156,120,.45); animation: pulse 1.4s ease-in-out infinite; }

.composer { display:flex; gap:5px; align-items:center; margin-top: 4px; }
.composer input { flex:1; margin:0; min-width: 0; padding: 12px 14px; font-size: 16px; }
.composer button.icon { width: 38px; height: 38px; flex: 0 0 auto; font-size: 15px; }
.composer button.mic { background: var(--card); box-shadow: none; border:1px solid var(--line); }
.composer button.mic .mic-ico { transform: scale(.62); background: var(--accent); }
.composer button.mic .mic-ico::after { border-color: var(--accent); }
.composer button.mic.on { background: var(--ok); border-color: var(--ok); animation: pulse 1s infinite; }
.composer button.mic.on .mic-ico { background:#fff; } .composer button.mic.on .mic-ico::after { border-color:#fff; }
.composer button.live { width: 38px; height: 38px; border-radius: 50%; border:1px solid var(--line); background: var(--card); color: var(--ok); font-size: 18px; }
.composer button.live.on { background: var(--ok); color:#fff; border-color: var(--ok); }
.attach-bar { display:flex; gap:8px; flex-wrap:wrap; }
.attach-bar:empty { display:none; }
.attach-bar .att { position:relative; width:64px; height:64px; border-radius:12px; overflow:hidden; background: var(--card); box-shadow: var(--shadow); display:flex; align-items:center; justify-content:center; font-size:11px; text-align:center; padding:4px; }
.attach-bar .att img { width:100%; height:100%; object-fit:cover; }
.attach-bar .att button { position:absolute; top:2px; right:2px; width:20px; height:20px; border-radius:50%; border:0; background: rgba(0,0,0,.6); color:#fff; font-size:12px; line-height:20px; padding:0; }
.bubble img.att { max-width: 180px; max-height: 180px; border-radius: 10px; display:block; margin-top:6px; }
.bubble a.att { display:block; margin-top:6px; color: inherit; font-size: 13px; }
.events .k img { width:34px; height:34px; border-radius:10px; object-fit:cover; }
.composer input { flex:1; margin:0; }
button.icon { width: 44px; height: 44px; border-radius: 50%; border:1px solid var(--line); background: var(--card); color: var(--accent); font-size: 18px; }
button.mic { width: 64px; height: 64px; border-radius: 50%; border:0; background: var(--accent); box-shadow: 0 6px 16px rgba(196,101,91,.4); position:relative; transition: transform .15s, background .2s; }
button.mic:active { transform: scale(.95); }
button.mic.on { background: var(--ok); box-shadow: 0 6px 16px rgba(94,156,120,.45); animation: pulse 1s infinite; }
.mic-ico { display:block; width: 16px; height: 26px; margin: 0 auto; background:#fff; border-radius: 8px; position:relative; }
.mic-ico::after { content:""; position:absolute; left:-6px; right:-6px; bottom:-8px; height: 14px; border: 3px solid #fff; border-top:0; border-radius: 0 0 14px 14px; }

/* ---- lists ---- */
.summary { font-size: 14px; color: var(--muted); margin-bottom: 8px; white-space: pre-line; }
.events { list-style:none; margin:0; padding:0; }
.events li { display:flex; align-items:center; gap:10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.events li:first-child { border-top:0; }
.events .k { width: 34px; height: 34px; border-radius: 10px; display:flex; align-items:center; justify-content:center; font-size: 16px; background: var(--bg); flex: 0 0 auto; }
.events .t { flex:1; }
.events .t small { display:block; color: var(--muted); }
.events .del { border:0; background:none; color: var(--muted); font-size: 18px; padding: 4px 8px; }
.reminders { font-size: 13px; color: var(--warn); margin-top: 6px; white-space: pre-line; }
.week { display:flex; align-items:flex-end; gap:6px; height: 120px; }
.week .bar { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:flex-end; height:100%; font-size: 10px; color: var(--muted); }
.week .bar i { display:block; width:100%; background: var(--accent-2); border-radius: 6px 6px 0 0; }
.week .bar b { font-size: 11px; color: var(--ink); }
.seg { display:flex; border:1px solid var(--line); border-radius: 12px; overflow:hidden; }
.seg button { flex:1; border:0; padding: 10px; background: var(--card); color: var(--ink); font-size: 15px; }
.seg button.on { background: var(--accent); color:#fff; }
.switch { display:flex; align-items:center; gap:10px; font-size: 15px; color: var(--ink); margin-top: 12px; }
.switch input { width:auto; margin:0; }
