/* Contabilidad KDENT: panel del propietario (fase 5b).
   Una hoja sobre fondo porcelana; la cinta del año es el único elemento llamativo. */

@font-face { font-family: "Plex"; src: url("/assets/fonts/plex-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url("/assets/fonts/plex-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url("/assets/fonts/plex-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  color-scheme: light;
  --page: #edf2f5;
  --sheet: #ffffff;
  --ink: #12212b;
  --ink-2: #546874;
  --line: #dce4e9;
  --grid: #e8eef1;
  --band: #e6f1f8;
  --income: #0277bd;
  --expense: #e8661f;
  --accent: #0277bd;
  --good: #006c10;
  --bad: #b42318;
  --warn: #b25e00;
  --focus: #0277bd;
  --on-accent: #ffffff;
  --radius-sheet: 18px;
  --radius-control: 10px;
  font-family: "Plex", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0c1419;
    --sheet: #142029;
    --ink: #e5edf1;
    --ink-2: #93a6b1;
    --line: #22323c;
    --grid: #1c2a33;
    --band: #1a3344;
    --income: #3d9be0;
    --expense: #e76624;
    --accent: #5fb2ec;
    --good: #53c556;
    --bad: #ff8a80;
    --warn: #f3b24a;
    --focus: #5fb2ec;
    --on-accent: #0c1419;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.07rem; font-weight: 600; letter-spacing: -0.005em; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
.muted { color: var(--ink-2); }
[hidden] { display: none !important; }
.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; }

/* Barra superior: marca y sesión, sin peso visual. */
.topbar { display: flex; align-items: center; gap: 1rem; max-width: 1180px; margin: 0 auto; padding: 1rem 1.25rem 0.75rem; }
.brand { display: flex; align-items: baseline; gap: 0.45rem; }
.topbar .brand { margin-right: auto; }
.brand strong { font-weight: 600; letter-spacing: 0.02em; }
.brand span { color: var(--ink-2); }
.topbar .who { color: var(--ink-2); font-size: 0.93rem; }
.link-button { background: none; border: 0; padding: 0.35rem 0.1rem; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* La hoja: un solo plano blanco; las secciones se separan con aire y líneas finas, no con tarjetas. */
.sheet { max-width: 1180px; margin: 0 auto 2.5rem; background: var(--sheet); border-radius: var(--radius-sheet); box-shadow: 0 1px 0 var(--line), 0 12px 32px -24px rgba(18, 33, 43, 0.35); transition: opacity 160ms ease; }
.sheet.busy { opacity: 0.55; }

/* Cinta del año. */
.year { padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--line); }
.year-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.year-head select { appearance: none; background: var(--page); border: 1px solid var(--line); border-radius: var(--radius-control); padding: 0.3rem 2rem 0.3rem 0.75rem; font-weight: 600; font-size: 1.07rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: right 0.9rem center, right 0.6rem center; background-size: 5px 5px; background-repeat: no-repeat; }
.legend { display: flex; gap: 1rem; margin-left: auto; color: var(--ink-2); font-size: 0.87rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .in { background: var(--income); }
.legend .out { background: var(--expense); }
.ribbon { position: relative; }
.ribbon svg { display: block; width: 100%; height: auto; overflow: visible; }
.ribbon .grid { stroke: var(--grid); stroke-width: 1; }
.ribbon .base { stroke: var(--line); stroke-width: 1; }
.ribbon .tick { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.ribbon .bar-in { fill: var(--income); }
.ribbon .bar-out { fill: var(--expense); }
.ribbon .slot { cursor: pointer; }
.ribbon .slot .hit { fill: transparent; }
.ribbon .slot .band { fill: transparent; transition: fill 120ms ease; }
.ribbon .slot:hover .band { fill: var(--grid); }
.ribbon .slot.selected .band { fill: var(--band); }
.ribbon .slot:focus { outline: none; }
.ribbon .slot:focus-visible .band { stroke: var(--focus); stroke-width: 2; }
.ribbon .slot.future { cursor: default; }
.ribbon .label { fill: var(--ink-2); font-size: 12px; text-anchor: middle; }
.ribbon .slot.selected .label { fill: var(--ink); font-weight: 600; }
.ribbon .closed { fill: var(--good); }
.ribbon.animate .bar-in, .ribbon.animate .bar-out { transform-box: fill-box; transform-origin: bottom; animation: grow 520ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .ribbon.animate .bar-in, .ribbon.animate .bar-out { animation: none; } }
.tooltip { position: absolute; pointer-events: none; background: var(--ink); color: var(--sheet); border-radius: 10px; padding: 0.5rem 0.7rem; font-size: 0.85rem; line-height: 1.35; min-width: 11rem; transform: translate(-50%, -100%); z-index: 2; }
.tooltip strong { display: block; font-weight: 600; margin-bottom: 0.2rem; }
.tooltip div { display: flex; align-items: center; gap: 0.45rem; }
.tooltip i { width: 12px; height: 2px; display: inline-block; border-radius: 2px; }
.tooltip b { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 0.75rem; }

details.table-view { margin-top: 0.5rem; }
details > summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; width: fit-content; }
details > summary::marker { color: var(--ink-2); }

/* Cuerpo: columna principal y columna de apoyo. */
.body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.main { padding: 1.75rem 1.5rem 1.5rem; min-width: 0; }
.rail { border-left: 1px solid var(--line); padding: 1.75rem 1.5rem 1.5rem; display: grid; gap: 1.75rem; align-content: start; }
.rail section + section { border-top: 1px solid var(--line); padding-top: 1.5rem; }

/* La frase principal. */
.lead { padding-bottom: 1.75rem; border-bottom: 1px solid var(--line); }
.lead .sentence { font-size: 1.2rem; color: var(--ink-2); }
.lead .figure { font-size: clamp(2.6rem, 7vw, 3.6rem); font-weight: 600; letter-spacing: -0.025em; line-height: 1.05; margin: 0.15rem 0 0.6rem; }
.lead .figure.negative { color: var(--bad); }
.delta { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 500; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--ink-2); }
.lead .flows { margin-top: 0.6rem; max-width: 60ch; }
.lead .note { margin-top: 0.85rem; font-size: 0.9rem; color: var(--ink-2); max-width: 64ch; }

.status { min-height: 1.2rem; color: var(--ink-2); }
.status.error { color: var(--bad); }
.status button { margin-left: 0.5rem; }

/* Movimientos como lista. */
.moves { padding-top: 1.75rem; }
.moves-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.filters { display: inline-flex; margin-left: auto; background: var(--page); border-radius: var(--radius-control); padding: 3px; }
.filters button { border: 0; background: none; padding: 0.3rem 0.8rem; border-radius: 8px; color: var(--ink-2); cursor: pointer; font-size: 0.9rem; }
.filters button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(18, 33, 43, 0.12); }
.move-list { list-style: none; margin: 0; padding: 0; }
.move { display: grid; grid-template-columns: 3.2rem 2rem minmax(0, 1fr) auto; align-items: center; gap: 0.75rem; padding: 0.7rem 0; border-top: 1px solid var(--grid); }
.move:first-child { border-top: 0; }
.move .day { color: var(--ink-2); font-size: 0.87rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.move .day b { display: block; color: var(--ink); font-size: 1.07rem; font-weight: 600; }
.move .kind { width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 1rem; }
.move .kind.in { background: color-mix(in srgb, var(--income) 14%, transparent); color: var(--income); }
.move .kind.out { background: color-mix(in srgb, var(--expense) 16%, transparent); color: var(--expense); }
.move .kind.inner { background: var(--grid); color: var(--ink-2); }
.move .what { min-width: 0; }
.move .what p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.move .what .cat { color: var(--ink-2); font-size: 0.87rem; }
.move .tag { font-size: 0.78rem; color: var(--warn); margin-left: 0.4rem; white-space: nowrap; }
.move .amount { font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.move .amount.in { color: var(--good); }
.empty { color: var(--ink-2); padding: 1rem 0; }
.move-list .more { padding: 0.9rem 0 0; border-top: 1px solid var(--grid); }

/* Por revisar. */
.todo-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: grid; gap: 0.9rem; }
.todo { display: grid; grid-template-columns: 1.25rem minmax(0, 1fr); gap: 0.55rem; }
.todo .mark { width: 1.25rem; height: 1.25rem; border-radius: 50%; border: 2px solid var(--warn); margin-top: 0.15rem; display: grid; place-items: center; color: var(--warn); font-size: 0.7rem; font-weight: 600; }
.todo .title { font-weight: 500; }
.todo .hint { color: var(--ink-2); font-size: 0.88rem; }
.all-clear { display: flex; gap: 0.5rem; align-items: center; color: var(--good); margin-top: 0.6rem; }
.count { color: var(--ink-2); font-weight: 400; }

/* Gastos por categoría: barras ordenadas, un solo tono. */
.spend { list-style: none; margin: 0.9rem 0 0; padding: 0; display: grid; gap: 0.8rem; }
.spend li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.2rem 0.75rem; }
.spend .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spend .value { font-variant-numeric: tabular-nums; font-weight: 500; }
.spend .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.spend .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--expense); }
.spend .share { color: var(--ink-2); font-weight: 400; margin-left: 0.4rem; }

