/* ==========================================================================
   Billullo panel — all the styling for the site lives in this one file.
   Colors are defined once as variables; the dark set replaces them when the
   computer is in dark mode.
   ========================================================================== */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --tip-bg: #0b0b0b;
  --tip-ink: #ffffff;

  /* Chart colors, one per estado, always in this order */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-other: #898781;

  /* Reserved for good / warning / problem messages */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --accent: #6da7ec;
    --accent-ink: #0b0b0b;
    --tip-bg: #f0efec;
    --tip-ink: #0b0b0b;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
  }
}

/* Each estado keeps the same color everywhere it appears */
.e-creado { --c: var(--series-1); }
.e-aprobado { --c: var(--series-2); }
.e-desembolso { --c: var(--series-3); }
.e-activo { --c: var(--series-4); }
.e-acuerdopago { --c: var(--series-5); }
.e-inactivo { --c: var(--series-6); }
.e-rechazado { --c: var(--series-7); }
.e-otro { --c: var(--series-other); }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 4px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--ink-2); font-weight: 400; }
.small { font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.brand span { color: var(--ink-2); font-weight: 400; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 6px; color: var(--ink-2); text-decoration: none; }
.nav a:hover { background: var(--wash); }
.nav a[aria-current] { background: var(--wash); color: var(--ink); font-weight: 600; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: 13px; }
.account-email { color: var(--ink-2); }
.account form { margin: 0; }
.link-button { border: 0; padding: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }

/* ---------- Page layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-narrow { max-width: 440px; padding-top: 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-bottom: 16px; }
.section-title { margin: 8px 0 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin: 0 0 16px;
  min-width: 0;
}
.cards { display: grid; grid-template-columns: 1fr; gap: 16px; }
.cards .card { margin: 0; }
@media (min-width: 900px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
}
figcaption { margin-bottom: 16px; }
.empty, .empty-chart { color: var(--ink-2); }
.empty-chart { padding: 32px 0; }

/* ---------- Messages ---------- */
.notice {
  padding: 10px 14px; margin: 0 0 16px;
  border: 1px solid var(--border); border-left: 4px solid var(--axis);
  border-radius: 8px; background: var(--surface);
}
.notice-success { border-left-color: var(--good); }
.notice-warning { border-left-color: var(--warning); }
.notice-error { border-left-color: var(--critical); }
.notice-info { border-left-color: var(--series-1); }

/* ---------- Forms and buttons ---------- */
.field { margin-bottom: 14px; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  width: 100%; padding: 8px 10px;
  font: inherit; color: var(--ink);
  background: var(--page);
  border: 1px solid var(--axis); border-radius: 6px;
}
.input-small { width: 80px !important; }
.help, .help ul { font-size: 13px; color: var(--ink-2); margin: 4px 0 0; padding-left: 18px; }
.help { padding-left: 0; }
.field-error { color: var(--critical); font-size: 13px; margin: 4px 0 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 14px; }

.button {
  display: inline-block; padding: 8px 16px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--accent-ink); background: var(--accent);
  border: 1px solid var(--accent); border-radius: 6px;
}
.button:hover { filter: brightness(1.1); }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button-quiet { padding: 4px 10px; font-weight: 400; font-size: 13px; color: var(--ink); background: transparent; border-color: var(--axis); }
.button-quiet:hover { background: var(--wash); filter: none; }

