/* Monzai: marino, petróleo, esmeralda y blanco. Sin fuentes externas (CSP). */
:root {
  --marino: #0b1f33; --marino-2: #14304a; --petroleo: #0e5a6b; --petroleo-d: #0a4553; --esm: #0f9d75; --esm-t: #0b7d5c;
  --niebla: #f4f7f8; --blanco: #fff; --linea: #dbe4e8; --texto: #12263a; --suave: #566a7b; --aviso: #96590a; --error: #b0352c;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 10px; --side: 248px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--sans); color: var(--texto); background: var(--niebla); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--petroleo); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--esm); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--blanco); padding: .6rem 1rem; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.boot { padding: 3rem 1.5rem; color: var(--suave); }
.muted { color: var(--suave); } .small { font-size: .875rem; } .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.serif { font-family: var(--serif); } .right { text-align: right; } .hide { display: none !important; }
.ok-t { color: var(--esm-t); } .warn-t { color: var(--aviso); } .err-t { color: var(--error); }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- botones y campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: 0 1.1rem; border-radius: 9px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none; background: var(--blanco); color: var(--texto); border-color: var(--linea); white-space: nowrap; }
.btn:hover { border-color: #b9c8cf; }
.btn.primary { background: var(--petroleo); color: #fff; border-color: var(--petroleo); } .btn.primary:hover { background: var(--petroleo-d); }
.btn.accent { background: var(--esm-t); color: #fff; border-color: var(--esm-t); }
.btn.danger { background: var(--error); color: #fff; border-color: var(--error); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--petroleo); }
.btn.sm { min-height: 36px; padding: 0 .8rem; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.fld { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; min-width: 0; }
.fld > span { font-size: .875rem; font-weight: 600; color: var(--texto); }
.fld small { color: var(--suave); }
input, select, textarea { width: 100%; min-height: 44px; padding: .55rem .75rem; border: 1px solid #b9c8cf; border-radius: 8px; background: var(--blanco); }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--petroleo); flex: none; }
input[type=color] { padding: 3px; width: 64px; }
input:invalid:not(:placeholder-shown):not(:focus) { border-color: var(--error); }
.form-error { color: var(--error); font-weight: 600; min-height: 1.5em; margin: .25rem 0 .5rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; margin: .5rem 0 1rem; font-size: .95rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.chip-opt { position: relative; }
.chip-opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.chip-opt span { display: inline-block; padding: .45rem .9rem; border: 1px solid #b9c8cf; border-radius: 999px; background: var(--blanco); font-size: .95rem; }
.chip-opt input:checked + span { background: var(--petroleo); color: #fff; border-color: var(--petroleo); }
.chip-opt input:focus-visible + span { outline: 3px solid var(--esm); outline-offset: 2px; }

/* ---------- autenticación ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 5fr) 6fr; }
.auth-brand { background: var(--marino); color: #e8f0f4; padding: 3rem clamp(1.5rem, 5vw, 4.5rem); display: flex; flex-direction: column; justify-content: space-between; gap: 2rem; }
.wordmark { display: inline-flex; align-items: center; gap: .6rem; font-family: var(--serif); font-size: 1.5rem; font-weight: 600; letter-spacing: .06em; color: #fff; }
.wordmark svg { width: 34px; height: 34px; }
.auth-brand h1 { color: #fff; font-size: clamp(1.9rem, 3.4vw, 2.7rem); max-width: 15ch; }
.auth-brand p { color: #b4c6d2; max-width: 38ch; }
.auth-brand ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .8rem; }
.auth-brand li { padding-left: 1.4rem; position: relative; color: #d6e3ea; }
.auth-brand li::before { content: ""; position: absolute; left: 0; top: .6em; width: .6rem; height: .6rem; border-radius: 50%; background: var(--esm); }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; background: var(--blanco); }
.auth-card { width: 100%; max-width: 420px; }
.tabs { display: flex; gap: 1.5rem; border-bottom: 1px solid var(--linea); margin-bottom: 1.5rem; }
.tab { background: none; border: 0; padding: .7rem 0; font-weight: 600; color: var(--suave); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab[aria-selected=true] { color: var(--petroleo); border-color: var(--esm); }
.beta-note { font-size: .85rem; color: var(--aviso); background: #fdf3e1; border-radius: 8px; padding: .6rem .8rem; margin-top: 1.25rem; }

/* ---------- estructura ---------- */
.shell { min-height: 100vh; }
.side { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--marino); color: #c7d6df; display: flex; flex-direction: column; padding: 1.25rem .85rem; overflow-y: auto; }
.side .wordmark { padding: 0 .5rem .5rem; }
.co-switch { margin: .75rem 0 1rem; }
.co-switch select { background: var(--marino-2); color: #fff; border-color: #2a4a66; min-height: 40px; font-size: .95rem; }
.nav { display: grid; gap: 2px; }
.nav a, .nav button { display: flex; align-items: center; gap: .75rem; padding: .62rem .75rem; border-radius: 8px; color: #c7d6df; text-decoration: none; background: none; border: 0; cursor: pointer; text-align: left; width: 100%; }
.nav a:hover, .nav button:hover { background: var(--marino-2); color: #fff; }
.nav a[aria-current=page] { background: var(--petroleo); color: #fff; }
.side-foot { margin-top: auto; padding-top: 1rem; font-size: .8rem; color: #8fa6b5; display: grid; gap: .5rem; }
.side-foot .user { overflow-wrap: anywhere; }
.main { margin-left: var(--side); padding: 2rem clamp(1rem, 3.5vw, 3rem) 4rem; max-width: calc(1180px + var(--side)); }
.main:focus { outline: none; }
.top { display: none; }
.tabbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head .sub { color: var(--suave); margin: .25rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.loading { color: var(--suave); padding: 2rem 0; }
.banner { background: #fdf3e1; color: #6b4107; border-radius: 8px; padding: .65rem .9rem; font-size: .9rem; margin-bottom: 1.25rem; }
.banner.info { background: #e3f1f4; color: #0a4553; }
.empty { text-align: center; padding: 3rem 1rem; border: 1px dashed #b9c8cf; border-radius: var(--r); background: var(--blanco); }
.empty h2 { margin-bottom: .4rem; } .empty p { color: var(--suave); max-width: 46ch; margin: 0 auto 1.25rem; }

/* ---------- tablas ---------- */
.tbl-wrap { background: var(--blanco); border: 1px solid var(--linea); border-radius: var(--r); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--suave); padding: .7rem 1rem; border-bottom: 1px solid var(--linea); white-space: nowrap; background: #fafcfc; }
td { padding: .8rem 1rem; border-bottom: 1px solid #eaf0f2; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover td { background: #f6fafb; }
td a.row-link { color: inherit; text-decoration: none; font-weight: 600; } td a.row-link:hover { color: var(--petroleo); text-decoration: underline; }
th.num { text-align: right; }
.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 320px; } .toolbar select { width: auto; min-width: 150px; }
.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .15rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e8eef1; color: #33495a; white-space: nowrap; }
.pill::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.pill.green { background: #dcf3ea; color: #0a6d50; } .pill.blue { background: #dcecf1; color: #0a4553; }
.pill.amber { background: #fbecd0; color: #7a4707; } .pill.red { background: #f8dedb; color: #8f2820; } .pill.grey { background: #e8eef1; color: #4a5f70; }
progress { width: 100%; max-width: 140px; height: 8px; accent-color: var(--esm); }

/* ---------- resumen ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 2rem; align-items: end; padding-bottom: 1.75rem; border-bottom: 1px solid var(--linea); margin-bottom: 1.75rem; }
.big { font-family: var(--serif); font-size: clamp(2.6rem, 6vw, 4rem); font-weight: 600; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big.neg { color: var(--error); } .big.pos { color: var(--petroleo); }
.hero .lbl { color: var(--suave); margin-bottom: .5rem; }
.hero-side { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 2rem; }
.stat .k { font-size: .85rem; color: var(--suave); } .stat .v { font-family: var(--serif); font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat .d { font-size: .85rem; color: var(--suave); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.stats .stat { border-left: 3px solid var(--esm); padding-left: .9rem; } .stats .stat.warn { border-color: #d98a1d; }
.cols { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 2rem; }
.panel { background: var(--blanco); border: 1px solid var(--linea); border-radius: var(--r); padding: 1.25rem; }
.panel h2 { margin-bottom: .9rem; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 13px var(--sans); fill: var(--suave); } .chart .gl { stroke: #e3eaed; stroke-width: 1; }
.chart .inc { fill: var(--esm); } .chart .exp { fill: var(--marino-2); }
.legend { display: flex; gap: 1.25rem; font-size: .85rem; color: var(--suave); margin-top: .5rem; }
.legend i { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .4rem; vertical-align: -1px; }
.legend .i1 { background: var(--esm); } .legend .i2 { background: var(--marino-2); }
.tips { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.tips li { padding-left: 1.1rem; position: relative; font-size: .95rem; }
.tips li::before { content: ""; position: absolute; left: 0; top: .55em; width: .55rem; height: .55rem; border-radius: 50%; background: var(--petroleo); }
.tips li.warn::before { background: #d98a1d; }
.qstat { display: grid; gap: .5rem; }
.qstat div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid #eaf0f2; padding-bottom: .4rem; }

/* ---------- editor de documentos ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 2rem; align-items: start; }
.sec { background: var(--blanco); border: 1px solid var(--linea); border-radius: var(--r); padding: 1.25rem; margin-bottom: 1.25rem; }
.sec > h2 { margin-bottom: 1rem; }
.assist { display: grid; gap: .6rem; }
.assist-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.mic[aria-pressed=true] { background: var(--error); color: #fff; border-color: var(--error); }
.lines { display: grid; gap: .6rem; }
.line { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem .6rem; align-items: end; border: 1px solid var(--linea); border-radius: 10px; padding: .75rem; background: #fafcfc; position: relative; }
.line .c-name { grid-column: 1 / 5; grid-row: 1; } .line .c-amt { grid-column: 5; grid-row: 1; align-self: center; padding-right: 2.4rem; }
.line .c-del { position: absolute; top: .45rem; right: .45rem; }
.line input, .line select { min-height: 40px; padding: .4rem .55rem; }
.line input.bad { border-color: var(--error); background: #fdf1f0; }
.line .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.05rem; }
.line .lab { display: block; font-size: .75rem; color: var(--suave); margin-bottom: .15rem; }
.icon-btn { width: 38px; height: 38px; min-height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid transparent; background: none; cursor: pointer; color: var(--suave); }
.icon-btn:hover { background: #f3e3e1; color: var(--error); }
.add-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.add-row select { width: auto; min-width: 220px; flex: 1; max-width: 420px; }
.summary { position: sticky; top: 1rem; background: var(--marino); color: #dbe7ee; border-radius: 14px; padding: 1.5rem; }
.summary .tot-l { font-size: .9rem; color: #9fb6c5; }
.summary .tot { font-family: var(--serif); font-size: 2.6rem; font-weight: 600; color: #fff; line-height: 1.1; font-variant-numeric: tabular-nums; margin-bottom: 1rem; }
.summary dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; font-size: .95rem; }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; color: #fff; } .summary dt { color: #b4c6d2; }
.summary hr { border: 0; border-top: 1px solid #2a4a66; margin: 1rem 0; }
.margin { margin-top: .25rem; }
.margin .m-top { display: flex; justify-content: space-between; align-items: baseline; }
.margin .m-val { font-family: var(--serif); font-size: 1.9rem; color: #fff; }
.gauge { display: block; width: 100%; height: 12px; margin: .5rem 0; }
.gauge .bg { fill: #1d3e5a; } .gauge .fg { fill: var(--esm); } .gauge.low .fg { fill: #e0a03a; } .gauge.bad .fg { fill: #e5655a; }
.m-note { font-size: .85rem; color: #b4c6d2; }
.summary .btn { width: 100%; margin-top: .6rem; }
.summary .btn.primary { background: var(--esm); border-color: var(--esm); color: #04241b; } .summary .btn.primary:hover { background: #12b185; }
.summary .btn:not(.primary) { background: transparent; color: #e8f0f4; border-color: #3a5b77; }
.stepper { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---------- empresa / admin ---------- */
.logo-row { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.logo-box { width: 140px; height: 76px; border: 1px dashed #b9c8cf; border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: #fafcfc; color: var(--suave); font-size: .8rem; text-align: center; }
.logo-box img { max-width: 100%; max-height: 100%; }
.swatch { display: inline-block; width: 20px; height: 20px; border-radius: 5px; vertical-align: middle; border: 1px solid var(--linea); }
.danger-zone { border-color: #e9c5c1; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; }

/* ---------- diálogos y avisos ---------- */
dialog.dlg { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); box-shadow: 0 20px 60px rgba(7, 20, 34, .35); color: var(--texto); }
dialog.dlg.wide { width: min(720px, calc(100vw - 2rem)); }
dialog.dlg::backdrop { background: rgba(7, 20, 34, .55); }
.dlg-body { padding: 1.5rem; } .dlg-body > h2 { margin-bottom: 1rem; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; flex-wrap: wrap; }
.dlg-actions .left { margin-right: auto; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 200; max-width: min(380px, calc(100vw - 2rem)); }
.toast { background: var(--marino); color: #fff; padding: .75rem 1rem; border-radius: 10px; box-shadow: 0 8px 24px rgba(7, 20, 34, .3); border-left: 4px solid var(--esm); }
.toast.err { border-color: #e5655a; }
.more-list { display: grid; gap: .25rem; } .more-list a { display: flex; gap: .75rem; align-items: center; padding: .8rem; border-radius: 8px; text-decoration: none; color: var(--texto); } .more-list a:hover { background: var(--niebla); }

/* ---------- tablet y móvil ---------- */
@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; } .summary { position: static; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .side { display: none; }
  .main { margin-left: 0; padding: 1rem 1rem 6.5rem; }
  .top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; background: var(--marino); color: #fff; padding: .7rem 1rem; position: sticky; top: 0; z-index: 20; }
  .top .wordmark { font-size: 1.15rem; } .top .wordmark svg { width: 26px; height: 26px; } .top select { width: auto; max-width: 52vw; min-height: 36px; background: var(--marino-2); color: #fff; border-color: #2a4a66; padding: .2rem .5rem; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--blanco); border-top: 1px solid var(--linea); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .55rem .2rem; font-size: .72rem; color: var(--suave); text-decoration: none; background: none; border: 0; cursor: pointer; min-height: 56px; }
  .tabbar [aria-current=page] { color: var(--petroleo); font-weight: 700; }
  .auth { grid-template-columns: 1fr; } .auth-brand { padding: 1.75rem 1.25rem; } .auth-brand ul, .auth-brand p.lead { display: none; } .auth-brand h1 { font-size: 1.6rem; }
  h1 { font-size: 1.45rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .hero-side { grid-template-columns: 1fr 1fr; }
  .line { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .line .c-name { grid-column: 1 / -1; padding-right: 2.6rem; } .line .c-amt { grid-column: 3; grid-row: 3; padding-right: 0; }
  #toasts { bottom: 4.5rem; }
  /* tablas en lista de tarjetas */
  .stack thead { display: none; } .stack, .stack tbody, .stack tr, .stack td { display: block; width: 100%; }
  .stack tr { padding: .75rem 1rem; border-bottom: 1px solid #eaf0f2; } .stack tr:last-child { border-bottom: 0; }
  .stack td { border: 0; padding: .1rem 0; text-align: left !important; }
  .stack td[data-l]::before { content: attr(data-l) ": "; color: var(--suave); font-size: .8rem; }
  .stack td.t { font-weight: 600; font-size: 1.02rem; }
}
@media (max-width: 480px) { .stats { grid-template-columns: 1fr 1fr; gap: 1rem; } .stat .v { font-size: 1.2rem; } .page-head .actions { width: 100%; } .page-head .actions .btn { flex: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print { .side, .top, .tabbar, .actions { display: none !important; } .main { margin: 0; } }
.actions select { width: auto; min-width: 90px; }
fieldset.fld { border: 0; padding: 0; margin: 0 0 .9rem; min-width: 0; } fieldset.fld legend { padding: 0; margin-bottom: .5rem; }
.actions .fld { margin: 0; }
.main.legal { margin: 0 auto; max-width: 760px; padding-bottom: 3rem; } .legal h2 { margin: 1.5rem 0 .5rem; } .legal li { margin-bottom: .4rem; }

.editor > div { min-width: 0; } .line > div { min-width: 0; }
@media (max-width: 860px) { .add-row select { min-width: 0; width: 100%; max-width: none; } .add-row .btn { width: 100%; } }

.side-foot .btn.ghost { color: #9fd3e0; } .side-foot .btn.ghost:hover { color: #fff; border-color: #2a4a66; }
.panel + .panel, .cols > div > .panel + .panel { margin-top: 1.25rem; }

/* Escaneo de facturas */
.scan-pick { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }
.scan-warn { margin: 0 0 1rem; padding: .75rem 1rem .75rem 1.75rem; border-radius: 10px; background: #fff4de; color: #6b4600; font-size: .9rem; }
.scan-warn li + li { margin-top: .3rem; }