/* Impuestos. */
.tax { margin-top: 0.75rem; display: grid; gap: 0.4rem; }
.tax dl { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 1rem; margin: 0.4rem 0 0; }
.tax dt { color: var(--ink-2); }
.tax dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }

/* Vista contable y descargas. */
.ledger-view { border-top: 1px solid var(--line); padding: 1.25rem 1.5rem 1.5rem; }
.ledger-view > summary { font-weight: 500; }
.ledger-view h3 { font-size: 0.98rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 14rem; }
th { font-weight: 500; color: var(--ink-2); background: var(--page); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.entry-start td { border-top: 1px solid var(--line); }
.downloads { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-top: 0.5rem; }
.tech { color: var(--ink-2); font-size: 0.87rem; padding-left: 1.1rem; }

/* Login. */
body.login { display: grid; place-items: center; padding: 1.25rem; }
.login-card { width: 100%; max-width: 400px; background: var(--sheet); border-radius: var(--radius-sheet); padding: 2rem 1.75rem 1.75rem; box-shadow: 0 1px 0 var(--line), 0 12px 32px -24px rgba(18, 33, 43, 0.35); }
.login-card .brand { margin-bottom: 1.5rem; }
.login-card h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; }
.login-card p.muted { margin: 0.35rem 0 1.5rem; }
.login-card form { display: grid; gap: 0.4rem; }
.login-card label { font-weight: 500; font-size: 0.93rem; margin-top: 0.5rem; }
.login-card input { padding: 0.65rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--page); }
.login-card input:focus-visible { outline-offset: 1px; }
.primary { margin-top: 1rem; background: var(--income); color: var(--on-accent); border: 0; border-radius: var(--radius-control); padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: 0.6; cursor: progress; }
.message { color: var(--bad); min-height: 1.4rem; margin-top: 0.5rem; }

/* En pantallas angostas lo pendiente sube justo después del resultado. */
@media (max-width: 900px) {
  .body { display: flex; flex-direction: column; }
  .main, .rail { display: contents; }
  .body section { padding: 1.5rem; border-top: 1px solid var(--line); }
  .body .lead { order: 1; border-top: 0; border-bottom: 0; }
  .body .todo-section { order: 2; }
  .body .moves { order: 3; }
  .body .spend-section { order: 4; }
  .body .tax-section { order: 5; }
}
@media (max-width: 560px) {
  .topbar { padding: 0.85rem 1rem 0.6rem; }
  .topbar .who { display: none; }
  .sheet { border-radius: 0; margin-bottom: 0; }
  .year, .ledger-view, .body section { padding-left: 1rem; padding-right: 1rem; }
  .legend { margin-left: 0; width: 100%; }
  .filters { margin-left: 0; }
  .move { grid-template-columns: 2.6rem 1.75rem minmax(0, 1fr) auto; gap: 0.6rem; }
  .move .kind { width: 1.75rem; height: 1.75rem; }
}
