/* ============================================================
   AI4Colegios "Libro de Pago" v3 — shared component kit
   The single, consistent component language for every surface.
   Builds on tokens.css. Brand fixed: navy + teal, gold crest,
   WhatsApp green; Georgia serif / system sans / mono money.
   ============================================================ */

:root {
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-pop: 0 18px 48px rgba(16, 24, 40, 0.18);
  --radius-lg: 14px;
  --ring: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent);
}
:root[data-theme="dark"] {
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 18px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
.v3 { font-family: var(--font-sans); font-size: var(--fs-body); line-height: var(--lh-body);
  color: var(--text); background: var(--warm); -webkit-font-smoothing: antialiased; font-variant-numeric: lining-nums; }
.v3 button { font-family: inherit; }
.v3 :focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.money { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }
.serif { font-family: var(--font-serif); }
.eyebrow { font-size: var(--fs-label); text-transform: uppercase; letter-spacing: var(--ls-label);
  font-weight: 700; color: var(--text-muted); }

/* ---------- CREST ---------- */
.crest { width: 34px; height: 34px; position: relative; flex: none; }
.crest .shield { position: absolute; inset: 0; background: radial-gradient(circle at 32% 28%, #F4D777 0%, var(--gold) 52%, var(--gold-dark) 100%);
  border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.55), var(--shadow-sm); }
.crest .r { position: absolute; inset: 0; display: grid; place-items: center; color: #5A3A0E;
  font-family: var(--font-serif); font-weight: 700; font-size: 16px; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: flex; flex-direction: column; height: 100%; background: var(--warm); overflow: hidden; position: relative; }
.app-body { flex: 1; display: flex; min-height: 0; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.main-scroll { flex: 1; overflow: auto; min-height: 0; }

/* ---------- HEADER ---------- */
.hdr { background: var(--header-bg); color: var(--header-text); height: 56px; flex: none;
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,.06); }
.hdr-brand { display: flex; align-items: center; gap: 12px; }
.hdr-brand .nm { font-family: var(--font-serif); font-weight: 600; font-size: 15.5px; color: #fff; line-height: 1.2; }
.hdr-brand .nm small { font-weight: 400; opacity: .62; margin-left: 7px; font-size: 12px; }
.hdr-brand .motto { font-family: var(--font-serif); font-style: italic; font-size: 11px; color: #9FB0D6; margin-top: 1px; }
.hdr-right { display: flex; align-items: center; gap: 14px; }
.hdr-saved { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: #9FB0D6; }
.hdr-saved .ck { width: 15px; height: 15px; border-radius: 50%; background: var(--wa-green); color: #062b13;
  display: grid; place-items: center; font-size: 9px; font-weight: 800; }
.hdr-seg { display: flex; align-items: center; background: rgba(255,255,255,.08); border-radius: 9px; padding: 3px; gap: 2px; }
.hdr-seg .sl { font-size: 9.5px; font-weight: 700; letter-spacing: .1em; color: rgba(255,255,255,.4); padding: 0 6px; align-self: center; }
.hdr-seg button { border: 0; background: transparent; color: rgba(255,255,255,.62); font-size: 11px; font-weight: 700;
  letter-spacing: .06em; padding: 5px 10px; border-radius: 6px; cursor: pointer; min-height: 26px; display: grid; place-items: center; }
.hdr-seg button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.hdr-seg button svg { width: 15px; height: 15px; display: block; }
.hdr-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; }

/* ---------- LEFT NAV ---------- */
.nav { width: var(--rail-left); flex: none; background: var(--sidebar-bg); color: #fff; display: flex; flex-direction: column;
  position: relative; transition: width .18s; }
.nav.collapsed { width: var(--rail-collapsed); }
.nav-toggle { position: absolute; top: 12px; right: -12px; z-index: 20; width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--grid); background: var(--paper); color: var(--text); cursor: pointer; display: grid; place-items: center; font-size: 12px; box-shadow: var(--shadow-sm); }
.nav-main { flex: 1; overflow-y: auto; padding: 12px 0; display: flex; flex-direction: column; min-height: 0; }
.nav-sec { font-size: 9.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--sidebar-muted);
  padding: 14px 18px 6px; font-weight: 700; }
.nav.collapsed .nav-sec { color: transparent; height: 1px; padding: 8px 0; overflow: hidden; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 18px; font-size: 13px; color: #CCD5E6;
  text-decoration: none; cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left;
  border-left: 3px solid transparent; transition: background .12s, color .12s; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-hover); border-left-color: var(--accent); color: #fff; }
.nav-item .ico { flex: none; width: 20px; height: 20px; display: grid; place-items: center; color: #93A4CC; }
.nav-item.active .ico { color: var(--accent-light); }
.nav-item .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; display: flex; align-items: center; gap: 7px; }
.nav-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--wa-green); flex: none; }
.nav.collapsed .nav-item { justify-content: center; padding: 10px 0; }
.nav.collapsed .nav-item .lbl { display: none; }
.nav.collapsed .nav-item.active { box-shadow: inset 3px 0 0 var(--accent); border-left-color: transparent; }
.nav-foot { border-top: 1px solid var(--sidebar-border); padding: 6px 0; }
.nav.collapsed .nav-today, .nav.collapsed .nav-sec.today-lbl { display: none; }

