@font-face {
  font-family: "Mona Sans";
  src: url("mona-sans-variable.woff2") format("woff2");
  font-weight: 200 900;
  font-stretch: 75% 125%;
  font-display: swap;
}

:root {
  --navy: #0b2d6b;
  --navy-deep: #071f4d;
  --brand: #114fdb;
  --brand-hover: #0e44bf;
  --electric: #00aeef;
  --ice: #93c5fd;
  --canvas: #f6f8fc;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-muted: #5b6b82;
  --line: #e3e8f0;
  --tint: #e6eefd;
  --tint-line: #c9daf8;
  --on-navy: #e6eefd;
  --on-navy-muted: #c9d6f2;
  --on-navy-faint: #afc1e8;
  --positive: #0f7b53;
  --warning: #b45309;
  --warning-surface: #fef3e2;
  --side-w: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Mona Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input { font: inherit; color: inherit; }
button:not(:disabled) { cursor: pointer; }
:focus-visible { outline: 2px solid var(--electric); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
[hidden] { display: none !important; }

/* Estructura */
.side {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w);
  background: var(--navy); color: #fff;
  display: flex; flex-direction: column; padding: 28px 14px; z-index: 10;
}
.side-head { padding: 0 10px 26px; }
.side-company { font-size: 19px; font-weight: 650; font-stretch: 112%; letter-spacing: -0.01em; }
.side-note { font-size: 13px; color: var(--on-navy-faint); margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--on-navy-muted); text-decoration: none; font-size: 15px; font-weight: 500;
  position: relative;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav a.is-active { color: #fff; background: rgba(255,255,255,.1); }
.nav a.is-active::before {
  content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--electric);
}
.nav svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.nav-short { display: none; }

main { margin-left: var(--side-w); min-height: 100vh; padding: 40px 44px 56px; transition: background-color .3s; }
body[data-view="mando"] { background: var(--navy-deep); }
body[data-view="mando"] main { color: #fff; }

.view { display: none; max-width: 1180px; }
.view.is-active { display: block; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; flex-wrap: wrap; }
.view-head h1 { font-size: 30px; line-height: 36px; font-weight: 600; font-stretch: 112%; letter-spacing: -0.01em; }
.view-head p { color: var(--ink-muted); margin-top: 6px; max-width: 60ch; }
body[data-view="mando"] .view-head p { color: var(--on-navy-muted); }

.btn {
  border: 0; border-radius: 10px; background: var(--brand); color: #fff;
  padding: 12px 20px; font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--brand-hover); }
.btn:disabled { background: #9db3e6; }

/* 1. Centro de mando */
.live { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--on-navy) !important; margin: 0 !important; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--electric); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(0,174,239,.7); } 100% { box-shadow: 0 0 0 12px rgba(0,174,239,0); } }

.kpis { display: grid; grid-template-columns: 1.5fr 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.kpi, .panel {
  background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.12); border-radius: 16px;
}
.kpi { padding: 20px 22px; }
.kpi-main { background: var(--brand); border-color: transparent; }
.kpi-label { font-size: 14px; color: var(--on-navy-muted); }
.kpi-main .kpi-label, .kpi-main .kpi-foot { color: var(--on-navy); }
.kpi-value { font-size: 34px; line-height: 1.15; font-weight: 650; font-stretch: 112%; letter-spacing: -0.02em; margin: 6px 0 4px; }
.kpi-main .kpi-value { font-size: 46px; }
.kpi-foot { font-size: 13px; color: var(--on-navy-faint); }
.kpi-value.bump { animation: bump .5s ease-out; }
@keyframes bump { 0% { color: var(--ice); } 100% { color: inherit; } }

