@import url("https://fonts.googleapis.com/css2?family=Archivo:wdth,wght@75..100,400..800&family=IBM+Plex+Mono:wght@400;500&display=swap");
:root{color-scheme:light;box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}html{scroll-padding-top:env(safe-area-inset-top,0px)}body{margin:0;padding:0;font:14px -apple-system,BlinkMacSystemFont,sans-serif;background:#fff;color:#000}img{max-width:100%}[hidden]:not([hidden=until-found i]){display:none!important}
/* Layout: una sola hoja angosta, como un formulario de aduana. Pestañas fijas arriba, casilleros con etiqueta chica y filas densas con cifras alineadas. */
:root {
  --bg: #F1F4F8; --surface: #FFFFFF; --surface-2: #E8EDF4; --line: #CFD8E3; --line-soft: #E3E9F0;
  --fg: #10223A; --fg-2: #3D4F66; --muted: #5A6A7F;
  --accent: #1C5CAB; --accent-fg: #FFFFFF; --accent-soft: #DCE8F7;
  --series: #2A78D6; --series-dim: #86B6EF; --track: #E3EBF5;
  --bad: #B42318; --bad-bg: #FBE7E4;
  --sombra: 0 6px 20px rgba(16, 34, 58, .14);
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C131C; --surface: #141D29; --surface-2: #1C2838; --line: #2B3A4E; --line-soft: #202D3D;
    --fg: #E7EDF5; --fg-2: #B7C4D4; --muted: #8E9DB1;
    --accent: #6DA7EC; --accent-fg: #071A30; --accent-soft: #18304D;
    --series: #3987E5; --series-dim: #1C5CAB; --track: #1E2B3C;
    --bad: #F2857A; --bad-bg: #3A1915;
    --sombra: 0 6px 20px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C131C; --surface: #141D29; --surface-2: #1C2838; --line: #2B3A4E; --line-soft: #202D3D;
  --fg: #E7EDF5; --fg-2: #B7C4D4; --muted: #8E9DB1;
  --accent: #6DA7EC; --accent-fg: #071A30; --accent-soft: #18304D;
  --series: #3987E5; --series-dim: #1C5CAB; --track: #1E2B3C;
  --bad: #F2857A; --bad-bg: #3A1915;
  --sombra: 0 6px 20px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box }
body { background: var(--bg); color: var(--fg); font: 400 15px/1.45 var(--font); font-stretch: 96%; -webkit-text-size-adjust: 100%; text-size-adjust: 100% }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg) }
button, input, select, textarea { font: inherit; color: inherit }
button { cursor: pointer; -webkit-tap-highlight-color: transparent }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap }
.app { max-width: 780px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 14px 32px; display: flex; flex-direction: column; gap: 10px }

.cab { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap }
.cab h1 { margin: 0; font-size: 19px; font-weight: 800; font-stretch: 82%; letter-spacing: .025em; text-transform: uppercase; line-height: 1.1; text-wrap: balance }
.cab .al { margin: 0; font: 500 12px/1.3 var(--mono); color: var(--muted) }

.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--bg); border-bottom: 1px solid var(--line) }
.tabs button { border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; padding: 11px 4px 9px; min-height: 44px; font-weight: 650; font-stretch: 88%; color: var(--muted) }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent) }

main { display: flex; flex-direction: column; min-width: 0 }
.hoja { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-width: 0 }
.sec { padding: 14px; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 10px; min-width: 0 }
.hoja > .sec:first-child { border-top: 0 }
.grupo { display: flex; flex-direction: column; min-width: 0 }
.tit { margin: 0; font-size: 17px; font-weight: 700; font-stretch: 90%; line-height: 1.25; text-wrap: balance; overflow-wrap: anywhere }
.tit.gran { font-size: 21px; font-weight: 750; font-stretch: 86%; line-height: 1.15 }
.nota { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4 }
.rot { margin: 0; font-size: 11px; font-weight: 700; font-stretch: 88%; letter-spacing: .07em; text-transform: uppercase; color: var(--muted) }
.cod { font: 500 12.5px/1.4 var(--mono); color: var(--fg-2) }

