:root {
  color-scheme: dark;
  --ink: #08111f;
  --ink-2: #0d1828;
  --surface: #111e30;
  --surface-raised: #16253a;
  --paper: #f5f7f4;
  --text: #eef4f0;
  --text-soft: #b9c7c1;
  --text-dim: #879891;
  --rule: rgba(199, 219, 210, .14);
  --rule-strong: rgba(199, 219, 210, .26);
  --mineral: #5bd4a5;
  --mineral-deep: #167a5d;
  --cobalt: #77a8ff;
  --coral: #ff806f;
  --amber: #f4bd63;
  --shadow: 0 18px 50px rgba(0, 0, 0, .24);
  --radius: 18px;
  --font-ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-data: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { background: var(--ink); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(rgba(119, 168, 255, .025) 1px, transparent 1px),
    var(--ink);
  background-size: 100% 48px;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
}
button, input, select { font: inherit; }
button, a, select, input { -webkit-tap-highlight-color: transparent; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.skip-link {
  position: fixed; left: 12px; top: -80px; z-index: 100;
  padding: 10px 14px; background: var(--paper); color: var(--ink); border-radius: 8px;
}
.skip-link:focus { top: 12px; }

.app-header {
  min-height: 74px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 10px clamp(14px, 3vw, 42px);
  border-bottom: 1px solid var(--rule);
  background: rgba(8, 17, 31, .94);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(14px);
}
.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-lockup strong, .brand-lockup span { display: block; }
.brand-lockup strong { font-size: 15px; letter-spacing: -.01em; }
.brand-lockup > div > span { color: var(--text-dim); font-size: 12px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto;
  color: var(--mineral); border: 1px solid var(--rule-strong); border-radius: 12px;
  background: var(--ink-2);
}
.brand-mark svg { width: 24px; height: 24px; }
.header-meta { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; }
.icon-button {
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 1px solid var(--rule); color: var(--text-soft); border-radius: 12px; text-decoration: none;
  background: var(--surface);
  transition: border-color .18s ease, color .18s ease, transform .18s ease;
}
.icon-button:hover { border-color: var(--mineral); color: var(--mineral); transform: translateY(-1px); }

main { width: min(1480px, calc(100% - 24px)); margin: 0 auto; padding: 18px 0 52px; }
.filter-dock {
  display: grid; grid-template-columns: repeat(3, minmax(138px, .75fr)) minmax(210px, 1.4fr) auto;
  gap: 10px; align-items: end; padding: 12px; margin-bottom: 14px;
  background: var(--ink-2); border: 1px solid var(--rule); border-radius: var(--radius);
}
label { color: var(--text-dim); font-size: 12px; font-weight: 650; }
select, input[type="search"] {
  width: 100%; height: 44px; margin-top: 5px; padding: 0 12px;
  border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); color: var(--text);
}
select:focus-visible, input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(119,168,255,.72); outline-offset: 2px;
}
.button {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--mineral); color: #04160f; font-weight: 750; cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button-subtle { background: transparent; color: var(--text-soft); border-color: var(--rule); }
.button-subtle:hover { border-color: var(--rule-strong); background: var(--surface); }

