:root {
  --bg: #f3f4f1;
  --card: #ffffff;
  --ink: #17202a;
  --muted: #6b7380;
  --line: #e2e4df;
  --line2: #eef0ec;
  --brand: #12355b;
  --brand-2: #1d4f86;
  --accent: #d9a21b;
  --pos: #1f7a4d;
  --pos-bg: #e6f3ec;
  --neg: #b42318;
  --neg-bg: #fdecea;
  --warn-bg: #fff6e0;
  --warn: #8a5a00;
  --info-bg: #eaf1fb;
  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.mt { margin-top: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; }
.b { font-weight: 600; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg) !important; }

/* header */
.top {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px;
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20;
}
.brand { color: #fff; font-weight: 500; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand b { font-weight: 700; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(217,162,27,.25); }
.brand.big { color: var(--brand); font-size: 20px; }
.top nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.top nav a { color: #c9d6e6; padding: 8px 12px; border-radius: 6px; white-space: nowrap; }
.top nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.top nav a.on { color: #fff; background: rgba(255,255,255,.14); }
.top .user { color: #9fb3cc; font-size: 13px; white-space: nowrap; }
.top .user a { color: #fff; }

main { max-width: 1440px; margin: 0 auto; padding: 24px; }
main.center { min-height: 100vh; display: grid; place-items: center; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead h1 { display: flex; align-items: center; gap: 10px; }
.back { font-size: 13px; display: inline-block; margin-bottom: 4px; }
.monthnav { display: flex; align-items: center; gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.narrow { max-width: 520px; }
.cardhead { display: flex; justify-content: space-between; align-items: baseline; }
.subtotal { font-weight: 600; font-size: 15px; }
.hint { color: var(--muted); font-size: 12.5px; margin: -6px 0 10px; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #d3d6d0; border-radius: 7px;
  padding: 7px 9px; min-width: 0; width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(29,79,134,.25); border-color: var(--brand-2); }
input[readonly] { background: #f7f8f6; color: #444; }
input.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.legs { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form label { flex: 1 1 160px; }
.inline-form.tight { margin-bottom: 12px; }
.inline-form.tight input, .inline-form.tight select { width: auto; flex: 1 1 120px; }
.rowform { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.rowform input { width: auto; padding: 4px 6px; }
.login { width: 340px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login p { margin: -8px 0 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; cursor: pointer;
  padding: 8px 14px; border-radius: 7px; border: 1px solid #cfd3cc; background: #fff; color: var(--ink);
  white-space: nowrap;
}
.btn:hover { text-decoration: none; background: #f6f7f4; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--neg); border-color: #f0c7c2; }
.btn.right { margin-left: auto; }
.linkbtn { border: 0; background: none; color: var(--brand-2); cursor: pointer; font: inherit; font-size: 13px; padding: 2px 4px; }
.x { border: 0; background: none; color: #a0a6ad; font-size: 18px; cursor: pointer; line-height: 1; padding: 2px 6px; }
.x:hover { color: var(--neg); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--info-bg); }
.flash.ok { background: var(--pos-bg); color: var(--pos); }
.flash.error { background: var(--neg-bg); color: var(--neg); }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi b { font-family: var(--mono); font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }
.kpi.pos b { color: var(--pos); }
.kpi.neg b { color: var(--neg); }

.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filters select { width: auto; }

/* tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.grid { background: var(--card); }
.card > .grid, .card .tablewrap > .grid { background: transparent; }
main > .tablewrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.grid th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid th.r { text-align: right; }
.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line2); vertical-align: top; }
.grid.compact td { padding: 6px 10px; }
.grid tfoot td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: 0; background: #fafbf9; }
.grid tr.click { cursor: pointer; }
.grid tr.click:hover td { background: #f7f9fc; }
.grid tr.dim td { color: #a7adb3; }
.empty { text-align: center; color: var(--muted); padding: 40px !important; }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 20px; }
.tag.abierta { background: var(--warn-bg); color: var(--warn); }
.tag.cerrada { background: #e9ecef; color: #495057; }

/* editor */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.sticky { position: sticky; top: 72px; }
.lines th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; padding: 4px 4px; font-weight: 600; }
.lines th.r { text-align: right; }
.lines td { padding: 2px 4px; border-top: 1px solid var(--line2); vertical-align: middle; }
.lines input { padding: 5px 7px; border-color: transparent; background: transparent; }
.lines tr:hover input:not([readonly]), .lines input:focus { border-color: #d3d6d0; background: #fff; }
.lines tr.has .cname { color: var(--ink); font-weight: 500; }
.lines .cname { color: var(--muted); padding-left: 2px; }
.lines tr.has td { background: #fbfcfa; }
.lines tr.extra input[name=g_concepto] { border-color: #d3d6d0; }
.w-lt { width: 90px; } .w-pr { width: 100px; } .w-mo { width: 150px; }
.lines td:nth-child(2) { width: 22%; }
.lines tr:not(.fuel):not(.extra) td:nth-child(3), .lines tr:not(.fuel):not(.extra) td:nth-child(4) { }
.locked .lines input { pointer-events: none; }
textarea { resize: vertical; }

.alerts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.alert { padding: 9px 14px; border-radius: 8px; font-size: 13.5px; border-left: 4px solid; }
.alert.error { background: var(--neg-bg); border-color: var(--neg); color: #7a1a12; }
.alert.warn { background: var(--warn-bg); border-color: var(--accent); color: var(--warn); }
.alert.info { background: var(--info-bg); border-color: var(--brand-2); color: #23466f; }

.summary td, .summary th { padding: 5px 4px; font-size: 13px; }
.summary th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.summary tr.tot td { border-top: 1px solid var(--line); font-weight: 600; }
.bigresult { margin-top: 16px; padding: 14px 16px; border-radius: 9px; background: var(--pos-bg); color: var(--pos); display: flex; flex-direction: column; }
.bigresult span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.bigresult b { font-size: 28px; font-weight: 500; }
.bigresult small { opacity: .8; }
.bigresult.neg { background: var(--neg-bg); }
.log { list-style: none; padding: 0; margin: 0; font-size: 12.5px; max-height: 180px; overflow: auto; }
.log li { padding: 3px 0; border-bottom: 1px solid var(--line2); }

/* resumen */
.two { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.bars { display: flex; gap: 3px; height: 180px; align-items: stretch; }
.bar { flex: 1; display: flex; flex-direction: column; text-decoration: none !important; min-width: 0; }
.bar .pos-half, .bar .neg-half { flex: 1; display: flex; }
.bar .pos-half { align-items: flex-end; border-bottom: 1px solid #c9ccc5; }
.bar .neg-half { align-items: flex-start; }
.bar i { display: block; width: 100%; border-radius: 3px 3px 0 0; background: var(--pos); opacity: .85; }
.bar .neg-half i { background: var(--neg); border-radius: 0 0 3px 3px; }
.bar:hover i { opacity: 1; }
.bar em { font-style: normal; font-size: 10px; color: var(--muted); text-align: center; padding-top: 3px; }

@media (max-width: 1100px) {
  .layout, .two { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  main { padding: 16px; }
  .top { padding: 0 16px; gap: 12px; height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .top nav { order: 3; flex: 1 0 100%; }
  .row4 { grid-template-columns: 1fr 1fr; }
  .legs { grid-template-columns: 1fr; gap: 8px; }
  .w-lt, .w-pr { width: 70px; } .w-mo { width: 110px; }
  .lines td:nth-child(2) { display: none; } .lines th:nth-child(2) { display: none; }
}
.print-only { display: none; }
.t-chof { display: none; }

@media print {
  @page { size: A4; margin: 8mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: #fff; font-size: 8pt; line-height: 1.25; }
  .top, .actions, .btn, .x, .back, .alerts, .log, .hint, .similar, .no-print, datalist { display: none !important; }
  .print-only { display: block; }
  main { padding: 0; max-width: none; }
  .pagehead { display: none; }
  .print-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 0.5mm solid var(--brand);
    padding-bottom: 1.5mm; margin-bottom: 2.5mm; font-size: 9pt; color: var(--brand); }
  .layout { display: grid; grid-template-columns: 1fr 56mm; gap: 2.5mm; }
  .col-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2mm; align-content: start; }
  .card { margin: 0; padding: 1.6mm 2.4mm; border: 0.25mm solid #bbb; border-radius: 1.5mm; break-inside: avoid; }
  .col-side .card { position: static; }
  .p-wide { grid-column: 1 / -1; }
  h2 { font-size: 6.8pt; margin: 0 0 1mm; }
  h2.mt { margin-top: 2.5mm; }
  h3 { font-size: 7pt; margin: 0 0 0.5mm; }
  .cardhead h2 { margin-bottom: 0.5mm; }
  .subtotal { font-size: 8pt; }
  label { font-size: 6.3pt; gap: 0; }
  input, select, textarea { border: 0 !important; background: none !important; padding: 0 !important; font-size: 8pt;
    min-height: 0; height: auto; -webkit-appearance: none; appearance: none; color: #000; }
  input[type=date]::-webkit-calendar-picker-indicator, input[type=time]::-webkit-calendar-picker-indicator { display: none; }
  input.num { font-size: 7.6pt; }
  .row2 { gap: 2mm; margin-bottom: 0.8mm; }
  .row4 { gap: 2mm; }
  .legs { gap: 4mm; }
  .lines { table-layout: auto; }
  .lines th { font-size: 5.8pt; padding: 0 1mm 0.4mm; }
  .lines td { padding: 0.15mm 1mm; border-top: 0.2mm solid #e5e5e5; background: none !important; }
  .lines .cname { color: #000; font-size: 7.6pt; }
  .lines tr:not(.has) { display: none; }
  .gastos:not(.comb) .lines th:nth-child(3), .gastos:not(.comb) .lines th:nth-child(4),
  .gastos:not(.comb) .lines td:nth-child(3), .gastos:not(.comb) .lines td:nth-child(4),
  .lines th:nth-child(6), .lines td:nth-child(6) { display: none; }
  .lines th:nth-child(2), .lines td:nth-child(2) { width: 18%; }
  .lines td:first-child { white-space: nowrap; }
  .lines th:nth-child(5), .lines td:nth-child(5) { width: 21mm; min-width: 21mm; }
  .lines th:nth-child(2), .lines td:nth-child(2) { max-width: 22mm; }
  .comb .lines th:nth-child(5), .comb .lines td:nth-child(5) { width: 26mm; min-width: 26mm; }
  .lines td:nth-child(5) input { padding-right: 0.5mm !important; }
  .legs input { font-size: 7pt; }
  .w-mo { width: 24mm; } .w-lt { width: 14mm; } .w-pr { width: 14mm; }
  .p-obs:has(textarea:placeholder-shown) { display: none; }
  textarea { resize: none; }
  .summary td, .summary th { padding: 0.3mm 0.5mm; font-size: 7.4pt; }
  .summary th { font-size: 6pt; }
  .bigresult { margin-top: 2mm; padding: 2mm 2.5mm; }
  .bigresult span { font-size: 6.5pt; }
  .bigresult b { font-size: 14pt; }
  .bigresult small { font-size: 6.5pt; }
  .row3 { grid-template-columns: 1fr; }
  .firmas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10mm; margin-top: 12mm; font-size: 7pt; color: #444; }
  .firmas div { border-top: 0.25mm solid #666; padding-top: 1mm; text-align: center; }

  /* versión para choferes: viático, gastos de tripulación y saldo */
  body.print-choferes .t-full { display: none; }
  body.print-choferes .t-chof { display: inline; }
  body.print-choferes section.gastos[data-sec="administracion"],
  body.print-choferes .p-ventas, body.print-choferes .p-param, body.print-choferes .p-rent { display: none !important; }
  body.print-choferes .p-saldo h2.mt { margin-top: 0; }
  body.print-choferes .saldo-hint { display: block !important; margin: 2mm 0 0; font-size: 8pt; color: #000; font-weight: 600; }
  body.print-choferes .summary td, body.print-choferes .summary th { font-size: 8.5pt; padding: 0.6mm 0.5mm; }
  body.print-choferes .layout { grid-template-columns: 1fr; }
  body.print-choferes .col-main { gap: 2.5mm; }
  body.print-choferes .card { padding: 2.5mm 3.5mm; }
  body.print-choferes input, body.print-choferes .lines .cname { font-size: 9pt; }
  body.print-choferes .legs input { font-size: 8.5pt; }
  body.print-choferes label { font-size: 7pt; }
  body.print-choferes h2 { font-size: 7.5pt; }
  body.print-choferes .lines td { padding: 0.5mm 1mm; }
  body.print-choferes .lines th:nth-child(5), body.print-choferes .lines td:nth-child(5) { width: 26mm; min-width: 26mm; }
  body.print-choferes .col-side .card { max-width: 110mm; margin-left: auto; margin-top: 2.5mm; }
  body.print-choferes .summary td, body.print-choferes .summary th { font-size: 9.5pt; padding: 0.8mm 1mm; }
}

/* v2 */
.similar { color: var(--warn); font-size: 12px; font-weight: 400; background: var(--warn-bg); padding: 3px 6px; border-radius: 5px; }
.similar a { font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #f1f3ef; border-radius: 6px; padding: 1px 2px 1px 8px; margin: 2px 4px 2px 0; }
.chip .x { font-size: 14px; }
.bignum { font-size: 22px; margin: 0 0 12px; }
.cur { color: var(--muted); font-weight: 400; font-size: 11px; }
.lines select { padding: 5px 6px; }
.unify select { flex: 1 1 160px; }
.grid .c { text-align: center; width: 60px; }
.grid tr.grouprow td { background: #f4f6f2; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--brand); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; }
.chip.dim { opacity: .5; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
