:root {
  --brand: #1d6b3a; --brand-2: #2f8a50; --brand-soft: #e6f2ea;
  --bg: #f4f6f5; --surface: #ffffff; --line: #dfe4e1; --line-2: #eef1ef;
  --ink: #1b2420; --ink-2: #4c5a53; --ink-3: #7b8781;
  --bar: #2f8a50; --bar-hover: #1d6b3a;
  --ok: #1e7b3c; --warn: #a86a00; --bad: #b3261e; --info: #1f5fa8;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0 0 8px; color: var(--ink-2); }
.muted { color: var(--ink-3); } .small { font-size: 12px; } .right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: #14301f; color: #d5e4da; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; color: #fff; font-size: 15px; letter-spacing: .3px; }
.brand span { font-size: 12px; color: #9fb8a8; }
.nav { padding: 8px; flex: 1; }
.nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #7f9c8a; margin: 14px 8px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #d5e4da; text-decoration: none; padding: 8px 10px; border-radius: 6px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.on { background: var(--brand-2); color: #fff; }
.nav .badge { margin-left: auto; background: #f2b134; color: #2a1d00; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.who { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.who b { color: #fff; display: block; }
.who button { margin-top: 8px; width: 100%; }
.main { padding: 22px 26px 60px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.menu-btn { display: none; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.grid > * { min-width: 0; }
.card:has(> table.t) { overflow-x: auto; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); } .g6 { grid-template-columns: repeat(6, minmax(0,1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #c9d1cc; border-radius: 6px; background: #fff; color: var(--ink); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,138,80,.35); border-color: var(--brand-2); }
input[readonly], input:disabled, select:disabled { background: #f3f5f4; color: var(--ink-2); }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; min-height: 60px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
button, .btn { font: inherit; border: 1px solid #c9d1cc; background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: #f1f4f2; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .primary:hover { background: #17582f; }
.danger { color: var(--bad); border-color: #e3b7b3; } .danger:hover { background: #fdf0ef; }
.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.ghost { border-color: transparent; background: transparent; } .ghost:hover { background: rgba(0,0,0,.05); }
.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.toolbar label.f { min-width: 130px; }

table.t { width: 100%; border-collapse: collapse; background: #fff; }
table.t th { text-align: left; font-size: 12px; color: var(--ink-2); font-weight: 600; background: #f6f8f7; border-bottom: 1px solid var(--line); padding: 8px 10px; position: sticky; top: 0; }
table.t td { border-bottom: 1px solid var(--line-2); padding: 7px 10px; vertical-align: middle; }
table.t tr:hover td { background: #fafcfb; }
table.t tr.click { cursor: pointer; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; border: 1px solid transparent; }
.st-BORRADOR { background: #eef0ef; color: #4c5a53; }
.st-PENDIENTE_AREA { background: #fff4d6; color: #7a5200; border-color: #f1dc9e; }
.st-PENDIENTE_FINANZAS { background: #ffe9d6; color: #8a4300; border-color: #f3c9a3; }
.st-AUTORIZADA { background: #e2eefc; color: #1f5fa8; border-color: #bcd5f3; }
.st-PAGADA { background: #e3f3e8; color: #1e6b37; border-color: #b9dfc4; }
.st-COMPROBADA { background: #d3ecdc; color: #11512a; border-color: #9fd0b0; }
.st-RECHAZADA { background: #fde8e6; color: #a1231b; border-color: #f2bdb8; }
.st-CANCELADA { background: #eceeed; color: #6d7772; text-decoration: line-through; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* Charts */
.cols { display: flex; align-items: flex-end; gap: 6px; height: 200px; border-bottom: 1px solid #b9c2bd; position: relative; padding-top: 18px;
  background-image: linear-gradient(to top, var(--line-2) 1px, transparent 1px); background-size: 100% 25%; }
.cols .c { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; position: relative; cursor: default; }
.cols .c .b { width: 70%; max-width: 46px; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 0; transition: background .1s; }
.cols .c:hover .b { background: var(--bar-hover); }
.cols .c .vl { position: absolute; font-size: 11px; color: var(--ink-2); white-space: nowrap; transform: translateY(-16px); }
.colx { display: flex; gap: 6px; } .colx div { flex: 1; text-align: center; font-size: 11px; color: var(--ink-3); padding-top: 4px; }
.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; font-size: 12px; cursor: default; }
.hbar .lb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar .tr { background: var(--line-2); border-radius: 0 4px 4px 0; height: 14px; }
.hbar .fl { background: var(--bar); height: 100%; border-radius: 0 4px 4px 0; }
.hbar:hover .fl { background: var(--bar-hover); }
.hbar .vv { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.meter { background: var(--line-2); border-radius: 4px; height: 10px; overflow: hidden; min-width: 80px; }
.meter > div { height: 100%; background: var(--bar); }
.meter.over > div { background: var(--bad); }
#tip { position: fixed; pointer-events: none; background: #1b2420; color: #fff; padding: 6px 9px; border-radius: 6px; font-size: 12px; z-index: 1000; display: none; box-shadow: 0 4px 12px rgba(0,0,0,.2); max-width: 280px; }

/* Modal */
.ov { position: fixed; inset: 0; background: rgba(15,25,20,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 500; padding: 5vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal .mh { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal .mh h2 { margin: 0; }
.modal .mb { padding: 16px 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1b2420; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 380px; font-size: 13px; }
.toast.err { background: var(--bad); } .toast.ok { background: var(--ok); }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #14301f, #2f8a50); padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { color: var(--brand); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }

/* Partidas */
table.partidas td { padding: 4px; } table.partidas input { padding: 5px 7px; }
.total-box { display: flex; justify-content: flex-end; gap: 16px; align-items: baseline; padding: 10px 6px 0; font-size: 16px; }
.total-box b { font-size: 22px; font-variant-numeric: tabular-nums; }
.folio-prev { background: var(--brand-soft); border: 1px dashed var(--brand-2); border-radius: 6px; padding: 8px 12px; font-family: Consolas, monospace; font-size: 15px; color: var(--brand); }
.bankbox { background: #f6f8f7; border: 1px solid var(--line); border-radius: 6px; padding: 10px; }

/* Stepper */
.steps { display: flex; gap: 0; margin: 4px 0 6px; flex-wrap: wrap; }
.steps .s { flex: 1; min-width: 110px; text-align: center; font-size: 12px; color: var(--ink-3); position: relative; padding-top: 22px; }
.steps .s::before { content: ''; position: absolute; top: 7px; left: 50%; width: 14px; height: 14px; border-radius: 50%; background: #d4dbd7; transform: translateX(-50%); z-index: 1; }
.steps .s::after { content: ''; position: absolute; top: 13px; left: -50%; width: 100%; height: 2px; background: #d4dbd7; }
.steps .s:first-child::after { display: none; }
.steps .s.done { color: var(--ok); } .steps .s.done::before, .steps .s.done::after { background: var(--ok); }
.steps .s.cur { color: var(--ink); font-weight: 700; } .steps .s.cur::before { background: #f2b134; box-shadow: 0 0 0 4px #fff1cc; }
.steps .s.cur::after { background: var(--ok); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.alert.warn { background: #fff4d6; border: 1px solid #f1dc9e; color: #6a4700; }
.alert.err { background: #fde8e6; border: 1px solid #f2bdb8; color: #8e1f18; }
.alert.info { background: #e2eefc; border: 1px solid #bcd5f3; color: #1b4f8a; }

/* ---------- FORMATO IMPRESO ---------- */
.print-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.sheet { background: #fff; width: 216mm; min-height: 279mm; margin: 0 auto; padding: 10mm 11mm 8mm; box-shadow: 0 2px 14px rgba(0,0,0,.15); font-family: Calibri, Arial, sans-serif; color: #000; font-size: 9.5pt; position: relative; display: flex; flex-direction: column; }
.fmt-top { display: grid; grid-template-columns: 26mm 1fr; align-items: start; gap: 4mm; }
.fmt-logo { text-align: center; } .fmt-logo img { max-width: 24mm; max-height: 22mm; }
.fmt-logo .ph { width: 20mm; height: 18mm; margin: 0 auto; border: 1px solid #1d6b3a; color: #1d6b3a; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 8pt; text-align: center; }
.fmt-company { background: #d9d9d9; text-align: center; font-weight: 700; font-size: 13pt; padding: 1mm; }
.fmt-title { font-weight: 700; font-size: 9pt; margin: 2mm 0 0 4mm; }
.fmt-ctl { display: flex; justify-content: flex-end; margin-top: 2mm; }
.fmt-ctl table { border-collapse: collapse; width: 92mm; }
.fmt-ctl td { white-space: nowrap; }
#sheetwrap { overflow: hidden; }
#sheetwrap .sheet { transform-origin: top left; }
.fmt-ctl td { border: 1px solid #000; padding: .4mm 2mm; font-size: 9pt; }
.fmt-ctl td:first-child { text-align: right; font-style: italic; font-weight: 700; width: 32%; }
.fmt-ctl td:last-child { text-align: center; font-weight: 700; }
.fmt-box { border: 1.6px solid #000; padding: 1mm 2mm 4mm; flex: 1; display: flex; flex-direction: column; }
.fmt-tg { display: grid; grid-template-columns: 40mm 1fr; font-weight: 700; padding: .5mm 0; }
table.fx { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.fx td { border: 1px solid #000; padding: .5mm 1.5mm; height: 5mm; font-size: 9pt; overflow: hidden; }
table.fx td.lb { text-align: right; font-weight: 700; font-style: italic; }
table.fx td.c { text-align: center; }
.fmt-gap { height: 4mm; }
.fmt-rule { border-top: 2px solid #000; margin: 6mm 0 4mm; }
table.fp { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.fp th { border: 1px solid #000; font-style: italic; font-size: 10pt; padding: .5mm; }
table.fp td { border: 1px solid #000; padding: .4mm 1.5mm; height: 4.6mm; font-size: 9pt; }
.fmt-total { display: flex; justify-content: flex-end; gap: 10mm; margin: 6mm 0 6mm; font-weight: 700; font-size: 10pt; align-items: baseline; }
.fmt-total .amt { border-bottom: 1.5px solid #000; min-width: 40mm; display: flex; justify-content: space-between; padding: 0 1mm; }
.fmt-obs { font-weight: 700; margin-top: 2mm; }
.fmt-line { border-bottom: 1.3px solid #000; min-height: 7mm; padding: 1mm 0; font-size: 9pt; white-space: pre-wrap; }
.fmt-firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 8mm 24mm; padding: 6mm 26mm 0; margin-top: auto; }
.fmt-firma .tt { border: 1.3px solid #000; text-align: center; font-weight: 700; font-size: 9pt; padding: .5mm; }
.fmt-firma .nm { text-align: center; margin-top: 9mm; font-size: 9pt; min-height: 4mm; }
.fmt-firma .ln { border-top: 1.3px solid #000; text-align: center; font-weight: 700; font-size: 9pt; }
.fmt-foot { display: flex; justify-content: space-between; font-size: 7pt; font-family: Arial, sans-serif; margin-top: 8mm; }
.fmt-reimp { position: absolute; top: 4mm; right: 11mm; font-size: 7pt; color: #555; }
.fmt-water { position: absolute; top: 45%; left: 0; right: 0; text-align: center; font-size: 54pt; font-weight: 800; color: rgba(179,38,30,.13); transform: rotate(-24deg); pointer-events: none; }

@media print {
  @page { size: letter; margin: 0; }
  body { background: #fff; }
  .side, .print-bar, .head, #toasts, .no-print, .menu-btn { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  .sheet { box-shadow: none; margin: 0 !important; width: 216mm; height: 279mm; min-height: 0; overflow: hidden; transform: none !important; }
  #sheetwrap { height: auto !important; overflow: visible; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 250px; z-index: 300; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; margin-bottom: 10px; }
  .main { padding: 14px 16px 60px; }
  .g3, .g4, .g6 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .span3 { grid-column: span 2; }
  .sheet { transform-origin: top left; }
}
@media (max-width: 560px) {
  .g2, .g3, .g4, .g6 { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; }
  .kv { grid-template-columns: 1fr; }
}