.closing-grid { display: grid; grid-template-columns: minmax(320px, .9fr) minmax(0, 1.55fr); gap: 14px; }
.monthly-close, .trend-panel, .panel, .ledger-section, .methodology {
  border: 1px solid var(--rule); background: var(--ink-2); border-radius: var(--radius); box-shadow: var(--shadow);
}
.monthly-close { overflow: hidden; }
.close-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 18px 14px; border-bottom: 1px solid var(--rule); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: clamp(22px, 2.2vw, 32px); letter-spacing: -.035em; }
h2 { margin-bottom: 2px; font-size: clamp(19px, 1.8vw, 25px); letter-spacing: -.025em; }
h3 { font-size: 15px; }
.close-head p, .section-title-row p, .ledger-head p { margin: 0; color: var(--text-dim); font-size: 13px; }
.status-chip {
  align-self: flex-start; padding: 5px 9px; border-radius: 999px; border: 1px solid rgba(91,212,165,.28);
  color: var(--mineral); font-size: 11px; font-weight: 750; white-space: nowrap;
}
.close-total { padding: 22px 18px; background: var(--paper); color: var(--ink); }
.close-total span { display: block; font-size: 12px; color: #52615b; font-weight: 700; }
.close-total strong {
  display: block; margin-top: 4px; font-family: var(--font-data); font-size: clamp(33px, 5vw, 56px);
  line-height: 1.05; letter-spacing: -.055em; font-variant-numeric: tabular-nums;
}
.close-ledger { margin: 0; padding: 4px 18px 0; }
.close-ledger > div { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--rule); }
.close-ledger dt { color: var(--text-dim); }
.close-ledger dd { margin: 0; font-family: var(--font-data); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.change-up { color: var(--coral); }
.change-down { color: var(--mineral); }
.method-note { margin: 0; padding: 12px 18px 16px; color: var(--text-dim); font-size: 11px; }

.trend-panel { min-width: 0; padding: 18px; display: flex; flex-direction: column; }
.section-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 12px; }
.legend-line { color: var(--text-dim); font: 600 11px var(--font-data); display: inline-flex; align-items: center; gap: 6px; }
.legend-line i { width: 18px; height: 2px; background: var(--mineral); display: inline-block; }
.trend-chart { min-height: 292px; flex: 1; overflow: hidden; }
.trend-chart svg { width: 100%; height: 100%; min-height: 292px; overflow: visible; }
.chart-grid { stroke: var(--rule); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--mineral); stroke-width: 3; vector-effect: non-scaling-stroke; }
.chart-area { fill: rgba(91, 212, 165, .09); stroke: none; }
.chart-dot { fill: var(--ink-2); stroke: var(--mineral); stroke-width: 2; }
.chart-label { fill: var(--text-dim); font: 10px var(--font-data); }
.chart-value { fill: var(--text-soft); font: 10px var(--font-data); }

.analysis-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(260px, .65fr) minmax(280px, .85fr); gap: 14px; margin-top: 14px; align-items: start; }
.panel { min-width: 0; padding: 18px; }
.ranked-bars { display: grid; gap: 10px; }
.bar-item { display: grid; grid-template-columns: minmax(90px, .75fr) minmax(100px, 1.5fr) auto; gap: 10px; align-items: center; }
.bar-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); font-size: 13px; }
.bar-track { height: 9px; border-radius: 999px; background: rgba(255,255,255,.055); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--cobalt); }
.bar-value { font: 700 11px var(--font-data); color: var(--text-soft); text-align: right; }
.owner-split { display: grid; gap: 10px; }
.owner-row { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.owner-row > div { display: flex; justify-content: space-between; gap: 10px; }
.owner-row strong { font-size: 14px; }
.owner-row span { font: 700 12px var(--font-data); }
.owner-meter { display: flex; height: 5px; border-radius: 999px; background: rgba(255,255,255,.055); margin-top: 9px; overflow: hidden; }
.owner-meter i { background: var(--mineral); display: block; }
.privacy-seal { display: flex; gap: 10px; align-items: center; margin-top: 16px; padding: 12px; border: 1px solid var(--rule); border-radius: 12px; color: var(--text-soft); }
.privacy-seal svg { flex: 0 0 auto; color: var(--mineral); }
.privacy-seal strong, .privacy-seal span { display: block; }
.privacy-seal strong { font-size: 12px; }
.privacy-seal span { color: var(--text-dim); font-size: 11px; }
.merchant-list { list-style: none; padding: 0; margin: 0; }
.merchant-list li { display: grid; grid-template-columns: 26px minmax(0,1fr) auto; gap: 9px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.merchant-rank { color: var(--text-dim); font: 11px var(--font-data); }
.merchant-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.merchant-amount { font: 700 11px var(--font-data); }

.ledger-section { margin-top: 14px; overflow: hidden; }
.ledger-head { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 18px; border-bottom: 1px solid var(--rule); }
.ledger-head h2 { margin-bottom: 2px; }
.toggle { display: flex; align-items: center; gap: 9px; color: var(--text-soft); font-size: 12px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--mineral-deep); }
.table-shell { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 920px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { position: sticky; top: 73px; z-index: 2; background: #0d1828; color: var(--text-dim); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
td { color: var(--text-soft); font-size: 12px; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: rgba(119,168,255,.045); }
tbody tr.excluded { opacity: .58; }
.numeric { text-align: right; font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.merchant-cell strong, .merchant-cell small, .owner-cell strong, .owner-cell small { display: block; }
.merchant-cell strong, .owner-cell strong { color: var(--text); font-size: 12px; }
.merchant-cell small, .owner-cell small { color: var(--text-dim); margin-top: 2px; }
.data-chip { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border: 1px solid var(--rule); border-radius: 999px; font-size: 10px; }
.confidence-alta { color: var(--mineral); }
.confidence-muy-alta { color: var(--mineral); border-color: rgba(91,212,165,.42); }
.confidence-media { color: var(--amber); }
.confidence-baja { color: var(--coral); }
.load-more { display: block; margin: 14px auto; background: var(--surface-raised); color: var(--text); border-color: var(--rule); }
.load-more[hidden] { display: none !important; }
.empty-row { text-align: center; padding: 30px; color: var(--text-dim); }

.methodology { margin-top: 14px; overflow: hidden; }
.methodology summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 14px; min-height: 64px; padding: 14px 18px; }
.methodology summary::-webkit-details-marker { display: none; }
.methodology summary strong, .methodology summary small { display: block; }
.methodology summary small { color: var(--text-dim); margin-top: 2px; }
.methodology[open] summary { border-bottom: 1px solid var(--rule); }
.methodology[open] summary svg { transform: rotate(180deg); }
.methodology-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 18px; }
.coverage-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); color: var(--text-soft); font-size: 12px; }
.coverage-row span:last-child { font-family: var(--font-data); }
.coverage-disclaimer { margin: 0; padding: 0 18px 18px; color: var(--text-dim); font-size: 12px; max-width: 80ch; }
.toast { position: fixed; left: 50%; bottom: 18px; z-index: 30; transform: translate(-50%, 140%); padding: 11px 15px; border-radius: 10px; background: var(--paper); color: var(--ink); font-weight: 750; box-shadow: var(--shadow); transition: transform .2s ease, opacity .2s ease; opacity: 0; visibility: hidden; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
  .filter-dock { grid-template-columns: repeat(3, 1fr); }
  .search-field { grid-column: span 2; }
  .analysis-grid { grid-template-columns: 1.25fr .75fr; }
  .merchant-panel { grid-column: 1 / -1; }
  .merchant-list { columns: 2; column-gap: 28px; }
  .merchant-list li { break-inside: avoid; }
}