.buscador { position: relative; display: flex }
.buscador input { width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 42px; font-size: 16px; -webkit-appearance: none; appearance: none }
.buscador input::placeholder { color: var(--muted) }
.buscador input::-webkit-search-cancel-button { display: none }
.buscador svg { position: absolute; left: 12px; top: 13px; width: 20px; height: 20px; color: var(--muted); pointer-events: none }
.buscador .limpiar { position: absolute; right: 4px; top: 4px; width: 38px; height: 38px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 22px; line-height: 1 }
.filtros { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center }
.filtros label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--muted) }
select { height: 38px; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 0 8px; font-size: 15px; font-weight: 650; color: var(--fg) }

.lista { display: flex; flex-direction: column; min-width: 0 }
.cabeza { display: grid; grid-template-columns: var(--pos, 2.4em) minmax(0, 1fr) auto; column-gap: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line) }
.cabeza span:first-child { text-align: right }
.fila { display: grid; grid-template-columns: var(--pos, 2.4em) minmax(0, 1fr) auto; column-gap: 10px; row-gap: 1px; align-items: baseline; width: 100%; padding: 10px 0; border: 0; border-top: 1px solid var(--line-soft); background: none; text-align: left; color: var(--fg) }
.lista > .fila:first-child { border-top: 0 }
.fila .pos { grid-row: 1 / span 3; align-self: start; padding-top: 2px; font: 500 12.5px/1.5 var(--mono); color: var(--muted); text-align: right }
.fila .nom { grid-column: 2; font-weight: 650; font-stretch: 88%; line-height: 1.25; overflow-wrap: anywhere }
.fila .val { grid-column: 3; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right }
.fila .sub { grid-column: 2; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere }
.fila .der { grid-column: 3; font-size: 12.5px; color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums }
.fila .det { grid-column: 2 / -1; font-size: 12.5px; color: var(--fg-2); overflow-wrap: anywhere }
.fila.sinpos { grid-template-columns: minmax(0, 1fr) auto }
.fila.sinpos .nom, .fila.sinpos .sub { grid-column: 1 }
.fila.sinpos .val, .fila.sinpos .der { grid-column: 2 }
.fila.sinpos .det, .fila.sinpos .medidor { grid-column: 1 / -1 }
button.fila:hover .nom { color: var(--accent) }
.fila.propia .nom::after { content: "tu empresa"; margin-left: 8px; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; white-space: nowrap }
.fila.propia { margin: 0 -8px; width: calc(100% + 16px); padding-left: 8px; padding-right: 8px; border-radius: 8px; background: var(--accent-soft) }
.fila.propia + .fila { border-top-color: transparent }
.lista > .rot { padding: 14px 0 6px; border-top: 1px solid var(--line-soft) }
.lista > .rot:first-child { padding-top: 0; border-top: 0 }
.lista > .rot + .fila { border-top: 0 }
.nota.aviso { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); color: var(--fg-2) }
.fila .det.ten { color: var(--muted) }
.apodo { font-weight: 500; color: var(--fg-2) }
.fila.seguida .nom::before { content: "★"; margin-right: 6px; color: var(--accent); font-size: .85em }
.sello.sigue { background: var(--accent-soft); color: var(--accent) }
.sello.sigue::before { content: "★"; width: auto; height: auto; border-radius: 0; background: none; font-size: 11px; line-height: 1 }
.campo-txt { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 650; color: var(--muted) }
.campo-txt input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 12px; font-size: 16px; font-weight: 400; color: var(--fg) }
.campo-txt input::placeholder { color: var(--muted) }
.campo-txt input:disabled, .seg button:disabled { opacity: .55; cursor: default }
.notas .opc { justify-content: flex-start }
.notas a { color: var(--accent) }
details.rubro .cuerpo { display: flex; flex-direction: column; gap: 2px; padding: 4px 0 2px }
details.rubro .cuerpo > .rot { padding-top: 10px }
details.rubro .cuerpo > .nota { padding-top: 6px }
details.rubro .fila { padding: 6px 0 }
.medidor { grid-column: 2 / -1; height: 4px; margin: 5px 0 3px; border-radius: 2px; background: var(--track) }
.medidor i { display: block; height: 100%; min-width: 2px; border-radius: 2px; background: var(--series) }
.mas { align-self: center; height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--accent); font-weight: 700; font-stretch: 90% }