/* today payments feed */
.nav-today { padding: 2px 10px 8px; }
.tp { display: block; width: 100%; text-align: left; background: transparent; border: 0; cursor: pointer;
  padding: 8px 9px; border-radius: 9px; color: #CCD5E6; transition: background .12s, transform .1s; margin-bottom: 2px; }
.tp:hover { background: var(--sidebar-hover); transform: translateY(-1px); }
.tp .who { font-size: 11.5px; font-weight: 600; color: #EAEEF6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-line { display: flex; align-items: center; justify-content: space-between; margin-top: 3px; }
.tp .amt { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: #86EFAC; }
.tp .mp { font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 999px; }
.tp .mp.cash { background: rgba(21,128,61,.24); color: #86EFAC; }
.tp .mp.transfer { background: rgba(124,58,237,.24); color: #C4B5FD; }
.tp .mp.card { background: rgba(30,64,175,.24); color: #93C5FD; }
.tp .tm { font-size: 10px; color: var(--sidebar-muted); margin-top: 2px; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.pagehead { background: var(--paper); border-bottom: 1px solid var(--grid); padding: 18px 26px 16px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; flex: none; }
.pagehead .ph-eyebrow { font-size: var(--fs-label); text-transform: uppercase; letter-spacing: var(--ls-label);
  font-weight: 700; color: var(--accent); margin-bottom: 5px; }
.pagehead h1 { font-family: var(--font-serif); font-size: 25px; font-weight: 600; letter-spacing: -.01em; margin: 0; color: var(--text); }
.pagehead .ph-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.ph-actions { display: flex; gap: 10px; flex: none; }

/* ============================================================
   BUTTONS / CONTROLS
   ============================================================ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: var(--radius-ctrl);
  padding: 0 16px; height: 38px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
  border: 1px solid transparent; transition: background .12s, border-color .12s, transform .08s, color .12s; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(44,140,153,.4); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--paper); color: var(--text); border-color: var(--grid-strong); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--grid); height: 34px; font-weight: 500; }
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }
.btn-wa { background: var(--wa-green); color: #062b13; font-weight: 700; }
.btn-wa:hover { filter: brightness(1.04); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* segmented control */
.seg { display: inline-flex; background: var(--warm-2); border: 1px solid var(--grid-strong); border-radius: var(--radius-ctrl); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--text-soft); font-family: inherit; font-size: 12.5px;
  font-weight: 600; padding: 6px 14px; border-radius: 6px; cursor: pointer; min-height: 30px; }
.seg button.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }

/* toggle switch */
.toggle { width: 42px; height: 24px; border-radius: 999px; background: var(--grid-strong); border: 0; position: relative;
  cursor: pointer; flex: none; transition: background .15s; padding: 0; }
.toggle.on { background: var(--accent); }
.toggle .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: transform .15s; }
.toggle.on .knob { transform: translateX(18px); }

/* search + selects */
.field { position: relative; display: inline-flex; align-items: center; }
.field .ic { position: absolute; left: 11px; color: var(--text-muted); pointer-events: none; display: grid; place-items: center; }
.field .ic svg { width: 16px; height: 16px; }
.inp { border: 1px solid var(--grid-strong); border-radius: var(--radius-ctrl); height: 38px; padding: 0 12px;
  font-size: 13px; font-family: inherit; background: var(--paper); color: var(--text); }
.inp.with-ic { padding-left: 34px; }
.inp:focus-visible { border-color: var(--accent); }
select.inp { cursor: pointer; padding-right: 28px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; }

/* ---------- STATUS PILL (the one shared component) ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; line-height: 1.4; }
.pill .pd { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.pill.good { background: var(--status-good-bg); color: var(--status-good); }
.pill.good .pd { background: var(--status-good); }
.pill.mora1 { background: var(--status-mora1-bg); color: var(--status-mora1); }
.pill.mora1 .pd { background: var(--status-mora1); }
.pill.mora2 { background: var(--status-mora2-bg); color: var(--status-mora2); }
.pill.mora2 .pd { background: var(--status-mora2); }
.pill.pagado { background: var(--status-pagado-bg); color: var(--status-pagado); }
.pill.pagado .pd { background: var(--status-pagado); }
.pill.sinmat { background: var(--warm-2); color: var(--text-muted); }
.pill.sinmat .pd { background: var(--text-muted); }
.pill-sm { font-size: 10px; padding: 2px 8px 2px 6px; }
:root[data-theme="dark"] .pill.good { color: #86EFAC; }
:root[data-theme="dark"] .pill.mora1 { color: #FCD34D; }
:root[data-theme="dark"] .pill.mora2 { color: #FCA5A5; }
:root[data-theme="dark"] .pill.pagado { color: #93C5FD; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px;
  border-radius: 999px; border: 1px solid var(--grid-strong); background: var(--paper); color: var(--text-soft); }
.chip.wa { background: rgba(37,211,102,.12); color: var(--chip-wa-text); border-color: transparent; }
.chip.util { background: var(--status-good-bg); color: var(--status-good); border-color: transparent; }
.chip.mk { background: var(--status-remate-bg); color: var(--status-remate); border-color: transparent; }

/* ---------- CARD ---------- */
.card { background: var(--paper); border: 1px solid var(--grid); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
.card-pad { padding: 18px 20px; }
.card h2, .card-title { font-family: var(--font-serif); font-size: 16px; font-weight: 600; margin: 0; color: var(--text); }
.kv { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.kv:last-child { border-bottom: 0; }
.kv .k { font-size: 12.5px; color: var(--text-muted); }
.kv .v { font-size: 13.5px; color: var(--text); font-weight: 600; }

/* ============================================================
   KPI STRIP
   ============================================================ */
.kpis { display: grid; gap: 14px; padding: 16px 26px; flex: none; }
.kpi { background: var(--paper); border: 1px solid var(--grid); border-radius: var(--radius-lg); padding: 14px 16px; box-shadow: var(--shadow-card); }
.kpi .kl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.kpi .kv { display: block; border: 0; padding: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums;
  font-size: 22px; font-weight: 700; color: var(--text); margin-top: 7px; line-height: 1.1; }
.kpi .kv .cur { font-family: var(--font-sans); font-size: 11px; color: var(--text-muted); font-weight: 700; margin-left: 6px;
  background: var(--warm-2); padding: 1px 6px; border-radius: 4px; vertical-align: 3px; }
.kpi .kfoot { font-size: 11px; color: var(--text-muted); margin-top: 6px; display: flex; align-items: center; gap: 6px; }
.kpi.good .kv { color: var(--status-good); }
.kpi.warn .kv { color: var(--status-mora2); }
.kpi .kico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
.kpi-spark { height: 4px; border-radius: 999px; background: var(--warm-2); margin-top: 10px; overflow: hidden; }
.kpi-spark > i { display: block; height: 100%; border-radius: 999px; }

/* ============================================================
   LEDGER TABLE
   ============================================================ */
.sheet { background: var(--paper); overflow: auto; flex: 1; min-height: 0; }
table.libro { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: var(--fs-cell); }
table.libro th, table.libro td { border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); padding: 10px 12px; text-align: left; white-space: nowrap; }
table.libro.dense th, table.libro.dense td { padding: 6px 9px; }
table.libro thead th { position: sticky; background: var(--thead-bg); font-weight: 700; color: var(--text-soft); z-index: 3; }
table.libro thead tr.band th { top: 0; text-transform: uppercase; letter-spacing: .06em; text-align: center; font-size: 10px;
  color: var(--text-muted); background: var(--warm-2); border-bottom: 2px solid var(--grid-strong); z-index: 4; }
table.libro thead tr.band .b-pay { background: #EEF4F5; }
table.libro thead tr.band .b-paid { background: #F0F7F1; }
table.libro thead tr.band .b-saldo { background: #FBF1EE; }
table.libro thead tr.cols th { top: 33px; font-size: 10.5px; }
table.libro.dense thead tr.cols th { top: 29px; }
table.libro th.m, table.libro td.m { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }
table.libro tbody tr:nth-child(even) td { background: var(--row-even); }
table.libro tbody tr:hover td { background: var(--warm-2); }
table.libro tbody tr.sel td { background: var(--status-good-bg) !important; }
.lname { background: transparent; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; }
.lname:hover { color: var(--accent); text-decoration: underline; }
.fcount { font-size: 10px; color: var(--text-muted); margin-left: 6px; background: var(--warm-2); border-radius: 4px; padding: 1px 5px; }
.col-no { text-align: center; color: var(--text-muted); }
.col-gr { text-align: center; font-weight: 600; }
/* sticky cols */
table.libro .s0, table.libro .s1, table.libro .s2, table.libro .s3 { position: sticky; z-index: 2; }
table.libro .s0 { left: 0; width: 38px; text-align: center; }
table.libro .s1 { left: 38px; }
table.libro .s2 { left: 78px; min-width: 220px; }
table.libro .s3 { left: 298px; text-align: center; }
table.libro thead .s0, table.libro thead .s1, table.libro thead .s2, table.libro thead .s3 { z-index: 5; }
table.libro tbody td.s0, table.libro tbody td.s1, table.libro tbody td.s2, table.libro tbody td.s3 { background: var(--paper); }
table.libro tbody tr:nth-child(even) td.s0, table.libro tbody tr:nth-child(even) td.s1, table.libro tbody tr:nth-child(even) td.s2, table.libro tbody tr:nth-child(even) td.s3 { background: var(--row-even); }
table.libro tbody tr.sel td.s0, table.libro tbody tr.sel td.s1, table.libro tbody tr.sel td.s2, table.libro tbody tr.sel td.s3 { background: var(--status-good-bg) !important; }
/* month cells */
th.mc, td.mc { text-align: center; min-width: 64px; }
td.mcell { text-align: center; font-family: var(--font-mono); font-variant-numeric: tabular-nums; cursor: pointer; }
td.mcell.paid { background: var(--money-cell-paid); color: var(--status-good); font-weight: 700; }
td.mcell.mora { background: var(--money-cell-mora); color: var(--status-mora2); font-weight: 700; }
td.mcell.future { color: var(--text-muted); }
td.mcell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
th.curm { background: var(--status-mora1-bg); color: var(--status-mora1); }
td.curcol { box-shadow: inset 0 0 0 9999px rgba(245,158,11,.06); }
.checkbox { width: 17px; height: 17px; border-radius: 5px; border: 1.5px solid var(--grid-strong); background: var(--paper);
  cursor: pointer; display: inline-grid; place-items: center; }
.checkbox.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* legend */
.legend { display: flex; align-items: center; gap: 18px; padding: 9px 26px; background: var(--paper); border-bottom: 1px solid var(--grid); font-size: 11.5px; color: var(--text-muted); flex-wrap: wrap; }
.legend .li { display: inline-flex; align-items: center; gap: 7px; }
.legend .sw { width: 13px; height: 13px; border-radius: 4px; border: 1px solid var(--grid-strong); }
.legend .sw.paid { background: var(--money-cell-paid); border-color: var(--status-good); }
.legend .sw.mora { background: var(--money-cell-mora); border-color: var(--status-mora2); }
.legend .sw.cur { background: rgba(245,158,11,.16); border-color: var(--status-mora1); }
.legend .sw.future { background: var(--warm-2); }

/* toolbar */
.toolbar { background: var(--paper); border-bottom: 1px solid var(--grid); padding: 12px 26px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; flex: none; }
.toolbar .spacer { flex: 1; }
.toolbar .qvl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 700; }
.qv { display: inline-flex; align-items: center; gap: 7px; background: var(--paper); color: var(--text-soft); border: 1px solid var(--grid-strong);
  padding: 7px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; height: 34px; }
.qv:hover { border-color: var(--accent); color: var(--accent); }
.qv.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.qv .ct { font-size: 11px; background: rgba(255,255,255,.22); border-radius: 999px; padding: 0 7px; font-weight: 700; }
.qv:not(.active) .ct { background: var(--warm-2); color: var(--text-muted); }

/* context strip / pager */
.ctxbar { background: var(--warm-2); border-top: 1px solid var(--grid); padding: 9px 26px; display: flex; align-items: center; gap: 18px;
  font-size: 12.5px; color: var(--text-soft); flex: none; }
.ctxbar b { color: var(--text); font-family: var(--font-mono); }
.ctxbar .pager { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ctxbar .pager button { background: var(--paper); border: 1px solid var(--grid-strong); border-radius: 7px; padding: 5px 12px; font: inherit; font-size: 12px; cursor: pointer; color: var(--text-soft); }
.ctxbar .pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.ctxbar .pager button:disabled { opacity: .4; }

/* ---------- FAB ---------- */
.fab { position: absolute; bottom: 26px; right: 26px; z-index: 40; background: var(--accent); color: #fff; border: 0; border-radius: 32px;
  height: 54px; padding: 0 22px 0 18px; display: flex; align-items: center; gap: 11px; font-family: inherit; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 28px rgba(44,140,153,.42), 0 3px 8px rgba(0,0,0,.16); cursor: pointer; }
.fab .pl { width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.22); display: grid; place-items: center; }
.fab:hover { background: var(--accent-dark); }
