:root {
  --navy: #0B2545;
  --navy-2: #13315C;
  --teal: #0FA3A3;
  --teal-strong: #0B7F7F;
  --teal-soft: #E3F5F5;
  --bg: #F4F7FA;
  --surface: #FFFFFF;
  --surface-2: #EEF3F7;
  --text: #0B2545;
  --muted: #5B6B7F;
  --line: #D5DEE8;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --warn: #8A5A00;
  --warn-soft: #FFF4DB;
  --ok: #157F3B;
  --ok-soft: #E6F6EC;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(11, 37, 69, .06), 0 4px 14px rgba(11, 37, 69, .06);
  --tap: 52px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A1626; --surface: #112238; --surface-2: #17304D; --text: #EAF1F8; --muted: #9FB2C8; --line: #24405F;
    --teal-soft: #0F3A41; --danger-soft: #3A1714; --warn-soft: #3A2C0B; --ok-soft: #0F3020; --navy: #EAF1F8; --navy-2: #CFE0F2;
    --teal: #2CC4C4; --teal-strong: #5BD8D8; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0A1626; --surface: #112238; --surface-2: #17304D; --text: #EAF1F8; --muted: #9FB2C8; --line: #24405F;
  --teal-soft: #0F3A41; --danger-soft: #3A1714; --warn-soft: #3A2C0B; --ok-soft: #0F3020; --navy: #EAF1F8; --navy-2: #CFE0F2;
  --teal: #2CC4C4; --teal-strong: #5BD8D8; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--teal-strong); }
small, .muted { color: var(--muted); }
.hidden { display: none !important; }

.boot { min-height: 80vh; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--teal); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout */
.topbar {
  position: sticky; top: 0; z-index: 20; background: #0B2545; color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 10px;
}
.topbar .brand { font-weight: 700; font-size: 1.02rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand small { color: #9FC7D6; font-weight: 500; display: block; font-size: .78rem; }
.topbar button { color: #fff; }
.demo-banner { background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: .85rem; padding: 8px 16px; text-align: center; border-bottom: 1px solid var(--line); }
main.page { max-width: 880px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .74rem; font-weight: 600;
}
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a.active { color: var(--teal-strong); }
@media (min-width: 900px) {
  .bottom-nav { top: 64px; bottom: 0; right: auto; width: 96px; grid-template-columns: 1fr; grid-auto-rows: 76px; border-top: 0; border-right: 1px solid var(--line); align-content: start; }
  .bottom-nav a { height: 76px; }
  main.page { padding-left: 120px; max-width: 1000px; padding-bottom: 120px; }
  .convo-bar { left: 96px !important; }
}

/* ---------- Componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.flat { box-shadow: none; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title h2, .card-title h3 { margin: 0; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.sep { height: 1px; background: var(--line); margin: 12px 0; border: 0; }

button, .btn {
  font: inherit; font-weight: 600; border-radius: 12px; border: 1px solid transparent; cursor: pointer;
  min-height: 44px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; background: var(--surface-2); color: var(--text); transition: filter .15s, transform .05s;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.btn-primary { background: #0B2545; color: #fff; }
:root[data-theme="dark"] .btn-primary { background: var(--teal); color: #04212A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { background: var(--teal); color: #04212A; } }
.btn-teal { background: var(--teal); color: #fff; }
.btn-outline { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { background: transparent; color: inherit; padding: 8px 10px; }
.btn-lg { min-height: var(--tap); font-size: 1.05rem; padding: 12px 20px; border-radius: 14px; }
.btn-block { width: 100%; }
.icon-btn { min-height: 44px; min-width: 44px; padding: 8px; background: transparent; }
.btn svg, button svg { width: 20px; height: 20px; flex: none; }

.hero-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-bottom: 14px; }
.hero-actions .btn { min-height: 72px; font-size: 1.08rem; flex-direction: column; gap: 4px; }
.hero-actions .btn svg { width: 26px; height: 26px; }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--teal); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--text); font-size: .95rem; min-height: 44px; }
.field { margin-bottom: 10px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.field .err { font-size: .82rem; color: var(--danger); margin-top: 4px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .76rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.teal { background: var(--teal-soft); color: var(--teal-strong); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.navy { background: #0B2545; color: #fff; }

.status-borrador { background: var(--surface-2); color: var(--muted); }
.status-listo { background: var(--teal-soft); color: var(--teal-strong); }
.status-enviado { background: #E7EEFB; color: #24489B; }
.status-aceptado { background: var(--ok-soft); color: var(--ok); }
.status-rechazado { background: var(--danger-soft); color: var(--danger); }
.status-vencido { background: var(--warn-soft); color: var(--warn); }

.alert { border-radius: 12px; padding: 12px 14px; font-size: .92rem; margin-bottom: 12px; border: 1px solid transparent; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(138, 90, 0, .2); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--teal-soft); color: var(--teal-strong); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 60px; }
.list-item:last-child { border-bottom: 0; }
.list-item > svg { width: 22px; height: 22px; flex: none; color: var(--muted); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { font-size: .84rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat .s { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.search { position: relative; margin-bottom: 12px; }
.search input { padding-left: 40px; }
.search svg { position: absolute; left: 12px; top: 13px; width: 20px; height: 20px; color: var(--muted); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.filters button { min-height: 36px; padding: 6px 14px; border-radius: 999px; font-size: .86rem; background: var(--surface); border-color: var(--line); white-space: nowrap; }
.filters button.on { background: #0B2545; color: #fff; border-color: #0B2545; }

/* ---------- Partidas */
.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: var(--surface); }
.item.pending { border-color: rgba(180, 35, 24, .45); background: linear-gradient(0deg, var(--danger-soft), var(--danger-soft)) left / 4px 100% no-repeat, var(--surface); }
.item-head { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.item-head .desc { flex: 1; min-width: 0; font-weight: 650; }
.item-head .desc small { display: block; font-weight: 500; }
.item-head .amt { font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.item-body { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.cands { display: grid; gap: 6px; margin-top: 8px; }
.cands button { justify-content: space-between; text-align: left; font-weight: 500; background: var(--teal-soft); color: var(--teal-strong); }

.totals { font-variant-numeric: tabular-nums; }
.totals .tr { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .tr.total { font-size: 1.25rem; font-weight: 800; border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; }
.totals .note { font-size: .8rem; color: var(--muted); margin-top: 6px; }

.textlist li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--line); }
.textlist li span { flex: 1; }

/* ---------- Barra conversacional */
.convo-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25;
  background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px; box-shadow: 0 -4px 16px rgba(11, 37, 69, .08);
}
.convo-inner { max-width: 880px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.convo-inner textarea { min-height: 48px; max-height: 140px; height: 48px; padding: 12px; }
.mic { background: var(--teal); color: #fff; min-width: 52px; min-height: 48px; border-radius: 12px; }
.mic.rec { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(180, 35, 24, .15); } }

.rec-panel { text-align: center; padding: 8px 0; }
.rec-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); margin-right: 6px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-time { font-size: 2rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.interim { min-height: 3em; color: var(--muted); font-style: italic; }

.changes li { padding: 6px 0 6px 26px; position: relative; border-bottom: 1px solid var(--line); font-size: .94rem; }
.changes li::before { content: "✓"; position: absolute; left: 4px; color: var(--teal-strong); font-weight: 800; }
.questions li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.questions li::before { content: "?"; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); font-weight: 800; font-size: .8rem; margin-right: 8px; }
.opts { display: grid; gap: 6px; margin-top: 8px; }
.opts button { justify-content: flex-start; text-align: left; background: var(--surface-2); font-weight: 500; }

/* ---------- Modal / hoja inferior */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(5, 15, 30, .5); display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
@media (min-width: 700px) { .modal-backdrop { align-items: center; } .modal { border-radius: 20px; } }
.modal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.modal-head h2 { flex: 1; margin: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions > * { flex: 1; }
.pdf-frame { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* ---------- Toasts */
.toasts { position: fixed; z-index: 80; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: #0B2545; color: #fff; border-radius: 12px; padding: 12px 14px; max-width: 520px; width: 100%; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); font-size: .94rem; }
.toast.error { background: var(--danger); }
.toast.ok { background: #136C3A; }
.toast button { background: rgba(255, 255, 255, .16); color: #fff; min-height: 36px; padding: 6px 12px; }
.toast .msg { flex: 1; }

.auth-wrap { max-width: 440px; margin: 0 auto; padding: 32px 16px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-logo img { width: 52px; height: 52px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs button { background: transparent; min-height: 40px; }
.tabs button.on { background: var(--surface); box-shadow: var(--shadow); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .94rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.copy-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.copy-row .k { color: var(--muted); font-size: .82rem; font-weight: 600; width: 110px; flex: none; }
.copy-row .v { flex: 1; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table.simple { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.simple td.num, table.simple th.num { text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.empty svg { width: 40px; height: 40px; opacity: .5; }
.outbox { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.sim-badge { background: repeating-linear-gradient(-45deg, var(--warn-soft), var(--warn-soft) 8px, transparent 8px, transparent 16px); border: 2px dashed var(--warn); color: var(--warn); font-weight: 800; padding: 10px; border-radius: 12px; text-align: center; margin-bottom: 12px; }
