:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #6b7686;
  --line: #e3e7ec;
  --primary: #1f3a5f;
  --accent: #0d9488;
  --ok: #15803d;   --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c;  --bad-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- header ---------- */
.top {
  background: var(--primary); color: #fff;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px;
  padding: 12px 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; opacity: .75; font-size: 12px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
nav { display: flex; flex-wrap: wrap; gap: 6px; }
nav button {
  border: 0; background: transparent; color: #cfd9e6; padding: 8px 14px; border-radius: 8px;
  font: inherit; cursor: pointer;
}
nav button:hover { background: rgba(255,255,255,.1); }
nav button.active { background: #fff; color: var(--primary); font-weight: 600; }

main { max-width: 1320px; margin: 0 auto; padding: 22px 20px 10px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 20px 28px; }

.tab { display: none; }
.tab.active { display: block; }

.intro h2 { margin: 0 0 4px; font-size: 20px; }
.intro p { margin: 0 0 16px; color: var(--muted); max-width: 820px; }

/* ---------- cards / layout ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }
h3 small, .card-head small { font-weight: 400; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.split.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 960px) { .split, .split.even { grid-template-columns: 1fr; } }
.scroll { overflow-x: auto; }
.scroll.tall { max-height: 460px; overflow-y: auto; }
.muted { color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi b { font-size: 20px; display: block; margin-top: 2px; }
.kpi small { color: var(--muted); }
.kpi.good b { color: var(--ok); } .kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); }

/* ---------- controls ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #c5ccd6; background: #fafbfc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(.95); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.disabled { opacity: .5; pointer-events: none; }
.hint { color: var(--muted); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
select, input[type=date], .grid input {
  font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 14px; font: inherit; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }

/* ---------- tables ---------- */
table.grid { width: 100%; border-collapse: collapse; }
.grid th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap;
  padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1;
}
.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid td small { display: block; color: var(--muted); font-size: 11.5px; }
.grid tr:last-child td { border-bottom: 0; }
.grid tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.right { text-align: right; white-space: nowrap; }
.grid th.right { text-align: right; }
.neg { color: var(--bad); }
.grid input { width: 100%; min-width: 90px; padding: 4px 6px; }
.grid input[type=number] { min-width: 80px; text-align: right; }
.grid input.bad { border-color: var(--bad); background: var(--bad-bg); }
.row-warn { background: #fffaf0; }
.obs { font-size: 12px; color: var(--warn); max-width: 280px; }

/* ---------- chips ---------- */
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; border: 0; font-weight: 600;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); cursor: pointer; }
.chip.warn:hover { background: #fde68a; }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.gray { background: #eef0f3; color: var(--muted); font-weight: 500; }

/* ---------- ticket cards ---------- */
.tickets { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; margin-bottom: 18px; }
.ticket { position: relative; cursor: pointer; display: block; }
.ticket > input { position: absolute; top: 8px; left: 8px; z-index: 2; width: 18px; height: 18px; accent-color: var(--accent); }
.paper {
  background: #fdfcf8; border: 1px solid #e6e2d4; border-radius: 4px; padding: 12px 14px;
  font: 12px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; color: #2b2b2b;
  box-shadow: 0 2px 6px rgba(0,0,0,.06); transition: transform .15s;
}
.ticket:hover .paper { transform: translateY(-2px); }
.ticket > input:not(:checked) ~ .paper { opacity: .45; }
.p-title { text-align: center; font-weight: 700; font-size: 13px; padding-left: 14px; }
.p-line { display: flex; justify-content: space-between; gap: 8px; }
.p-line.center { justify-content: center; text-align: center; font-size: 11px; color: #555; }
.p-line.total { font-weight: 700; border-top: 1px dashed #999; margin-top: 4px; padding-top: 4px; }
.paper hr { border: 0; border-top: 1px dashed #bbb; margin: 6px 0; }
.smudge { filter: blur(2.2px); }

/* ---------- confidence / alerts / bars ---------- */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.alerts { display: grid; gap: 8px; margin-bottom: 16px; }
.alert { padding: 9px 12px; border-radius: 8px; border-left: 4px solid; font-size: 13px; }
.alert.warn { background: var(--warn-bg); border-color: var(--warn); }
.alert.info { background: var(--info-bg); border-color: var(--info); }
.alert.ok { background: var(--ok-bg); border-color: var(--ok); }

.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.cat-row:hover { background: #f5f7fa; }
.cat-row.sel { background: #eaf6f4; outline: 1px solid var(--accent); }
.cat-row .bar { grid-column: 1 / -1; height: 6px; background: #eef0f3; border-radius: 3px; overflow: hidden; }
.cat-row .bar i { display: block; height: 100%; border-radius: 3px; }
.cat-row small { color: var(--muted); }
.t-ingreso i { background: #16a34a; } .t-egreso i { background: #64748b; }
.t-impositivo i { background: #d97706; } .t-gasto i { background: #7c3aed; }

.mes-row { margin-bottom: 14px; }
.mes-row > b { display: block; margin-bottom: 4px; font-size: 13px; }
.dual { display: grid; grid-template-columns: 22px 1fr 130px; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 3px; }
.dual .bar { height: 10px; background: #eef0f3; border-radius: 5px; overflow: hidden; }
.dual .bar i { display: block; height: 100%; border-radius: 5px; }
.dual.df i { background: #1f3a5f; } .dual.cf i { background: #0d9488; }
.dual span:last-child { text-align: right; }
.mes-row .dif { font-size: 12px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }

.col-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 10px; }

/* ---------- chat ---------- */
.chat { position: sticky; top: 12px; }
.chat-body {
  background: #efeae2; border-radius: 10px; padding: 10px; max-height: 560px; overflow-y: auto; min-height: 140px;
}
.chat-empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 13px; }
.msg { margin-bottom: 12px; }
.msg-meta { font-size: 11px; color: #667; margin: 0 4px 3px; }
.bubble {
  background: #d9fdd3; border-radius: 10px 10px 2px 10px; padding: 8px 10px; white-space: pre-line;
  box-shadow: 0 1px 1px rgba(0,0,0,.1); font-size: 13px; margin-left: 18px;
}
.bubble time { display: block; text-align: right; font-size: 10.5px; color: #667; margin-top: 3px; }

/* ---------- ajustes de anchos de tablas ---------- */
.split.banco { grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); }
@media (max-width: 960px) { .split.banco { grid-template-columns: 1fr; } }
#bk-movs td, #iva-comps td { white-space: nowrap; }
#bk-movs td:nth-child(2) { white-space: normal; min-width: 230px; }
#iva-comps td:nth-child(4) { white-space: normal; min-width: 190px; }
#iva-comps th, #iva-comps td { padding: 8px; }
#tk-table { min-width: 1100px; }
#tk-table th, #tk-table td { padding: 7px 6px; }
#tk-table input { min-width: 70px; font-size: 13px; }
#tk-table input[type=date] { min-width: 128px; }
#tk-table td:nth-child(2) input { min-width: 130px; }
#tk-table td:nth-child(3) input { min-width: 118px; }
#tk-table td:nth-child(4) input { min-width: 172px; }
#tk-table td:nth-child(5) input { min-width: 104px; }
#tk-table td:nth-child(10) input { min-width: 84px; }
#tk-table input[type=number] { min-width: 74px; }
.row-warn td { border-bottom: 0; }
.obs-row td { background: #fffaf0; padding: 0 10px 10px; }
.obs-row .obs { max-width: none; font-size: 12.5px; }

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0;
  background: #1b2430; color: #fff; padding: 10px 18px; border-radius: 10px; transition: .25s; pointer-events: none;
  z-index: 10; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }
#iva-avisos { display: grid; gap: 8px; margin-bottom: 14px; }
.aviso { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; line-height: 1.45; border: 1px solid; }
.aviso.warn { background: #fff7e6; border-color: #f2c66d; color: #7a4b00; }
.aviso.info { background: #eef4fb; border-color: #c7d9ee; color: #1f3a5f; }
.btn.wa { display: inline-block; margin: 4px 0 0 8px; text-decoration: none; background: #25d366; border-color: #25d366; color: #fff; font-weight: 600; }
.btn.alt { background: #fff; }

/* ---------- ocultar datos personales ---------- */
.mask-toggle { margin-left: auto; font-size: 13px; color: #cfd9e6; display: flex; align-items: center; gap: 6px; cursor: pointer; }
body.masked .pii { filter: blur(6px); user-select: none; }
.guion { margin: 0 0 10px; padding-left: 20px; display: grid; gap: 6px; }
.guion code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; }

/* ---------- alquileres ---------- */
.al-form { margin-bottom: 14px; }
.al-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 14px; }
.al-grid .field { display: flex; flex-direction: column; align-items: stretch; gap: 3px; font-size: 12px; color: var(--muted); }
.al-grid .field input, .al-grid .field select { font: inherit; font-size: 14px; color: var(--ink); padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.al-grid .field.check { flex-direction: row; align-items: center; align-self: end; color: var(--ink); font-size: 14px; }
.idx-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
tr.ajuste td { background: #f3f8ff; }
.al-stack { display: grid; gap: 14px; }

/* ---------- descargas ---------- */
.logbox { margin: 0; max-height: 420px; overflow: auto; background: #0f1b2d; color: #cfe3ff; padding: 10px 12px; border-radius: 8px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
.neg { color: var(--bad); }

.busy { opacity: .5; pointer-events: none; }

/* VEP */
.chip.nc { cursor: default; }
.chip.warn.nc:hover { background: var(--warn-bg); }
.vp-acc { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- versión definitiva ---------- */
.hidden { display: none !important; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }
.formcol { display: grid; gap: 12px; }
.formcol label, .dlg label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.formcol input, .dlg input, .dlg select, .formcol select {
  font: inherit; font-size: 14px; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.userbox .btn { padding: 4px 10px; font-size: 12px; background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.userbox .btn:hover { background: rgba(255,255,255,.12); }
dialog.dlg { border: 0; border-radius: var(--radius); padding: 22px; width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.dlg::backdrop { background: rgba(15, 23, 42, .5); }
dialog.dlg h3 { margin: 0 0 14px; }
.dlg .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.acc { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.chip.nc { cursor: default; }
.chip.warn.nc:hover { background: var(--warn-bg); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.inactivo td { opacity: .55; }

/* ---- documentos / OCR ---- */
dialog.dlg.wide { width: min(1180px, 96vw); max-height: 94vh; overflow: auto; }
.docwrap { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(380px, 1.5fr); gap: 20px; align-items: start; }
.docprev { position: sticky; top: 0; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; padding: 8px; text-align: center; max-height: 82vh; overflow: auto; }
.docprev img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.docform .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.docform .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.docform .sumaline { margin-top: 10px; font-size: 13px; }
.docform .sumaline.bad { color: var(--bad); font-weight: 600; }
.docform .sumaline.ok { color: var(--ok); }
.docform h4 { margin: 14px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
table.movs { width: 100%; border-collapse: collapse; font-size: 12px; }
table.movs th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px; position: sticky; top: 0; background: #fff; }
table.movs td { padding: 2px; vertical-align: middle; }
table.movs input { padding: 4px 6px; font-size: 12px; width: 100%; box-sizing: border-box; }
table.movs input.num { text-align: right; }
table.movs tr.dudoso td { background: var(--warn-bg); }
table.movs tr.malsaldo td { background: var(--bad-bg); }
.movscroll { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.docform .err { margin-top: 8px; }
@media (max-width: 860px) { .docwrap { grid-template-columns: 1fr; } .docprev { position: static; max-height: 40vh; } .docform .grid3 { grid-template-columns: 1fr 1fr; } }
.docform input, .docform select { width: 100%; box-sizing: border-box; min-width: 0; }
.docform label { min-width: 0; }
.docform .grid3 > *, .docform .grid2 > * { min-width: 0; }
table.movs { table-layout: fixed; min-width: 640px; }
table.movs th:nth-child(1) { width: 132px; } table.movs th:nth-child(2) { width: auto; }
table.movs th:nth-child(3), table.movs th:nth-child(4), table.movs th:nth-child(5) { width: 104px; } table.movs th:nth-child(6) { width: 34px; }
table.movs input[type=date] { padding: 4px 2px; }