@media (max-width: 780px) {
  .app-header { min-height: 66px; }
  .header-meta > span { display: none; }
  main { width: min(100% - 16px, 1480px); padding-top: 10px; }
  .filter-dock { grid-template-columns: 1fr 1fr; gap: 8px; }
  .search-field { grid-column: 1 / -1; }
  .button-subtle { width: 100%; }
  .closing-grid, .analysis-grid { grid-template-columns: 1fr; }
  .trend-chart, .trend-chart svg { min-height: 230px; }
  .merchant-panel { grid-column: auto; }
  .merchant-list { columns: 1; }
  .methodology-grid { grid-template-columns: 1fr; }
  .ledger-head { align-items: flex-start; flex-direction: column; }
  th { top: 65px; }
}

@media (max-width: 520px) {
  .brand-lockup > div > span { display: none; }
  .filter-dock { grid-template-columns: 1fr 1fr; }
  .filter-dock label:nth-child(3) { grid-column: 1 / -1; }
  .close-total strong { font-size: 37px; }
  .close-ledger > div { grid-template-columns: minmax(0, 1fr) minmax(96px, auto); }
  .trend-panel, .panel { padding: 14px; }
  .bar-item { grid-template-columns: minmax(112px,.9fr) 1fr; }
  .bar-label { white-space: normal; line-height: 1.2; }
  .bar-value { grid-column: 2; }
  .table-shell { overflow: visible; }
  table, tbody { display: block; min-width: 0; width: 100%; }
  thead { display: none; }
  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "merchant amount"
      "date amount"
      "category quality"
      "owner owner";
    gap: 7px 12px;
    padding: 15px 14px;
    border-bottom: 1px solid var(--rule);
  }
  tbody td { padding: 0; border: 0; min-width: 0; }
  tbody td:nth-child(1) { grid-area: date; color: var(--text-dim); font-size: 11px; }
  tbody td:nth-child(2) { grid-area: merchant; }
  tbody td:nth-child(3) { grid-area: category; }
  tbody td:nth-child(4) { grid-area: owner; }
  tbody td:nth-child(5) { grid-area: quality; justify-self: end; }
  tbody td:nth-child(6) { grid-area: amount; align-self: start; font-size: 14px; font-weight: 750; white-space: nowrap; }
  .methodology summary small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