.volver { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 4px 8px 4px 0; border: 0; background: none; color: var(--accent); font-weight: 650 }
.linea-rut { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px }
.sellos { display: flex; flex-wrap: wrap; gap: 6px }
.sello { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 650; font-stretch: 90%; background: var(--surface-2); color: var(--fg-2) }
.sello::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor }
.sello.comp { background: var(--bad-bg); color: var(--bad) }
.sello.comp::before { border-radius: 1px; transform: rotate(45deg) }
.sello.prop { background: var(--accent-soft); color: var(--accent) }
.campos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--line-soft) }
.campo { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 9px 12px 10px; background: var(--surface) }
.campo.ancho { grid-column: 1 / -1 }
.campo b { font-size: 16px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere }
.campo b.gran { font-size: 28px; font-weight: 750; font-stretch: 90%; letter-spacing: -.01em; line-height: 1.1 }
.campo small { font-size: 12px; color: var(--muted); line-height: 1.35 }
@media (min-width: 620px) { .campos { grid-template-columns: repeat(4, minmax(0, 1fr)) } }

.graf { position: relative; min-width: 0 }
.graf svg { display: block; width: 100%; height: auto; overflow: visible }
.graf text { font-family: var(--font); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums }
.graf .grilla { stroke: var(--line-soft); stroke-width: 1 }
.graf .eje { stroke: var(--line); stroke-width: 1 }
.graf .col { fill: var(--series-dim) }
.graf .col.sel { fill: var(--series) }
.graf g.banda { cursor: pointer; outline-offset: -2px }
.graf g.banda .zona { fill: transparent }
.graf g.banda:hover .col, .graf g.banda:focus-visible .col { fill: var(--series) }
.graf text.valor { fill: var(--fg); font-size: 11.5px; font-weight: 700 }
.graf text.sel { fill: var(--fg); font-weight: 700 }
.tip { position: absolute; z-index: 3; pointer-events: none; transform: translate(-50%, -100%); padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--sombra); font-size: 12px; color: var(--muted); white-space: nowrap }
.tip b { display: block; font-size: 14px; color: var(--fg); font-variant-numeric: tabular-nums }
details.tabla summary { cursor: pointer; font-size: 13px; font-weight: 650; color: var(--accent); padding: 4px 0 }
.scroll { overflow-x: auto; max-width: 100% }
table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums }
th, td { padding: 5px 10px 5px 0; border-bottom: 1px solid var(--line-soft); text-align: left; white-space: nowrap }
th { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted) }
td.n, th.n { text-align: right; padding-right: 14px }

.btn { height: 46px; padding: 0 16px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: var(--accent-fg); font-weight: 700; font-stretch: 90% }
.btn.claro { background: var(--surface); color: var(--accent) }
.btn:disabled { opacity: .5; cursor: default }
.enlace { border: 0; background: none; padding: 6px 2px; color: var(--accent); font-size: 13px; font-weight: 650; text-decoration: underline; text-underline-offset: 3px }
.chips { display: flex; flex-wrap: wrap; gap: 8px }
.chip { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--fg); font-size: 13.5px; font-weight: 600; font-stretch: 90%; text-align: left }
.chip:hover { border-color: var(--accent); color: var(--accent) }