.auth-card { padding: 28px; }
.auth-card .button { width: 100%; margin-bottom: 16px; }
.inline-form { display: grid; gap: 0 16px; align-items: end; }
@media (min-width: 800px) {
  .inline-form { grid-template-columns: 1.4fr 1fr auto auto; }
  .inline-form .button, .inline-form .check { margin-bottom: 14px; }
  .inline-form .check { height: 38px; }
}
.copy-row { display: flex; gap: 8px; margin-bottom: 12px; }
.link-card { border-left: 4px solid var(--good); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table-scroll { max-height: 280px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
thead th { font-size: 13px; font-weight: 600; color: var(--ink-2); border-bottom-color: var(--axis); }
tfoot th, tfoot td { border-top: 1px solid var(--axis); border-bottom: 0; font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.actions form { margin: 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
.pill-on::before { background: var(--good); }
.pill-wait::before { background: var(--warning); }
.pill-off::before { background: var(--critical); }

/* ---------- Today's numbers ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.tile p { margin: 0; }
.tile-label { color: var(--ink-2); font-size: 14px; }
.tile-value { font-size: 24px; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.tile-sub { color: var(--ink-2); font-size: 13px; }

/* ---------- Period filter ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 16px; }
.filters-label { font-weight: 600; }
.segmented { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented a { padding: 6px 14px; color: var(--ink-2); text-decoration: none; border-left: 1px solid var(--grid); }
.segmented a:first-child { border-left: 0; }
.segmented a:hover { background: var(--wash); }
.segmented a[aria-current] { background: var(--ink); color: var(--surface); font-weight: 600; }

/* ---------- Hover label shared by all charts ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(var(--h, 100%) + 8px);
  transform: translateX(-50%);
  padding: 4px 8px; border-radius: 6px;
  background: var(--tip-bg); color: var(--tip-ink);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  pointer-events: none; z-index: 5;
}
[data-tip].tip-start:hover::after, [data-tip].tip-start:focus-visible::after { left: 0; transform: none; }
[data-tip].tip-end:hover::after, [data-tip].tip-end:focus-visible::after { left: auto; right: 0; transform: none; }

/* ---------- Column chart (one column per day) ---------- */
.colchart {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 200px auto;
  column-gap: 10px; row-gap: 8px;
  padding-top: 8px;
}
.colchart-y, .colchart-grid { display: flex; flex-direction: column; justify-content: space-between; }
.colchart-y { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.colchart-y span { height: 0; line-height: 0; white-space: nowrap; }
.colchart-plot { position: relative; }
.colchart-grid, .colchart-bars { position: absolute; inset: 0; }
.colchart-grid span { height: 0; border-top: 1px solid var(--grid); }
.colchart-grid span:last-child { border-top-color: var(--axis); }
.colchart-bars, .colchart-x { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); }
.col { display: flex; align-items: flex-end; justify-content: center; outline-offset: -2px; }
.col:hover { background: var(--wash); }
.bar {
  width: min(24px, 100% - 2px); height: var(--h);
  background: var(--series-1);
  border-radius: 4px 4px 0 0;
}
.col:hover .bar { filter: brightness(1.15); }
.colchart-x { grid-column: 2; font-size: 12px; color: var(--muted); }
.colchart-x span { width: 0; justify-self: center; display: flex; justify-content: center; white-space: nowrap; }

/* ---------- Horizontal bars (share of each estado) ---------- */
.hbars { display: grid; gap: 12px; padding-top: 4px; }
.hbar-row { display: grid; grid-template-columns: 118px minmax(0, 1fr) 112px; align-items: center; gap: 10px; font-size: 14px; }
.hbar-track { display: block; }
.hbar-fill { display: block; height: 16px; min-width: 2px; background: var(--c); border-radius: 0 4px 4px 0; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Stacked bars (amount by city and estado) ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none; margin: 0 0 16px; padding: 0; font-size: 13px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.stack-rows { display: grid; gap: 10px; margin-bottom: 20px; }
.stack-row { display: grid; grid-template-columns: 140px minmax(0, 1fr) 84px; align-items: center; gap: 10px; font-size: 14px; }
.stack-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack-track { display: flex; gap: 2px; }
.seg { flex: 0 1 auto; min-width: 2px; height: 18px; background: var(--c); }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg:hover { filter: brightness(1.15); }
.stack-total { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- "Ver como tabla" ---------- */
.table-view { margin-top: 16px; }
.table-view summary { cursor: pointer; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }

@media (max-width: 600px) {
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .hbar-row { grid-template-columns: 96px minmax(0, 1fr) 96px; }
  .stack-row { grid-template-columns: 96px minmax(0, 1fr) 72px; }
  .copy-row { flex-direction: column; }
}
