:root {
  --bg: #f6f7f8; --card: #fff; --text: #14181b; --muted: #667; --line: #e2e5e8;
  --brand: #0f766e; --brand-text: #fff; --me: #d9f2ee; --warn: #b45309;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1214; --card: #171d20; --text: #e8ecee; --muted: #93a0a6; --line: #263036; --me: #12403b; --warn: #f59e0b; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, Segoe UI, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--brand); color: var(--brand-text); border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
.err { color: #dc2626; min-height: 1.2em; }
.hint { color: var(--muted); margin: 0 0 8px; }

#login { height: 100%; display: grid; place-items: center; padding: 16px; }
#loginForm { width: min(360px, 100%); display: grid; gap: 12px; }
#loginForm h1 { margin: 0 0 4px; font-size: 1.4rem; }

#app { height: 100%; display: flex; flex-direction: column; }
header { padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--brand); color: var(--brand-text); display: flex; justify-content: space-between; align-items: baseline; }
header small { opacity: .8; font-size: .75rem; }
main { flex: 1; min-height: 0; position: relative; }
.tab { position: absolute; inset: 0; padding: 12px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
#tab-chat { padding-bottom: 0; }

#msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); border-color: transparent; }
.msg p { margin: .3em 0; } .msg h2, .msg h3 { font-size: 1rem; margin: .8em 0 .2em; }
.msg ul { margin: .3em 0; padding-left: 1.2em; }
.typing { color: var(--muted); font-style: italic; }
.msg.pend { border-color: var(--warn); background: var(--card); }
.msg.pend pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 8px 0; padding: 8px 10px; background: var(--bg); border-radius: 8px; }

#chatForm { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 10px; position: sticky; bottom: 0; background: var(--bg); }
#chatForm textarea { resize: none; max-height: 140px; }
#mic.rec { background: #dc2626; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

#chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
#chips button { white-space: nowrap; padding: 6px 12px; font-size: .85rem; border-radius: 99px; }
.card.static { cursor: default; }
.fld { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); margin: 8px 0; }
.fld input { color: var(--text); }
.res { min-height: 1.2em; font-size: .85rem; margin: 6px 0 0; }
.ok { color: #16a34a; }
details { margin: 6px 0; font-size: .85rem; color: var(--muted); }
details ol { padding-left: 1.2em; margin: 6px 0; }
code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: .8rem; overflow-wrap: anywhere; }
h3.sec { margin: 18px 0 0; }
.learn { display: grid; gap: 4px; }
.learn p { margin: 0; overflow-wrap: anywhere; }
.learn small { color: var(--muted); }
.learn .bar button { padding: 4px 10px; font-size: .8rem; }
.bar.wrap { flex-wrap: wrap; align-items: center; }
.chk { display: flex; gap: 6px; align-items: center; white-space: nowrap; font-size: .9rem; }
.chk input { width: auto; }
.badge.alta { color: #dc2626; border-color: #dc2626; }
.badge.media { color: var(--warn); border-color: var(--warn); }
.badge.baja { color: var(--muted); }
.rv { display: grid; gap: 6px; }
.rv p { margin: 2px 0; }
.rv textarea { min-height: 150px; }
pre.orig { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto; font: inherit; font-size: .85rem; background: var(--bg); padding: 8px 10px; border-radius: 8px; margin: 6px 0; }
.bar { display: flex; gap: 8px; }
.bar select { width: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; }
.card h3 { margin: 0 0 2px; font-size: 1rem; }
.card small { color: var(--muted); }
.badge { font-size: .7rem; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); margin-left: 6px; }
.badge.yes { background: var(--me); } .badge.no { color: var(--muted); }
.badge.inv { color: var(--warn); border-color: var(--warn); }
.task { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.task input { width: auto; margin-top: 4px; }
.task small { color: var(--muted); display: block; }

#memory { flex: 1; min-height: 40vh; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }

#modal { position: fixed; inset: 0; background: #0008; display: flex; align-items: flex-end; z-index: 10; }
.sheet { background: var(--bg); width: 100%; max-height: 88%; overflow-y: auto; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; }
@media (min-width: 720px) { #modal { align-items: center; justify-content: center; } .sheet { width: 720px; border-radius: 18px; } }

nav { display: flex; border-top: 1px solid var(--line); background: var(--card); padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; background: none; color: var(--muted); border-radius: 0; display: grid; gap: 0; padding: 8px 0; font-size: 1.2rem; }
nav button span { font-size: .7rem; }
nav button.on { color: var(--brand); font-weight: 600; }
@media (min-width: 900px) { #app { max-width: 900px; margin: 0 auto; border-inline: 1px solid var(--line); } }