.chat { min-height: 62vh }
.msgs { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; padding: 14px }
.intro { display: flex; flex-direction: column; gap: 10px }
.msg { min-width: 0; max-width: 100%; overflow-wrap: anywhere }
.msg.yo { align-self: flex-end; max-width: 88%; padding: 8px 12px; border-radius: 14px 14px 4px 14px; background: var(--accent-soft); white-space: pre-wrap }
.msg.ia p { margin: 0 0 8px }
.msg.ia ul, .msg.ia ol { margin: 0 0 8px; padding-left: 20px }
.msg.ia li { margin: 3px 0 }
.msg.ia > .txt > :last-child { margin-bottom: 0 }
.msg.ia .h { font-weight: 700 }
.msg.ia code { padding: 0 4px; border-radius: 4px; background: var(--surface-2); font: 500 .92em var(--mono) }
.msg.ia .aviso { margin-top: 6px; font-size: 12.5px; color: var(--muted) }
.estado { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 12.5px; color: var(--muted) }
.estado::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--series); animation: pulso 1.1s ease-in-out infinite }
@keyframes pulso { 0%, 100% { opacity: .25 } 50% { opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .estado::before { animation: none } }
.composer { position: sticky; bottom: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 14px 12px; border-top: 1px solid var(--line-soft); border-radius: 0 0 12px 12px; background: var(--surface) }
.composer form { display: flex; align-items: flex-end; gap: 8px }
.composer textarea { flex: 1; min-width: 0; min-height: 46px; max-height: 132px; resize: none; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px; line-height: 1.35 }
.composer textarea::placeholder { color: var(--muted) }
.opc { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px }
.seg { display: inline-flex; overflow: hidden; border: 1px solid var(--line); border-radius: 8px }
.seg button { min-height: 32px; padding: 5px 11px; border: 0; background: var(--surface); color: var(--muted); font-size: 12.5px; font-weight: 650 }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent) }
.yo { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding-top: 10px; border-top: 1px solid var(--line-soft) }
.yo-elegida { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; min-width: 0 }
.yo-elegida b { font-size: 16px; font-weight: 700; font-stretch: 90%; line-height: 1.25; overflow-wrap: anywhere }
.yo-acc { display: inline-flex; flex-wrap: wrap; gap: 0 12px }
.yo-buscar { display: flex; flex-direction: column; gap: 6px; min-width: 0 }
.yo-buscar input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 12px; font-size: 16px; -webkit-appearance: none; appearance: none }
.yo-buscar input::placeholder { color: var(--muted) }
.yo-buscar input::-webkit-search-cancel-button { display: none }
.yo-lista { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--sombra) }
.yo-lista button { display: flex; flex-direction: column; gap: 1px; width: 100%; padding: 9px 12px; border: 0; border-top: 1px solid var(--line-soft); background: none; text-align: left; color: var(--fg) }
.yo-lista button:first-child { border-top: 0 }
.yo-lista button:hover, .yo-lista button:focus-visible { background: var(--accent-soft) }
.yo-lista .n { font-weight: 650; font-stretch: 88%; line-height: 1.25; overflow-wrap: anywhere }
.yo-lista .r { font: 500 12px/1.4 var(--mono); color: var(--muted) }
.yo-lista .nota { padding: 9px 12px; border-top: 1px solid var(--line-soft) }
.yo-lista .nota:first-child { border-top: 0 }
.prod { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 10px; row-gap: 1px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line-soft) }
.prod:first-child { border-top: 0 }
.prod input { grid-row: 1 / span 2; align-self: center; width: 18px; height: 18px; margin: 0; accent-color: var(--accent) }
.prod .nom { font-weight: 650; font-stretch: 88%; line-height: 1.25; overflow-wrap: anywhere; cursor: pointer }
.prod .val { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right }
.prod .sub { grid-column: 2 / -1; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere }
.prod.no .nom, .prod.no .val { color: var(--muted); text-decoration: line-through }
.pie { padding: 2px 2px 0 }

/* ----- Entrada, barra de sesión y piezas comunes (versión con servidor) ----- */
.tabs { grid-template-columns: repeat(2, minmax(0, 1fr)) }
.tabs.con-chat { grid-template-columns: repeat(3, minmax(0, 1fr)) }
.acceso { max-width: 440px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 24px 40px; display: flex; flex-direction: column; justify-content: center; gap: 14px }
.acceso .cab { justify-content: center; text-align: center }
.acceso .cab h1 { font-size: 21px }
.acceso form, .acceso .hoja > .sec { gap: 12px }
.acceso .btn { width: 100% }
.acceso .enlace { align-self: center }
.acceso .pie { display: flex; flex-direction: column; gap: 6px; text-align: center }
.nota.error { color: var(--bad) }
.sesion { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0 14px; margin: -6px 0 -8px; font-size: 12.5px; color: var(--muted) }
.sesion .quien { font-weight: 650; color: var(--fg-2); overflow-wrap: anywhere }
.en-linea { display: inline; margin: 0 }
a.enlace { display: inline-block }
.enlace-a { color: var(--accent); font-weight: 650; text-underline-offset: 3px; overflow-wrap: anywhere }
.boton-a { display: inline-flex; align-items: center; justify-content: center; text-decoration: none }
.fila-btn { display: flex; flex-wrap: wrap; align-items: center; gap: 8px }
.marca { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--fg-2) }
.marca input { width: 18px; height: 18px; flex: none; accent-color: var(--accent) }
.campo-txt select { width: 100%; height: 44px; border-radius: 10px; padding: 0 10px; font-size: 16px; font-weight: 400 }
.puntos { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--fg-2) }
