/* Una columna central; arriba la marca y las pestañas (abajo en el celular). */
:root {
  --bg: #f5f6f5;
  --surface: #ffffff;
  --fg: #1b2220;
  --muted: #65706c;
  --line: #e1e5e3;
  --accent: #23705f;
  --accent-soft: #e2efeb;
  --danger: #b4372e;
  --danger-soft: #fae8e6;
  --warn: #946000;
  --warn-soft: #faefd8;
  --info: #3b5b94;
  --info-soft: #e6ecf7;
  --ok: #4a5954;
  --ok-soft: #eceff0;
  --overlay: rgba(20, 28, 26, .4);
  --font-display: "Outfit", "Avenir Next", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121715; --surface: #1a201e; --fg: #e7ecea; --muted: #98a49f; --line: #2a3330;
    --accent: #5fbfa6; --accent-soft: #1e3430; --danger: #ef8a80; --danger-soft: #3a2220;
    --warn: #e6b450; --warn-soft: #352b16; --info: #8eaee8; --info-soft: #1f2838;
    --ok: #a9b5b0; --ok-soft: #242c29; --overlay: rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: 20px;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.brand { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  background: none; border: 0; padding: 8px 12px; border-radius: 999px; color: var(--muted); font-weight: 500;
  display: flex; align-items: center; gap: 6px; text-decoration: none;
}
.tab:hover { color: var(--fg); background: var(--bg); }
.tab.on { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.tab svg { width: 18px; height: 18px; flex: none; }
.userbox { display: flex; align-items: center; gap: 8px; }
.linkbtn { background: none; border: 0; color: var(--muted); padding: 4px 0; font-size: .88rem; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover { color: var(--fg); }

main {
  max-width: 980px; margin: 0 auto;
  padding-block: 24px 80px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 24px;
}
.demo-banner { background: var(--info-soft); color: var(--info); font-size: .88rem; padding: 8px 14px; border-radius: 10px; }

.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
h1 { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; margin: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
h2 .count, .muted { color: var(--muted); font-family: var(--font-body); font-weight: 400; font-size: .88rem; }
.sub { color: var(--muted); margin: 4px 0 0; font-size: .92rem; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { width: auto; }
section { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sechead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Botones ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 9px 16px; font-weight: 600;
  background: var(--accent); color: var(--surface); white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--surface); color: var(--fg); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); filter: none; }
.btn.danger { background: var(--danger); color: var(--surface); }
.btn.small { padding: 5px 12px; font-size: .85rem; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.btnrow select { width: auto; }

/* ---------- Números ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.stat .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.stat .hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.danger .value { color: var(--danger); }
.stat.warn .value { color: var(--warn); }
.stat.accent .value { color: var(--accent); }

.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }

/* ---------- Listas ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 16px; align-items: center;
  width: 100%; text-align: left; background: none; border: 0; padding: 12px 16px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
button.row:hover, a.row:hover { background: var(--bg); }
a.row { color: inherit; text-decoration: none; }
.row .what { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.row .meta { grid-column: 1; color: var(--muted); font-size: .85rem; display: flex; gap: 4px 10px; flex-wrap: wrap; align-items: center; min-width: 0; }
.row .amount { grid-row: 1; grid-column: 2; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.row .side { grid-column: 2; display: flex; justify-content: flex-end; gap: 6px; align-items: center; flex-wrap: wrap; }
.empty { padding: 20px 16px; color: var(--muted); text-align: center; }

/* Tabla de liquidación */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: left; border-top: 1px solid var(--line); white-space: nowrap; }
thead th { border-top: 0; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--bg); }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--bg); }
td .name { font-weight: 600; white-space: normal; min-width: 170px; }
td .small { color: var(--muted); font-size: .82rem; white-space: normal; }
tfoot td { font-weight: 600; background: var(--bg); }

.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kv > div { background: var(--surface); padding: 10px 14px; min-width: 0; }
.kv .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kv .v { font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.breakdown { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.breakdown .line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 14px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.breakdown .line:first-child { border-top: 0; }
.breakdown .line.total { background: var(--bg); font-weight: 600; }
.breakdown .line.big { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* Etiquetas de estado */
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }

.alerts { display: flex; flex-direction: column; gap: 0; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 16px; border-top: 1px solid var(--line); }
.alert:first-child { border-top: 0; }
.alert .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--muted); }
.alert.danger .dot { background: var(--danger); }
.alert.warn .dot { background: var(--warn); }
.alert.info .dot { background: var(--info); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: .9rem; }
.chip button { background: none; border: 0; color: var(--muted); padding: 0 6px; font-size: 1rem; line-height: 1; }
.chip button:hover { color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .legend { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field .help { font-size: .8rem; color: var(--muted); }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fgrid .full { grid-column: 1 / -1; }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 60px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; max-height: 100%; overflow-y: auto;
  padding: 20px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.sheet.wide { max-width: 640px; }
.sheet h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions .right { display: flex; gap: 10px; margin-left: auto; }
.confirm { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; font-size: .9rem; }
.formerror { color: var(--danger); font-size: .88rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem; z-index: 60; max-width: calc(100% - 32px);
}

/* ---------- Ingreso ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login form { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 1.5rem; }
.loading { padding: 60px 16px; text-align: center; color: var(--muted); }
.passwrap { position: relative; }
.passwrap input { padding-right: 76px; }
.verpass {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: .82rem; font-weight: 600; color: var(--accent);
}
.verpass:hover { background: var(--accent-soft); }

/* ---------- Comprobante ---------- */
.comprobante { background: #fff; color: #111; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; max-width: 720px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.comprobante h2 { font-size: 1.3rem; }
.comprobante .head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 2px solid #111; padding-bottom: 10px; }
.comprobante table th { background: #f2f2f2; color: #444; }
.comprobante td, .comprobante th { border-color: #ddd; }
.comprobante .firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 50px; }
.comprobante .firma { border-top: 1px solid #111; padding-top: 6px; text-align: center; font-size: .85rem; }
.comprobante .fine { font-size: .78rem; color: #555; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line); justify-content: space-around;
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .tab { flex-direction: column; gap: 2px; font-size: .7rem; padding: 6px 8px; border-radius: 10px; }
  .tab svg { width: 22px; height: 22px; }
  .userbox { margin-left: auto; }
  main { padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr 1fr; }
  .fgrid { grid-template-columns: 1fr; }
  .overlay { align-items: flex-end; padding-bottom: 0; }
  .sheet { border-radius: 16px 16px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(12px); opacity: .6; } to { transform: none; opacity: 1; } }
}

/* ---------- Impresión (solo el comprobante) ---------- */
@media print {
  body { background: #fff; }
  .topbar, .tabs, .noprint, .demo-banner, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .comprobante { border: 0; padding: 0; max-width: none; }
}
