:root {
  --paper: #EEF2F5;
  --surface: #FFFFFF;
  --ink: #16233B;
  --muted: #5B6B82;
  --line: #D8DFE8;
  --brand: #22406E;
  --brand-ink: #FFFFFF;
  --go: #1E9E5A;
  --wait: #E0A106;
  --stop: #D93A3A;
  --late: #7F1D1D;
  --off: #C9D1DC;
  --bubble-me: #22406E;
  --bubble-me-ink: #FFFFFF;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1726;
    --surface: #182236;
    --ink: #E8EDF5;
    --muted: #9AA8BD;
    --line: #2A3650;
    --brand: #8FB0E6;
    --brand-ink: #0F1726;
    --off: #33405A;
    --bubble-me: #2C4A7C;
    --bubble-me-ink: #FFFFFF;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.muted { color: var(--muted); }
.error { color: var(--stop); min-height: 1.2em; font-size: .9rem; }

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); padding: 32px 28px;
  border-radius: var(--radius-lg); border: 1px solid var(--line); display: grid; gap: 14px;
}
.login-card h1 { margin: 6px 0 0; font-size: 1.75rem; letter-spacing: -.02em; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.brand-lights { display: flex; gap: 6px; }
.brand-lights i { width: 14px; height: 14px; border-radius: 50%; background: var(--go); }
.brand-lights i:nth-child(2) { background: var(--wait); }
.brand-lights i:nth-child(3) { background: var(--stop); }

input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--paper);
}
.btn { border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn:disabled { opacity: .6; }

/* ---------- layout */
.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--paper);
}
.topbar h1 { margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; }
.topbar-actions { display: flex; gap: 4px; }
main { overflow: hidden; position: relative; }
.view { height: 100%; overflow-y: auto; padding: 4px 16px 24px; max-width: 760px; margin: 0 auto; }

.icon-btn {
  width: 42px; height: 42px; border: 0; background: transparent; border-radius: 50%;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn[aria-pressed="true"] { color: var(--brand); background: var(--surface); }

/* ---------- tabbar */
.tabbar {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  position: relative; display: grid; justify-items: center; gap: 3px; padding: 9px 0 8px;
  color: var(--muted); text-decoration: none; font-size: .74rem; font-weight: 600;
}
.tabbar a svg { width: 23px; height: 23px; fill: currentColor; }
.tabbar a[aria-current="page"] { color: var(--ink); }
.nav-lights { display: flex; gap: 3px; height: 23px; align-items: center; }
.nav-lights i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }
.tabbar a[aria-current="page"] .nav-lights i:nth-child(1) { background: var(--go); opacity: 1; }
.tabbar a[aria-current="page"] .nav-lights i:nth-child(2) { background: var(--wait); opacity: 1; }
.tabbar a[aria-current="page"] .nav-lights i:nth-child(3) { background: var(--stop); opacity: 1; }
.tabbar b {
  position: absolute; top: 5px; left: calc(50% + 10px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--stop); color: #fff; font-size: .68rem; line-height: 18px; text-align: center;
}

/* ---------- chat */
.chat-view { display: flex; flex-direction: column; padding-bottom: 0; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; white-space: normal; overflow-wrap: anywhere; }
.msg p { margin: 0 0 .5em; } .msg p:last-child { margin: 0; }
.msg ul, .msg ol { margin: .2em 0 .5em; padding-left: 1.2em; }
.msg.assistant { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; align-self: flex-start; }
.msg.user { background: var(--bubble-me); color: var(--bubble-me-ink); border-bottom-right-radius: 6px; align-self: flex-end; }
.msg .att { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; opacity: .9; margin-bottom: 6px; }
.msg .att a { color: inherit; }
.file-btn {
  display: inline-flex; gap: 8px; align-items: center; margin-top: 8px; padding: 9px 14px;
  border-radius: 999px; background: var(--brand); color: var(--brand-ink); text-decoration: none; font-weight: 700; font-size: .9rem;
}
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }
.empty-chat { margin: auto 0; color: var(--muted); }
.empty-chat h2 { color: var(--ink); font-size: 1.3rem; margin: 0 0 8px; letter-spacing: -.01em; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.suggest button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 12px;
  font-size: .88rem; cursor: pointer; text-align: left;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 6px 4px 12px; font-size: .82rem; margin-bottom: 6px;
}
.chips button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; }
.composer {
  display: flex; align-items: flex-end; gap: 2px; padding: 6px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 26px;
}
.composer textarea {
  border: 0; background: transparent; resize: none; padding: 10px 6px; max-height: 140px; line-height: 1.35;
}
.composer textarea:focus { outline: none; }
.composer .send { background: var(--brand); color: var(--brand-ink); }
.composer .mic.listening { background: var(--stop); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(217,58,58,.45) } 70% { box-shadow: 0 0 0 12px rgba(217,58,58,0) } 100% { box-shadow: 0 0 0 0 rgba(217,58,58,0) } }

