:root {
  --bg: #f6f7f4; --surface: #ffffff; --text: #17201b; --muted: #5a665f; --line: #dfe5df;
  --brand: #0f5132; --brand-2: #157347; --accent: #b54708; --danger: #b42318; --ok: #157347; --warn: #b54708;
  --bubble-me: #0f5132; --bubble-me-text: #ffffff; --bubble: #ffffff; --chip: #e8efe9;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vvh: 100dvh; --tabs-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1512; --surface: #15201b; --text: #e8efe9; --muted: #a9b8af; --line: #26352e;
          --brand: #3fb27f; --brand-2: #46c08a; --bubble-me: #1f6b48; --bubble: #17241e; --chip: #1d2c25; --accent: #f79009; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
       padding: calc(var(--safe-top) + 8px) 16px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.verde { background: var(--ok); } .dot.amarillo { background: var(--warn); } .dot.rojo { background: var(--danger); }
.net { font-size: 13px; color: var(--accent); }
main { padding: 12px 16px calc(var(--tabs-h) + var(--safe-bottom) + 16px); max-width: 860px; margin: 0 auto; }
main:focus { outline: none; }
.view-title { font-size: 20px; margin: 4px 0 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.narrow { max-width: 440px; margin: 24px auto; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.msg { min-height: 1.2em; color: var(--danger); }
.msg.ok { color: var(--ok); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 12px; font: inherit; color: var(--text); text-align: left; min-height: 64px; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px;
       padding: 10px 14px; font: inherit; font-size: 16px; min-height: 44px; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.big { width: 100%; padding: 14px; font-weight: 600; }
.btn.link { border: none; background: none; color: var(--brand-2); text-decoration: underline; padding-left: 0; }
.btn.danger { color: var(--danger); }
.btn:focus-visible, .tile:focus-visible, .icon-btn:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--line);
                          border-radius: 12px; padding: 10px 12px; width: 100%; }
label { font-size: 14px; color: var(--muted); display: block; margin-bottom: 4px; }
details.alt { margin-top: 16px; } details.alt summary { cursor: pointer; color: var(--brand-2); min-height: 44px; display: flex; align-items: center; }
.codes { columns: 2; font-family: ui-monospace, Menlo, monospace; }
.icon-btn { appearance: none; border: none; background: transparent; font-size: 22px; min-width: 44px; min-height: 44px; border-radius: 12px; cursor: pointer; color: var(--text); }

/* Conversación */
#view-chat { display: flex; flex-direction: column; min-height: calc(var(--vvh) - 140px); }
.messages { list-style: none; padding: 0; margin: 0 0 8px; flex: 1; }
.messages li { display: flex; margin: 8px 0; }
.messages li.user { justify-content: flex-end; }
.messages li.event { justify-content: center; }
.bubble { max-width: 84%; padding: 10px 14px; border-radius: 18px; background: var(--bubble); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.messages li.user .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-color: transparent; border-bottom-right-radius: 6px; }
.messages li.assistant .bubble { border-bottom-left-radius: 6px; }
.messages li.event .bubble { background: transparent; border: none; color: var(--muted); font-size: 14px; }
.messages li.target .bubble { outline: 3px solid var(--accent); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: var(--chip); color: var(--text); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 15px; min-height: 40px; cursor: pointer; }
.approval { margin-top: 8px; padding: 12px; border: 2px solid var(--accent); border-radius: 14px; background: var(--surface); }
.approval pre { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 6px 0; color: var(--muted); max-height: 220px; overflow: auto; }
.composer { position: sticky; bottom: calc(var(--tabs-h) + var(--safe-bottom)); display: flex; gap: 6px; align-items: flex-end;
            background: var(--bg); padding: 8px 0; }
.composer textarea { resize: none; max-height: 140px; min-height: 44px; }
.mic.recording { background: var(--danger); color: #fff; }
.typing { color: var(--muted); font-size: 14px; }

/* Listas y tarjetas */
.item { display: flex; gap: 10px; align-items: flex-start; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.item .grow { flex: 1; min-width: 0; }
.item small { display: block; color: var(--muted); }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); margin-left: 6px; }
.pill.urg { background: var(--danger); color: #fff; } .pill.warn { background: #fde7c8; color: #7a3b04; }
.important { border-left: 5px solid var(--brand); }
.state-row { display: grid; grid-template-columns: 14px 1fr; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.state-row:last-child { border-bottom: none; }

/* Pestañas */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
        background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); height: calc(var(--tabs-h) + var(--safe-bottom)); }
.tabs a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted);
          text-decoration: none; font-size: 20px; min-height: 48px; }
.tabs a span { font-size: 12px; }
.tabs a.active { color: var(--brand); }
.badge { position: absolute; top: 6px; right: 24%; background: var(--danger); color: #fff; font-size: 11px; border-radius: 999px; padding: 1px 6px; }

/* Manos libres */
.handsfree { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center;
             gap: 24px; padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px); text-align: center; }
.handsfree p { font-size: 22px; max-width: 32ch; }
.hf-btn { width: min(70vw, 320px); height: min(70vw, 320px); border-radius: 50%; border: none; font-size: 80px; background: var(--brand); color: #fff; }
.hf-btn.recording { background: var(--danger); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-bottom) + 16px); z-index: 30;
         background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: 90vw; }
@media (min-width: 900px) {
  .tabs { left: 50%; transform: translateX(-50%); max-width: 860px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
