/* Finanzas NK — estilos. Colores tomados del logo NK. */
:root {
  --red: #c8171e;
  --slate: #2b3442;
  --slate-2: #1e252f;
  --mint: #a9d6c3;
  --gold: #e3a82b;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --text: #1d2430;
  --muted: #667085;
  --line: #e2e7e5;
  --accent: #2b3442;
  --pos: #16855a;
  --neg: #c8171e;
  --warn: #b26b00;
  --warn-bg: #fff6e0;
  --ok-bg: #e7f6ef;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 8px rgba(16, 24, 40, 0.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --surface-2: #222a34;
    --text: #e8ecf1;
    --muted: #98a2b3;
    --line: #2d3642;
    --accent: #a9d6c3;
    --pos: #3ccf8e;
    --neg: #ff6b6b;
    --warn: #f0bc45;
    --warn-bg: #2e2614;
    --ok-bg: #12291f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
body.noscroll { overflow: hidden; }
a { color: inherit; }
h1 { font-size: 1.45rem; margin: 0.2rem 0 0.8rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.7rem; }
h3 { font-size: 0.98rem; margin: 0.8rem 0 0.4rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: transparent; }
input[type='checkbox'], input[type='radio'] { width: auto; min-height: 0; accent-color: var(--red); }
input[type='color'] { padding: 2px; height: 42px; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.86rem; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea, label > div { color: var(--text); font-weight: 400; font-size: 0.95rem; }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); font-size: 0.92rem; }
code { background: var(--surface-2); padding: 0.1rem 0.3rem; border-radius: 4px; }
pre { white-space: pre-wrap; font-size: 0.78rem; background: var(--surface-2); padding: 0.6rem; border-radius: 8px; max-height: 260px; overflow: auto; }
details > summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 0.3rem 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 0.84rem; margin: 0.5rem 0; }
.warn { color: var(--warn); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn-t { color: var(--warn); }
.ic { width: 20px; height: 20px; flex: none; vertical-align: -4px; }

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 42px;
  padding: 0.5rem 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
label.btn { flex-direction: row; font-size: 0.95rem; color: var(--text); }
label.btn.primary { color: #fff; }
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--neg); }
.btn.danger:not(.ghost) { background: var(--neg); color: #fff; border-color: var(--neg); }
.btn.big { width: 100%; min-height: 52px; font-size: 1.02rem; }
.btn.sm { min-height: 34px; padding: 0.3rem 0.6rem; }
.btn.full { width: 100%; margin-top: 1rem; }
.link { background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 600; text-align: left; }
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin 0.7s linear infinite; vertical-align: -4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.boot, .loading, .empty { display: grid; place-items: center; gap: 0.8rem; padding: 3rem 1rem; text-align: center; color: var(--muted); }
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.8rem;
  padding: calc(0.55rem + env(safe-area-inset-top)) 1rem 0.55rem;
  background: var(--slate); color: #fff;
}
.brand { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.brand b { color: var(--gold); }
.spaces { display: flex; gap: 0.35rem; overflow-x: auto; margin-left: auto; scrollbar-width: none; }
.chip { border: 1px solid rgba(255, 255, 255, 0.25); background: transparent; color: #dfe6ee; border-radius: 999px; padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.85rem; white-space: nowrap; }
.chip.on { background: #fff; color: var(--slate); border-color: #fff; font-weight: 700; }
.chip.on.sp-personal { background: #3f7cc4; color: #fff; border-color: #3f7cc4; }
.chip.on.sp-terceros { background: #4a9bb0; color: #fff; border-color: #4a9bb0; }
.chip.on.sp-negocio { background: var(--red); color: #fff; border-color: var(--red); }
.frame { display: flex; max-width: 1280px; margin: 0 auto; }
.side { display: none; }
main { flex: 1; min-width: 0; padding: 1rem 1rem 6rem; }
.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 0.3rem 0 calc(0.3rem + env(safe-area-inset-bottom));
}
.bottom a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.7rem; text-decoration: none; color: var(--muted); padding: 0.2rem 0.6rem; }
.bottom a.on { color: var(--red); }
.bottom .fab { background: var(--red); color: #fff; width: 52px; height: 52px; border-radius: 50%; justify-content: center; margin-top: -24px; box-shadow: 0 4px 12px rgba(200, 23, 30, 0.35); }
.bottom .fab .ic { width: 26px; height: 26px; }
.menu-list { display: grid; gap: 0.4rem; }
.menu-list a { display: flex; gap: 0.7rem; align-items: center; padding: 0.85rem 1rem; background: var(--surface); border-radius: 12px; text-decoration: none; font-weight: 600; box-shadow: var(--shadow); }

@media (min-width: 960px) {
  .side { display: flex; flex-direction: column; gap: 0.2rem; width: 230px; padding: 1rem 0.6rem; position: sticky; top: 56px; height: calc(100vh - 56px); }
  .side a { display: flex; gap: 0.6rem; align-items: center; padding: 0.6rem 0.8rem; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; }
  .side a:hover { background: var(--surface); }
  .side a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .side a.on .ic { color: var(--red); }
  .bottom { display: none; }
  main { padding: 1.4rem 1.6rem 3rem; }
}

/* Componentes */
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; margin-top: 1rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 0.8rem; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.head-row h1, .head-row h2 { margin: 0; }
.head-row input[type='month'] { width: auto; }
.card { background: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; border: 1px solid var(--line); }
.grid2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 820px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 1rem; } }
.callout { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; justify-content: space-between; background: var(--ok-bg); border-radius: 12px; padding: 0.8rem 1rem; margin-bottom: 1rem; text-decoration: none; }
.callout.warn-c { display: block; background: var(--warn-bg); color: var(--text); }
.callout.warn-c .ic { margin-right: 0.3rem; }
.badge { display: inline-block; font-size: 0.68rem; padding: 0.05rem 0.4rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); margin-left: 0.3rem; font-weight: 600; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tabs { display: flex; gap: 0.3rem; background: var(--surface); padding: 0.25rem; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 1rem; }
.tabs.scroll { overflow-x: auto; }
.tabs a { padding: 0.45rem 0.8rem; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; font-size: 0.9rem; }
.tabs a.on { background: var(--slate); color: #fff; }
.toolbar { margin-bottom: 1rem; }
.toolbar select, .toolbar input { width: auto; }
.toolbar label { flex-direction: row; align-items: center; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.7rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 0.85rem 1rem; box-shadow: var(--shadow); border: 1px solid var(--line); }
.kpi span { display: block; color: var(--muted); font-size: 0.8rem; }
.kpi b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.spaces-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.7rem; margin-bottom: 1rem; }
.space-card { background: var(--surface); border-radius: var(--radius); padding: 0.85rem 1rem; border: 1px solid var(--line); border-top: 4px solid var(--c); box-shadow: var(--shadow); }
.space-card h3 { margin: 0 0 0.4rem; }
.space-card div { display: flex; justify-content: space-between; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.space-card .net { border-top: 1px solid var(--line); margin-top: 0.3rem; padding-top: 0.3rem; font-weight: 700; }

/* Gráficas */
.chart { display: block; overflow: visible; }
.bar-in { fill: var(--pos); }
.bar-out { fill: var(--neg); opacity: 0.85; }
.axis { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }
.sw.in { background: var(--pos); }
.sw.out { background: var(--neg); }
.hbar { margin-bottom: 0.55rem; }
.hbar-l { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.88rem; }
.hbar-l b { font-variant-numeric: tabular-nums; }
.hbar-t { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.hbar-t div { height: 100%; border-radius: 4px; }

/* Saldos */
.bal-total { display: flex; flex-wrap: wrap; gap: 1.2rem; margin-bottom: 0.6rem; }
.bal-total span { display: block; font-size: 0.78rem; color: var(--muted); }
.bal-total b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.acc-list { list-style: none; margin: 0; padding: 0; }
.acc-list li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.acc-list li:last-child { border: 0; }
.acc-list a { display: flex; align-items: center; gap: 0.45rem; text-decoration: none; }
.acc-list b { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Movimientos */
.mov-list { display: flex; flex-direction: column; }
.mov { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0.4rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.mov:hover { background: var(--surface-2); }
.mov.draft { background: var(--warn-bg); }
.mov-main { flex: 1; min-width: 0; }
.mov-main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.mov-main small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-dot { width: 8px; height: 34px; border-radius: 4px; flex: none; }
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.neu { color: var(--muted); }
#list { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); padding: 0 0.6rem; }
.filters { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.8rem; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.6rem; margin: 0.5rem 0; }
.totals { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.9rem; margin: 0.4rem 0; font-variant-numeric: tabular-nums; }
.sel-all { margin: 0.4rem 0; }
.bulk { position: sticky; top: 60px; z-index: 10; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; background: var(--slate); color: #fff; padding: 0.6rem; border-radius: 12px; margin-bottom: 0.6rem; }
.bulk select { width: auto; flex: 1 1 140px; color: var(--text); }

/* Formulario de movimiento */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 0.55rem; border-radius: 9px; font-weight: 700; color: var(--muted); font-size: 0.92rem; }
.seg-ingreso input:checked + span { background: var(--pos); color: #fff; }
.seg-gasto input:checked + span { background: var(--neg); color: #fff; }
.seg-transferencia input:checked + span { background: var(--slate); color: #fff; }
.amount-in { font-size: 1.4rem !important; font-weight: 700; font-variant-numeric: tabular-nums; }
.with-btn { display: flex; gap: 0.4rem; }
.with-btn select { flex: 1; }
.reader { border-style: dashed; }
.ocr-msg { display: flex; gap: 0.5rem; align-items: center; color: var(--muted); }
.ocr-ok { background: var(--ok-bg); border-radius: 10px; padding: 0.7rem; margin-top: 0.5rem; }
.files-inline { display: flex; flex-direction: column; gap: 0.4rem; }
.file-chip { display: flex; align-items: center; gap: 0.5rem; background: var(--surface-2); border-radius: 10px; padding: 0.45rem 0.6rem; }
.file-chip a { display: flex; align-items: center; gap: 0.4rem; text-decoration: none; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip.pend { border: 1px dashed var(--line); }
.file-chip small { color: var(--muted); margin-left: auto; white-space: nowrap; }
.x { border: 0; background: transparent; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 0.3rem; }
.split-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap: 0.4rem; align-items: center; }
@media (max-width: 640px) { .split-row { grid-template-columns: 1fr 1fr; } }
.sticky-actions { position: sticky; bottom: 70px; background: var(--surface); padding-top: 0.5rem; }
@media (min-width: 960px) { .sticky-actions { bottom: 0; } }

/* Listas de tarjetas */
.cards-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.8rem; }
.cards-list .card { margin: 0; text-align: left; text-decoration: none; cursor: pointer; display: flex; flex-direction: column; gap: 0.25rem; }
.cards-list h3 { margin: 0; }
.acc-card { border-left: 5px solid var(--c); }
.acc-bal { font-size: 1.3rem; font-variant-numeric: tabular-nums; margin: 0.3rem 0; }
.t-bal { font-size: 0.95rem; margin: 0.3rem 0; }
.t-bal b { font-size: 1.2rem; }
.archived { opacity: 0.55; }
.colors { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.colors label { cursor: pointer; }
.colors input { position: absolute; opacity: 0; }
.colors i { display: block; width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.colors input:checked + i { border-color: var(--text); }
.simple-list { list-style: none; margin: 0; padding: 0; }
.simple-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.8rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.simple-list li small { color: var(--muted); }
.simple-list li .btn { margin-left: auto; }

/* Archivos */
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.8rem; margin-top: 0.8rem; }
.file-card { background: var(--surface); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.thumb { display: grid; place-items: center; height: 130px; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.pdf { font-weight: 800; color: var(--red); letter-spacing: 0.05em; }
.fc-body { padding: 0.5rem 0.6rem; display: flex; flex-direction: column; font-size: 0.82rem; }
.fc-body b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fc-body small { color: var(--muted); }
input.full { margin-bottom: 0.3rem; }

/* Tablas y reportes */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-bottom: 0.6rem; }
.tbl th, .tbl td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.sum td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl tr.big td { font-size: 1rem; }
.tbl tr.warn-row td { color: var(--warn); }
.tbl tr[data-href] { cursor: pointer; }
.tbl.compact td, .tbl.compact th { padding: 0.3rem 0.4rem; }
.tbl.compact select { min-height: 32px; padding: 0.2rem 0.3rem; font-size: 0.82rem; }
.report { background: var(--surface); border-radius: var(--radius); padding: 1.2rem; border: 1px solid var(--line); margin-bottom: 1rem; }
.report h2 { margin-top: 1.4rem; padding-bottom: 0.3rem; border-bottom: 2px solid var(--gold); }
.report-head { display: flex; gap: 0.9rem; align-items: center; margin-bottom: 1rem; }
.report-head h1 { margin: 0; font-size: 1.25rem; }
.report-head p { margin: 0.2rem 0 0; }

/* Acceso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at 30% 20%, #3a4659, var(--slate-2)); }
.auth-card { background: var(--surface); border-radius: 20px; padding: 2rem 1.5rem; width: 100%; max-width: 400px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
.auth-card h1 { margin: 0.5rem 0; }
.auth-card form { text-align: left; margin-top: 1rem; }
.auth-logo { filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.25)); }
.email-login { margin-top: 1.2rem; text-align: left; }

/* Modal y avisos */
.modal-back { position: fixed; inset: 0; background: rgba(10, 14, 20, 0.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 1.2rem; position: relative; padding-bottom: calc(1.2rem + env(safe-area-inset-bottom)); }
.modal.wide { max-width: 900px; }
@media (min-width: 640px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }
.modal-x { position: absolute; top: 0.6rem; right: 0.7rem; border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); }
.confirm-msg { font-size: 1rem; margin: 0.5rem 2rem 1.2rem 0; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; transition: 0.2s; background: var(--slate); color: #fff; padding: 0.7rem 1.1rem; border-radius: 12px; z-index: 60; max-width: calc(100% - 2rem); pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--neg); }

/* Impresión / PDF */
@media print {
  @page { margin: 14mm; }
  :root { --bg: #fff; --surface: #fff; --text: #111; --muted: #555; --line: #ccc; --pos: #0b6b45; --neg: #a10f15; color-scheme: light; }
  body { background: #fff; font-size: 11pt; }
  .top, .side, .bottom, .no-print, .tabs, .callout, .toolbar, #toast { display: none !important; }
  main { padding: 0 !important; }
  .report, .card, .kpi { border: 0; box-shadow: none; padding: 0; }
  .kpi { border: 1px solid #ccc; padding: 0.4rem 0.6rem; }
  .report h2 { break-after: avoid; }
  .tbl tr { break-inside: avoid; }
}
