/* =========================================================================
   Fondo TI — "Libro mayor" edition
   Square corners, shared seams, registration marks. No floating cards.
   Brand: Servicios Compartidos navy #17225b + gold #e7ba22
   Display: Space Grotesk · Body: Hanken Grotesk · Labels/data: Space Mono
   ========================================================================= */
:root {
  --ink: #10163a;
  --navy: #17225b;
  --navy-2: #1f2662;
  --gold: #e7ba22;
  --gold-ink: #7c5a05;
  --paper: #e7e9f1;
  --surface: #ffffff;
  --tint: #f3f4f9;
  --rule: #17225b;        /* structural seams */
  --hair: #cfd3e2;        /* interior hairlines */
  --t1: #171d3d;
  --t2: #5a6180;
  --pos: #1a7a4c;
  --neg: #b23a22;
  --mono: "Space Mono", ui-monospace, monospace;
  --maxw: 1140px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--t1);
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Space Grotesk", sans-serif; margin: 0; line-height: 1.02; }
button { font-family: inherit; cursor: pointer; }
.tabular { font-variant-numeric: tabular-nums; }

/* micro-label: the statement/ledger texture */
.kicker {
  font-family: var(--mono); font-size: .68rem; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase; color: var(--gold-ink);
}
.muted { color: var(--t2); font-size: .9rem; }
.section-title { font-size: clamp(1.3rem, 2.6vw, 1.7rem); font-weight: 600; color: var(--t1); letter-spacing: -.01em; }