/* ---------- panel semáforo (pieza protagonista) */
.signal {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  background: var(--ink); color: #fff; border-radius: 26px; padding: 16px;
  margin-top: 6px;
}
@media (prefers-color-scheme: dark) { .signal { background: #070C16; } }
.lamp { display: grid; justify-items: center; gap: 6px; text-align: center; }
.lamp .bulb {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  font-size: 1.6rem; font-weight: 800; background: #26324A; color: #7D8AA3;
}
.lamp.on .bulb { color: #fff; }
.lamp.go.on .bulb { background: var(--go); box-shadow: 0 0 24px rgba(30,158,90,.55); }
.lamp.wait.on .bulb { background: var(--wait); color: #2A1E00; box-shadow: 0 0 24px rgba(224,161,6,.55); }
.lamp.stop.on .bulb { background: var(--stop); box-shadow: 0 0 24px rgba(217,58,58,.6); }
.lamp span { font-size: .8rem; color: #B9C4D6; }
.legend { font-size: .82rem; color: var(--muted); text-align: center; margin: 10px 0 18px; }

.group h2 { font-size: 1rem; margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }
.group h2 .dot { width: 10px; height: 10px; border-radius: 50%; }
.item {
  display: grid; grid-template-columns: 58px 1fr; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 12px; margin-bottom: 8px;
}
.pod {
  width: 58px; border-radius: 14px; padding: 6px 0; display: grid; justify-items: center; gap: 1px;
  color: #fff; line-height: 1;
}
.pod strong { font-size: 1.5rem; font-weight: 800; }
.pod small { font-size: .68rem; opacity: .9; }
.item.verde .pod { background: var(--go); }
.item.amarillo .pod { background: var(--wait); color: #2A1E00; }
.item.rojo .pod { background: var(--stop); }
.item.vencido .pod { background: var(--late); }
.item.sin_fecha .pod, .item.lejano .pod { background: var(--off); color: var(--ink); }
.item h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.item .meta { font-size: .85rem; color: var(--muted); }
.item .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.item .amount { font-weight: 800; white-space: nowrap; }
.item .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.item .actions button {
  border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 12px;
  font-size: .82rem; font-weight: 600; cursor: pointer;
}
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- cuentas */
.seg { display: grid; grid-auto-flow: column; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-top: 6px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 9px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.seg.small { margin-top: 8px; background: transparent; border: 0; padding: 0; justify-content: start; }
.seg.small button { padding: 6px 12px; font-size: .85rem; border: 1px solid var(--line); background: var(--surface); }
.seg.small button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.acc-total { margin: 16px 0 10px; }
.acc-total strong { display: block; font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.acc-total span { color: var(--muted); font-size: .9rem; }
.bar { height: 6px; background: var(--paper); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--go); }

/* ---------- negocios */
.period { margin: 6px 0 12px; }
.period label, .report-grid label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.biz {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 10px;
}
.biz header { display: flex; justify-content: space-between; align-items: baseline; }
.biz h3 { margin: 0; font-size: 1.05rem; }
.biz .tag { font-size: .75rem; color: var(--muted); }
.biz .profit { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 10px; }
.biz .profit.neg { color: var(--stop); }
.biz dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.biz dt { font-size: .75rem; color: var(--muted); }
.biz dd { margin: 0; font-weight: 700; font-size: .92rem; }
.report-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; margin-top: 18px; }
.report-box h2 { margin: 0 0 12px; font-size: 1.05rem; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.report-grid .full { grid-column: 1 / -1; }

/* ---------- ajustes */
.panel-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px; margin: 6px 0 14px; display: grid; gap: 12px;
}
.panel-box h2 { margin: 0; font-size: 1.05rem; }
.panel-box label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.panel-box .report-grid { margin: 0; }
.panel-box .btn { justify-self: start; }
.hint { margin: -4px 0 0; font-size: .82rem; color: var(--muted); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn:not(.primary):not(.danger) { background: var(--paper); border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--stop); color: #fff; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 12px; }
.danger-zone summary { cursor: pointer; color: var(--stop); font-weight: 700; }
.danger-zone form { display: grid; gap: 12px; margin-top: 12px; }
.topbar a.icon-btn[aria-current="page"] { color: var(--brand); background: var(--surface); }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- escritorio */
@media (min-width: 900px) {
  .app { grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .tabbar {
    grid-row: 2; grid-column: 1; grid-template-columns: 1fr; align-content: start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); padding: 12px;
  }
  .tabbar a { grid-template-columns: 26px 1fr; justify-items: start; align-items: center; font-size: .95rem; padding: 10px 12px; border-radius: 12px; }
  .tabbar a[aria-current="page"] { background: var(--paper); }
  .tabbar b { position: static; justify-self: end; grid-column: 3; }
  main { grid-row: 2; grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