.mando-grid { display: grid; grid-template-columns: 1.5fr 1fr; grid-template-areas: "chart feed" "routes feed"; gap: 16px; }
.panel { padding: 20px 22px; min-width: 0; }
.panel h2 { font-size: 15px; font-weight: 600; color: var(--on-navy); margin-bottom: 12px; }
.panel-chart { grid-area: chart; }
.panel-routes { grid-area: routes; }
.panel-feed { grid-area: feed; }
#chart { display: block; width: 100%; height: 200px; }
.panel-routes svg { display: block; width: 100%; max-height: 260px; }
.route-lines path { fill: none; stroke: rgba(147,197,253,.35); stroke-width: 1.5; stroke-dasharray: 4 5; }
.route-trucks circle { fill: var(--electric); }
.route-nodes circle { fill: var(--navy-deep); stroke: var(--ice); stroke-width: 2; }
.route-nodes .hub { fill: #fff; stroke: var(--brand); stroke-width: 4; }
.route-labels text { fill: var(--on-navy-muted); font-size: 12px; font-family: inherit; }

#feed li {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: baseline;
  padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,.09); font-size: 14px;
  animation: feed-in .45s ease-out;
}
#feed li:last-child { border-bottom: 0; }
@keyframes feed-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
#feed .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ice); transform: translateY(-1px); }
#feed .is-pago .dot { background: #4ade80; }
#feed .is-alerta .dot { background: #fbbf24; }
#feed strong { display: block; font-weight: 600; color: #fff; }
#feed span.what { color: var(--on-navy-muted); }
#feed time { color: var(--on-navy-faint); font-size: 13px; white-space: nowrap; }

/* 2. Proceso */
.process-meter {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 20px;
}
.process-meter > div { padding: 18px 24px; border-left: 1px solid var(--line); }
.process-meter > div:first-child { border-left: 0; }
.meter-label { font-size: 14px; color: var(--ink-muted); }
.meter-value { font-size: 32px; font-weight: 650; font-stretch: 112%; letter-spacing: -0.02em; color: var(--navy); }
.meter-compare .meter-value { color: var(--ink-muted); }