/* buttons: square, stamped */
.btn { border: 1.5px solid transparent; border-radius: 0; padding: .6rem 1.15rem; font-size: .9rem; font-weight: 700; letter-spacing: .01em; transition: background .15s, color .15s; }
.btn-gold { background: var(--gold); color: #241d02; border-color: var(--gold); }
.btn-gold:hover { background: #f3cd45; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-block { width: 100%; margin-top: .4rem; padding: .85rem; }

/* ================= topbar ================= */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem clamp(1rem, 4vw, 2rem);
  background: var(--navy); color: #fff;
  border-bottom: 3px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.ring-accent { fill: var(--gold); }
.ring-body { fill: #ffffff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 1.12rem; }
.brand-text small { font-family: var(--mono); font-size: .6rem; letter-spacing: .1em; text-transform: uppercase; color: rgba(255,255,255,.6); }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.last-updated { font-family: var(--mono); font-size: .66rem; letter-spacing: .06em; color: rgba(255,255,255,.6); }

/* ================= framed document ================= */
main {
  position: relative;
  max-width: var(--maxw);
  margin: clamp(1rem, 3vw, 1.8rem) auto;
  background: var(--surface);
  border: 2px solid var(--rule);
}
/* registration marks at opposite corners */
main::before, main::after { content: ""; position: absolute; width: 16px; height: 16px; z-index: 3; }
main::before { top: 6px; left: 6px; border-top: 3px solid var(--gold); border-left: 3px solid var(--gold); }
main::after { bottom: 6px; right: 6px; border-bottom: 3px solid var(--gold); border-right: 3px solid var(--gold); }

/* every module is a band separated from the next by a seam (shared rule) */
.section { padding: clamp(1.4rem, 3.5vw, 2.2rem) clamp(1.1rem, 4vw, 2.2rem); border-top: 1px solid var(--rule); }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
/* the gold seam-tick that heads a section */
.section-head > div:first-child { position: relative; padding-left: 14px; }
.section-head > div:first-child::before { content: ""; position: absolute; left: 0; top: 3px; width: 5px; height: calc(100% - 4px); background: var(--gold); }
.section-head--panel { align-items: center; margin-bottom: 0; }

/* ================= hero (navy statement band) ================= */
.hero { position: relative; overflow: hidden; padding: clamp(1.9rem, 4.5vw, 3.2rem) clamp(1.1rem, 4vw, 2.2rem); color: #fff;
  background: radial-gradient(130% 150% at 90% -20%, rgba(231,186,34,.16), transparent 45%), linear-gradient(150deg, var(--navy) 8%, var(--ink) 98%); }
.hero-inner { position: relative; z-index: 2; max-width: 680px; }
.eyebrow { font-family: var(--mono); font-size: .7rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); margin: 0 0 1rem; }
.eyebrow--dark { color: var(--gold-ink); }
.hero-title { font-size: clamp(2.2rem, 6vw, 3.7rem); font-weight: 600; letter-spacing: -.02em; color: #fff; margin-bottom: 1.6rem; }
.hero-title em { font-style: normal; color: var(--gold); }
.hero-balance { display: flex; flex-direction: column; gap: .1rem; margin-bottom: 1.5rem; padding-bottom: 1.2rem; border-bottom: 2px solid var(--gold); max-width: 520px; }
.hero-balance-label { font-family: var(--mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.6); }
.hero-balance-amount { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: clamp(2.6rem, 7vw, 4rem); font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: #fff; }
.reconciled {
  align-self: flex-start; margin-top: .8rem;
  display: inline-flex; align-items: center; gap: .5rem;
  font-family: var(--mono); font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #b8f0d3;
  background: rgba(21,122,82,.24); border: 1.5px solid rgba(120,220,170,.45); padding: .34rem .7rem;
}
.reconciled::before { content: "✓"; font-weight: 700; }

.hero-split { display: flex; flex-direction: column; gap: .7rem; max-width: 520px; }
.split-bar { display: flex; height: 14px; border: 1.5px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); }
.split-seg { height: 100%; }
.split-seg.cele { background: var(--gold); }
.split-seg.navi { background: #8b96de; }
.split-legend { display: flex; flex-wrap: wrap; gap: 1.4rem; }
.split-item { display: flex; align-items: baseline; gap: .5rem; font-size: .84rem; }
.split-item .dot { width: 10px; height: 10px; align-self: center; }
.split-item .dot.cele { background: var(--gold); }
.split-item .dot.navi { background: #8b96de; }
.split-item .amt { font-family: "Space Grotesk", sans-serif; font-weight: 600; font-variant-numeric: tabular-nums; color: #fff; }
.split-item .lbl { font-family: var(--mono); font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: rgba(255,255,255,.62); }

.hero-ring { position: absolute; top: -12%; right: -6%; width: min(50%, 440px); z-index: 1; opacity: .22; pointer-events: none; }
.hero-ring svg { width: 100%; height: auto; display: block; transform-origin: 50% 50%; animation: spin 80s linear infinite; }
.hero-ring .ring-accent, .hero-ring .ring-body { fill: var(--gold); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= fund modules (share a central seam) ================= */
.fund-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--rule); }
.fund-card { position: relative; padding: 1.4rem 1.5rem; background: var(--surface); }
.fund-card + .fund-card { border-left: 1.5px solid var(--rule); }
.fund-card::before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 4px; background: var(--fund-accent, var(--gold)); }
.fund-name { display: flex; align-items: center; gap: .55rem; font-weight: 600; color: var(--t1); }
.fund-dot { width: 11px; height: 11px; background: var(--fund-accent, var(--gold)); }
.fund-balance { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: clamp(1.8rem, 4vw, 2.3rem); font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--navy); margin: .55rem 0 .15rem; }
.fund-sub { color: var(--t2); font-size: .84rem; }
.fund-meta { display: flex; flex-wrap: wrap; gap: .7rem 1.4rem; margin-top: 1.1rem; padding-top: .95rem; border-top: 1px solid var(--hair); }
.fund-meta div { font-family: var(--mono); font-size: .62rem; letter-spacing: .07em; text-transform: uppercase; color: var(--t2); }
.fund-meta b { display: block; margin-top: .2rem; font-family: "Space Grotesk", sans-serif; font-size: 1rem; color: var(--t1); font-variant-numeric: tabular-nums; letter-spacing: 0; }

/* ================= segmented toggle (square) ================= */
.seg { display: inline-flex; border: 1.5px solid var(--rule); }
.seg--full { display: flex; width: 100%; margin: 0 0 1rem; overflow-x: auto; }
.seg-btn { border: 0; background: var(--surface); color: var(--t2); padding: .45rem 1rem; font-family: var(--mono); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.seg-btn + .seg-btn { border-left: 1.5px solid var(--rule); }
.seg-btn.is-active { background: var(--navy); color: #fff; }

/* ================= matrix (signature grid) ================= */
.matrix-legend { display: flex; flex-wrap: wrap; gap: 1.3rem; margin-bottom: 1rem; }
.legend-item { display: flex; align-items: center; gap: .5rem; font-family: var(--mono); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; color: var(--t2); }
.legend-chip { width: 15px; height: 15px; }
.legend-chip.is-full { background: var(--gold); }
.legend-chip.is-partial { background: linear-gradient(135deg, var(--gold) 0 50%, #efe1b4 50% 100%); }
.legend-chip.is-none { background: var(--surface); border: 1.5px solid var(--hair); }
.legend-chip.is-pre { background: #dfe2ec; }

.matrix-scroll { overflow-x: auto; border: 1.5px solid var(--rule); }
.matrix { border-collapse: collapse; width: 100%; }
.matrix thead th {
  position: sticky; top: 0; z-index: 2; background: var(--navy); color: #fff;
  font-family: var(--mono); font-weight: 700; font-size: .6rem; letter-spacing: .04em;
  text-align: center; padding: .55rem .1rem; white-space: nowrap; border-left: 1px solid rgba(255,255,255,.12);
}
.matrix thead th .q { display: block; font-size: .56rem; color: rgba(255,255,255,.55); }
.matrix thead th.name-col, .matrix tbody td.name-col {
  position: sticky; left: 0; z-index: 3; background: var(--surface); text-align: left;
  padding: .6rem .9rem; min-width: 186px; border-right: 2px solid var(--rule);
}
.matrix thead th.name-col { z-index: 4; background: var(--navy); }
.matrix tbody tr:nth-child(even) td { background: var(--tint); }
.matrix tbody tr:nth-child(even) td.name-col { background: var(--tint); }
.matrix tbody td { border-top: 1px solid var(--hair); border-left: 1px solid var(--hair); text-align: center; height: 44px; }
.m-name { display: block; font-weight: 600; font-size: .9rem; color: var(--t1); line-height: 1.2; }
.m-sub { display: inline-flex; align-items: center; gap: .4rem; font-family: var(--mono); font-size: .68rem; color: var(--t2); margin-top: .16rem; }
.m-pill { font-family: var(--mono); font-size: .62rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: .06rem .4rem; }
.m-pill.ok { background: rgba(26,122,76,.12); color: var(--pos); }
.m-pill.due { background: rgba(178,58,34,.1); color: var(--neg); }

.cell { display: inline-block; width: 20px; height: 20px; vertical-align: middle; }
.cell.is-full { background: var(--gold); }
.cell.is-partial { background: linear-gradient(135deg, var(--gold) 0 50%, #efe1b4 50% 100%); }
.cell.is-none { background: transparent; border: 1.5px solid var(--hair); }
.cell.is-pre { width: 8px; height: 2px; background: #c3c8d8; }

/* ================= lower panels (share a seam) ================= */
.lower { display: block; padding: 0; border-top: 1px solid var(--rule); }
.panel { padding: clamp(1.3rem, 3vw, 1.9rem) clamp(1.1rem, 3vw, 1.7rem); background: var(--surface); min-width: 0; }
.panel + .panel { border-top: 1px solid var(--rule); }
.ledger, .reimb-list { list-style: none; margin: 0; padding: 0; }
.ledger { max-height: 480px; overflow-y: auto; }
.ledger-item { display: flex; align-items: center; gap: .85rem; padding: .7rem 0; border-top: 1px solid var(--hair); }
.ledger-item:first-child { border-top: 0; }
.led-icon { flex: none; width: 30px; height: 30px; display: grid; place-items: center; font-size: .95rem; font-weight: 700; border: 1.5px solid; }
.led-icon.in { color: var(--pos); border-color: var(--pos); }
.led-icon.out { color: var(--neg); border-color: var(--neg); }
.led-body { flex: 1; min-width: 0; }
.led-desc { display: block; font-weight: 500; font-size: .9rem; color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.led-meta { font-family: var(--mono); font-size: .64rem; letter-spacing: .03em; text-transform: uppercase; color: var(--t2); display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .1rem; }
.led-tag { color: var(--gold-ink); }
.led-amount { font-family: "Space Grotesk", sans-serif; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.led-amount.in { color: var(--pos); }
.led-amount.out { color: var(--neg); }
.ledgerCount, #ledgerCount { font-family: var(--mono); font-size: .66rem; letter-spacing: .05em; text-transform: uppercase; }

.reimb-item { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .75rem 0; border-top: 1px solid var(--hair); }
.reimb-item:first-child { border-top: 0; }
.reimb-info { display: flex; flex-direction: column; min-width: 0; }
.reimb-info .who { font-weight: 600; font-size: .92rem; }
.reimb-info .what { font-size: .78rem; color: var(--t2); }
.reimb-right { display: flex; align-items: center; gap: .8rem; }
.reimb-amt { font-family: "Space Grotesk", sans-serif; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--neg); }
.btn-pay { padding: .34rem .8rem; font-family: var(--mono); font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--navy); color: #fff; border: 0; }
.btn-pay:hover { background: var(--navy-2); }
.empty { color: var(--t2); font-size: .88rem; padding: 1.6rem 0; text-align: center; }

/* ================= footer ================= */
.foot { max-width: var(--maxw); margin: 0 auto 2.6rem; padding: 1.2rem clamp(1rem, 4vw, 2rem) 0; display: flex; align-items: center; gap: .8rem; color: var(--t2); font-family: var(--mono); font-size: .68rem; letter-spacing: .04em; }
.foot-mark { width: 34px; height: 34px; flex: none; }
.foot-mark .ring-accent { fill: var(--gold); }
.foot-mark .ring-body { fill: var(--navy); }

/* ================= admin: fab, drawer, modal (square, flat) ================= */
.fab { position: fixed; right: clamp(1rem, 4vw, 2rem); bottom: clamp(1rem, 4vw, 2rem); z-index: 45; background: var(--gold); color: #241d02; border: 2px solid var(--navy); padding: .8rem 1.3rem; font-family: var(--mono); font-weight: 700; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
.fab:hover { background: #f3cd45; }
.scrim { position: fixed; inset: 0; background: rgba(9,12,32,.6); z-index: 50; }
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; }
.modal-card { width: min(410px, 100%); }
.card { background: var(--surface); border: 2px solid var(--navy); padding: 1.7rem; }
.card-title { font-size: 1.3rem; font-weight: 600; margin-bottom: .3rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.modal .btn-ghost { color: var(--t2); border-color: var(--hair); }
.modal .btn-ghost:hover { background: var(--tint); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(430px, 100%); background: var(--surface); border-left: 2px solid var(--navy); padding: 1.4rem clamp(1.1rem, 3vw, 1.7rem); overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: .9rem; border-bottom: 2px solid var(--gold); }
.icon-btn { background: var(--tint); border: 1.5px solid var(--hair); width: 34px; height: 34px; color: var(--t2); font-size: .9rem; }
.icon-btn:hover { background: #e7e9f2; }
.field { display: flex; flex-direction: column; gap: .32rem; margin-bottom: .85rem; }
.field > span { font-family: var(--mono); font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--t2); }
.field input, .field select { font-family: inherit; font-size: .95rem; color: var(--t1); border: 1.5px solid var(--hair); border-radius: 0; padding: .6rem .7rem; background: var(--surface); }
.field input:focus, .field select:focus { outline: 0; border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.form-error { color: var(--neg); font-size: .84rem; margin: .2rem 0 0; }
.form-note { font-size: .82rem; color: var(--t2); }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 70; background: var(--navy); color: #fff; padding: .7rem 1.1rem; border: 1.5px solid var(--gold); font-family: var(--mono); font-size: .74rem; letter-spacing: .04em; font-weight: 700; }
.toast.err { background: var(--neg); border-color: var(--neg); }

/* ================= receipts ================= */
.field-photo input[type="file"] { font-family: var(--mono); font-size: .78rem; color: var(--t2); border: 1.5px dashed var(--hair); border-radius: 0; padding: .55rem; background: var(--tint); }
.field-photo input[type="file"]::file-selector-button { font-family: var(--mono); font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; margin-right: .7rem; padding: .4rem .7rem; border: 0; background: var(--navy); color: #fff; cursor: pointer; }
.hint { color: var(--t2); font-size: .72rem; margin-top: .2rem; }

.chip-receipt { display: inline-flex; align-items: center; gap: .3rem; font-family: var(--mono); font-size: .66rem; font-weight: 700; letter-spacing: .04em; padding: .14rem .45rem; border: 1.5px solid var(--hair); background: var(--surface); color: var(--gold-ink); cursor: pointer; }
.chip-receipt:hover { border-color: var(--gold); }

.viewer { width: min(680px, 100%); max-height: 88vh; background: var(--surface); border: 2px solid var(--navy); display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 2px solid var(--gold); }
.viewer-imgs { overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .8rem; }
.viewer-imgs img { width: 100%; height: auto; border: 1px solid var(--hair); display: block; }
.viewer-imgs .empty { text-align: center; }

/* ================= photo picker (camera + gallery) ================= */
.photo-actions { display: flex; gap: .5rem; margin-top: .1rem; }
.photo-btn { flex: 1; font-family: var(--mono); font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: .58rem; border: 1.5px solid var(--navy); background: var(--surface); color: var(--navy); }
.photo-btn:hover { background: var(--tint); }
.photo-thumbs { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .6rem; }
.photo-thumbs:empty { margin-top: 0; }
.thumb { position: relative; width: 66px; height: 66px; border: 1.5px solid var(--hair); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x { position: absolute; top: -9px; right: -9px; width: 21px; height: 21px; border: 1.5px solid var(--surface); background: var(--neg); color: #fff; font-size: .66rem; line-height: 1; display: grid; place-items: center; cursor: pointer; }

/* ================= focus + motion ================= */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ================= responsive ================= */
@media (max-width: 820px) {
  .lower { grid-template-columns: 1fr; }
  .panel + .panel { border-left: 0; border-top: 1px solid var(--rule); }
}
@media (max-width: 560px) {
  .brand-text small { display: none; }
  .last-updated { display: none; }
  .fund-grid { grid-template-columns: 1fr; }
  .fund-card + .fund-card { border-left: 0; border-top: 1.5px solid var(--rule); }
  .field-row { grid-template-columns: 1fr; }
  .hero-ring { opacity: .15; }
}