.stages { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; counter-reset: st; }
.stage {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; min-height: 230px; opacity: .55; transition: opacity .3s, border-color .3s, box-shadow .3s, transform .3s;
}
.stage::before {
  counter-increment: st; content: counter(st);
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--tint); color: var(--navy); font-weight: 650; font-size: 14px; margin-bottom: 10px;
  transition: background-color .3s, color .3s;
}
.stage h2 { font-size: 15px; font-weight: 600; line-height: 1.3; }
.stage .took { font-size: 13px; color: var(--ink-muted); margin-top: 2px; }
.stage .detail { margin-top: 12px; font-size: 13.5px; line-height: 1.45; opacity: 0; transform: translateY(6px); transition: opacity .35s .15s, transform .35s .15s; }
.stage.is-active, .stage.is-done { opacity: 1; }
.stage.is-active { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(17,79,219,.14); transform: translateY(-4px); }
.stage.is-active::before { background: var(--brand); color: #fff; }
.stage.is-done::before { background: var(--positive); color: #fff; content: "✓"; }
.stage.is-active .detail, .stage.is-done .detail { opacity: 1; transform: none; }
.bubble { background: #e7f8ec; border-radius: 12px 12px 12px 3px; padding: 9px 11px; color: #14361f; }
.bubble.out { background: var(--tint); border-radius: 12px 12px 3px 12px; color: var(--navy); }
.detail b { font-weight: 600; }
.detail .ok { color: var(--positive); font-weight: 600; }
.process-done {
  margin-top: 20px; padding: 16px 20px; border-radius: 14px; background: var(--navy); color: #fff;
  font-size: 17px; font-weight: 500; animation: feed-in .4s ease-out;
}

/* 3. Asistente */
.chat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; max-width: 860px; }
.chat-log { padding: 24px; display: flex; flex-direction: column; gap: 16px; min-height: 300px; max-height: 56vh; overflow-y: auto; }
.msg { max-width: 88%; animation: feed-in .3s ease-out; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 16px 16px 4px 16px; }
.msg.bot { align-self: flex-start; background: var(--canvas); border: 1px solid var(--line); padding: 14px 18px; border-radius: 16px 16px 16px 4px; width: min(88%, 620px); }
.msg.bot .lead { font-size: 17px; }
.msg.bot .lead b { font-weight: 650; color: var(--navy); }
.typing { display: flex; gap: 5px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.viz { margin-top: 14px; display: grid; gap: 8px; }
.viz-row { display: grid; grid-template-columns: 120px 1fr 88px; gap: 10px; align-items: center; font-size: 14px; }
.viz-row .track { height: 14px; background: var(--tint); border-radius: 7px; overflow: hidden; }
.viz-row .fill { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 7px; transition: width .8s cubic-bezier(.2,.7,.2,1); }
.viz-row.warn .fill { background: var(--warning); }
.viz-row b { text-align: right; font-weight: 600; }
.cols { display: flex; align-items: flex-end; gap: 10px; height: 150px; margin-top: 16px; }
.cols div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; font-size: 13px; color: var(--ink-muted); }
.cols i { display: block; width: 100%; height: 0; background: var(--brand); border-radius: 6px 6px 0 0; transition: height .8s cubic-bezier(.2,.7,.2,1); }
.cols .top i { background: var(--electric); }
.msg-action { margin-top: 14px; }
.msg-action .btn { padding: 9px 16px; font-size: 14px; }
.msg-action .sent { color: var(--positive); font-weight: 600; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 24px 16px; }
.chips button {
  border: 1px solid var(--tint-line); background: var(--tint); color: var(--navy);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500;
}
.chips button:hover { background: #d8e5fc; }
.chat-form { display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.chat-form input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

/* 4. Documentos */
.doc-picker { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.doc-picker button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 18px;
  font-weight: 600; font-size: 15px; text-align: left;
}
.doc-picker button small { display: block; font-weight: 400; color: var(--ink-muted); font-size: 13px; }
.doc-picker button[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(17,79,219,.14); }
.doc-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.paper-wrap { position: relative; }
.paper {
  background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 30px 30px 34px; min-height: 470px;
  box-shadow: 0 18px 40px -22px rgba(11,45,107,.45); font-size: 13.5px; color: #1f2937;
}
.paper:empty::before { content: "Aquí aparece el documento."; color: var(--ink-muted); }
.paper .p-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #1f2937; padding-bottom: 12px; margin-bottom: 14px; }
.paper .p-issuer { font-weight: 700; font-size: 15px; }
.paper .p-type { font-weight: 700; font-size: 18px; text-align: right; font-stretch: 112%; }
.paper .p-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; margin-bottom: 16px; }
.paper .p-meta span { color: #6b7280; display: block; font-size: 12px; }
.paper table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.paper th { text-align: left; font-size: 12px; color: #6b7280; font-weight: 500; border-bottom: 1px solid #d1d5db; padding: 6px 4px; }
.paper td { padding: 7px 4px; border-bottom: 1px solid #eef0f3; }
.paper th.n, .paper td.n { text-align: right; }
.paper .p-totals { margin-left: auto; width: min(240px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; }
.paper .p-totals .t { font-weight: 700; font-size: 15px; }
.paper [data-k] { border-radius: 3px; transition: background-color .25s, box-shadow .25s; padding: 0 2px; margin: 0 -2px; }
.paper [data-k].hit { background: rgba(0,174,239,.2); box-shadow: 0 0 0 1.5px var(--electric); }
.scan {
  position: absolute; left: 0; right: 0; top: 0; height: 64px; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,174,239,0), rgba(0,174,239,.28));
  border-bottom: 2px solid var(--electric);
  animation: scan 1.3s ease-in-out forwards;
}
@keyframes scan { from { transform: translateY(-64px); } to { transform: translateY(var(--scan-to, 420px)); opacity: .2; } }

.extract { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.extract h2 { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.extract-empty { color: var(--ink-muted); }
#extract-list div { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); animation: feed-in .3s ease-out; }
#extract-list dt { color: var(--ink-muted); font-size: 14px; }
#extract-list dd { font-weight: 600; text-align: right; }
.extract-result { margin-top: 18px; padding: 14px 16px; border-radius: 12px; background: #e8f6f0; color: #0b5c3e; font-weight: 600; animation: feed-in .4s ease-out; }

/* 5. Ahorro */
.calc { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 24px; align-items: start; }
.calc-controls { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 26px; }
.field { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 18px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.field:last-child { border-bottom: 0; }
.field label { font-weight: 500; }
.field output { font-size: 22px; font-weight: 650; color: var(--navy); font-stretch: 112%; }
.field input { grid-column: 1 / -1; width: 100%; accent-color: var(--brand); height: 28px; margin: 0; }
.calc-result { background: var(--navy); color: #fff; border-radius: 20px; padding: 32px 34px; }
.result-label { color: var(--on-navy-muted); }
.result-money { font-size: clamp(44px, 6.4vw, 78px); line-height: 1.05; font-weight: 700; font-stretch: 112%; letter-spacing: -0.03em; margin: 6px 0 22px; }
.result-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 20px 0; border-top: 1px solid rgba(255,255,255,.14); border-bottom: 1px solid rgba(255,255,255,.14); }
.result-num { font-size: 34px; font-weight: 650; font-stretch: 112%; letter-spacing: -0.02em; }
.result-cap { font-size: 14px; color: var(--on-navy-muted); }
.bars { display: grid; gap: 12px; margin: 22px 0 18px; }
.bar-line { display: grid; grid-template-columns: 150px 1fr 76px; gap: 12px; align-items: center; font-size: 14px; color: var(--on-navy); }
.bar { height: 16px; background: rgba(255,255,255,.1); border-radius: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ice); border-radius: 8px; transition: width .35s ease-out; }
.bar i.after { background: var(--electric); }
.bar-line b { text-align: right; font-weight: 600; }
.result-note { font-size: 13px; color: var(--on-navy-faint); max-width: 62ch; }

/* Tableta y celular */
@media (max-width: 1100px) {
  .stages { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-main { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .side {
    inset: auto 0 0 0; width: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255,255,255,.12);
  }
  .side-head { display: none; }
  .nav { flex-direction: row; flex: 1; gap: 2px; }
  .nav a { flex: 1; flex-direction: column; gap: 3px; padding: 8px 2px; font-size: 11px; min-width: 0; }
  .nav a.is-active::before { display: none; }
  .nav-long { display: none; }
  .nav-short { display: block; }
  main { margin-left: 0; padding: 24px 16px 104px; }
  .view-head h1 { font-size: 25px; line-height: 30px; }
  .mando-grid { grid-template-columns: 1fr; grid-template-areas: "chart" "feed" "routes"; }
  .kpi-value { font-size: 28px; }
  .kpi-main .kpi-value { font-size: 40px; }
  .kpi { padding: 16px; }
  #chart { height: 150px; }
  .stages { grid-template-columns: 1fr; }
  .stage { min-height: 0; }
  .process-meter > div { padding: 14px; }
  .meter-value { font-size: 24px; }
  .meter-label { font-size: 12.5px; }
  .doc-grid, .calc { grid-template-columns: 1fr; }
  .paper { padding: 20px 18px; min-height: 0; font-size: 12.5px; }
  .chat-log { padding: 16px; max-height: none; min-height: 220px; }
  .chips { padding: 0 16px 14px; }
  .chat-form { padding: 12px 16px; }
  .msg, .msg.bot { max-width: 100%; width: 100%; }
  .msg.user { width: auto; }
  .viz-row { grid-template-columns: 92px 1fr 76px; font-size: 13px; }
  .calc-result { padding: 24px 20px; }
  .bar-line { grid-template-columns: 1fr 70px; }
  .bar-line span { grid-column: 1 / -1; }
  .view-head .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
