:root {
  --bg: #f6eddf;
  --surface: #fffaf2;
  --surface-2: #f1e4d0;
  --ink: #2a190c;
  --ink-2: #5c4430;
  --muted: #806650;
  --line: #e2cfb4;
  --accent: #9a4c12;
  --accent-ink: #fffaf2;
  --accent-soft: #f3dcc0;
  --focus: #c76a1f;
  --ok: #276b3f;
  --ok-soft: #dcefe2;
  --warn: #8a5300;
  --warn-soft: #fbe9c7;
  --err: #a8241b;
  --err-soft: #f8dcd8;
  --bar: #b0601f;
  --shadow: 0 1px 0 rgba(90, 50, 20, .06), 0 8px 24px -12px rgba(90, 50, 20, .25);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", var(--font);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17100a;
    --surface: #221810;
    --surface-2: #2c2016;
    --ink: #f5ead9;
    --ink-2: #dbc8b0;
    --muted: #b09a82;
    --line: #3b2c1f;
    --accent: #e39a52;
    --accent-ink: #1d1209;
    --accent-soft: #3d2a18;
    --focus: #f0b170;
    --ok: #7fcf98;
    --ok-soft: #1d3324;
    --warn: #f2c06b;
    --warn-soft: #3a2c12;
    --err: #ff9d92;
    --err-soft: #3d1d19;
    --bar: #d98c47;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px 10px 12px 12px;
  background: linear-gradient(160deg, #c47a35, #8a4310);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.18), inset 0 3px 0 rgba(255,255,255,.25);
  display: grid; place-items: center;
  color: #fff6e8; font: 800 13px/1 var(--font-display); letter-spacing: .02em;
}
.brand-name { font: 700 17px/1.1 var(--font-display); }
.brand-name small { display: block; font: 500 12px/1.2 var(--font); color: var(--muted); }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a, .nav button {
  min-height: 40px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid transparent; background: none; cursor: pointer;
  color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 15px;
}
.nav a:hover, .nav button:hover { background: var(--surface-2); }
.nav .who { color: var(--muted); font-size: 14px; padding: 0 4px; }

/* ---------- Status bar ---------- */
.statusbar { display: grid; gap: 6px; padding: 8px 16px 0; max-width: 1100px; margin: 0 auto; }
.pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; font-size: 14px; font-weight: 600;
}
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Layout ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 12px 16px 48px; display: grid; gap: 16px; }
@media (min-width: 900px) {
  .wrap.two { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
  .wrap.two > .side { position: sticky; top: 76px; }
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
h1, h2 { font-family: var(--font-display); margin: 0; }
h2 { font-size: 17px; }

/* ---------- Fecha / semana ---------- */
.when {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center;
  padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px dashed var(--line);
}
.week-stamp {
  width: 76px; height: 76px; border-radius: 50%;
  border: 2px solid var(--accent); color: var(--accent);
  display: grid; place-content: center; text-align: center;
  background: var(--accent-soft);
}
.week-stamp .lbl { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.week-stamp .num { font: 800 30px/1 var(--font-display); }
.week-stamp .of { font-size: 11px; font-weight: 600; opacity: .8; }
.week-stamp.bad { border-color: var(--err); color: var(--err); background: var(--err-soft); }
.when-date { display: grid; gap: 6px; min-width: 0; }
.when-date .long { font: 700 19px/1.2 var(--font-display); }
.when-date .long::first-letter { text-transform: uppercase; }
.date-row { grid-column: 1 / -1; display: flex; gap: 6px; align-items: stretch; }
.date-row input[type="date"] {
  flex: 1; min-width: 0; min-height: 44px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.icon-btn {
  min-width: 44px; min-height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
  font-size: 18px; font-weight: 700; color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--accent); }
.when-warn { font-size: 13px; color: var(--warn); font-weight: 600; }
.when-warn.err { color: var(--err); }

/* ---------- Form ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; position: relative; }
.field > label, .field > .label { font-weight: 700; font-size: 14px; color: var(--ink-2); letter-spacing: .01em; }
.input {
  width: 100%; min-height: 56px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 20px;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.input.num { font: 700 28px/1 var(--font-display); text-align: center; font-variant-numeric: tabular-nums; }
.input.invalid { border-color: var(--err); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 13px; color: var(--muted); min-height: 18px; }
.hint.err { color: var(--err); font-weight: 600; }

.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% - 2px); z-index: 20;
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 50vh; overflow-y: auto;
}
.combo-list li {
  padding: 12px 12px; border-radius: 8px; cursor: pointer; font-size: 18px;
}
.combo-list li[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.combo-list li.empty { cursor: default; color: var(--muted); font-size: 15px; }
.combo-list mark { background: none; color: inherit; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }

.totals {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 2px 14px; color: var(--ink-2); font-size: 15px;
}
.totals b { font: 800 20px/1 var(--font-display); color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 18px; border-radius: 12px;
  border: 2px solid transparent; cursor: pointer;
  font-weight: 800; font-size: 17px; text-decoration: none;
}
.btn-primary { width: 100%; min-height: 60px; font-size: 20px; background: var(--accent); color: var(--accent-ink); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.btn-primary:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 rgba(0,0,0,.18); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--accent); }

.msg { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 15px; }
.msg.error { background: var(--err-soft); color: var(--err); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }

.kbd-hint { margin-top: 10px; font-size: 12px; color: var(--muted); text-align: center; }
@media (pointer: coarse) { .kbd-hint { display: none; } }

/* ---------- Recientes ---------- */
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.list-head .sub { font-size: 13px; color: var(--muted); }
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.feed li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid transparent;
}
.feed li.mine { border-color: var(--line); background: var(--surface); }
.feed li.fresh { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--ok-soft); } }
.feed .p { font-weight: 800; font-size: 16px; overflow-wrap: anywhere; }
.feed .money { font: 800 18px/1.2 var(--font-display); text-align: right; font-variant-numeric: tabular-nums; }
.feed .units { font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.feed .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.feed .actions { grid-column: 2; grid-row: 2 / span 2; align-self: end; justify-self: end; }
.tag { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; }
.tag.pend { background: var(--warn-soft); color: var(--warn); }
.tag.me { background: var(--accent-soft); color: var(--accent); }
.undo {
  min-height: 40px; padding: 6px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); font-weight: 700; font-size: 14px;
}
.undo:hover { border-color: var(--err); color: var(--err); }
.undo.confirm { background: var(--err); border-color: var(--err); color: #fff; }
.empty-state { padding: 24px 8px; text-align: center; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 14px 22px; border-radius: 99px; font-weight: 800; font-size: 18px;
  background: var(--ok); color: #fff; box-shadow: var(--shadow);
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--warn); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast { color: #10200f; }
  :root:not([data-theme="light"]) .toast.warn { color: #2a1b00; }
}

/* ---------- Dialog ---------- */
dialog {
  width: min(460px, calc(100vw - 32px)); padding: 0; border: none; border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(30, 15, 5, .5); }
.dlg { padding: 20px; display: grid; gap: 14px; }
.dlg h2 { font-size: 20px; }
.dlg ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.dlg li { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--ink); font-size: 15px; }
.dlg li b { color: var(--warn); }
.dlg .btn-dlg { min-height: 52px; font-size: 17px; }
.dlg .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(400px, 100%); }
.login .brand { margin-bottom: 18px; }
.login .brand-mark { width: 48px; height: 48px; font-size: 16px; }
.login .brand-name { font-size: 22px; }

/* ---------- Resumen ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 759px) {
  .kpi:not(.hero) { padding: 12px; }
  .kpi:not(.hero) .v { font-size: 22px; }
  .kpi:not(.hero) .k { font-size: 11px; }
  .kpi:not(.hero) .s { font-size: 12px; }
}
@media (min-width: 760px) { .kpis { grid-template-columns: 1.4fr 1fr 1fr 1fr; } }
.kpi { padding: 14px 16px; }
.kpi .k { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font: 800 26px/1.15 var(--font-display); margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .s { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.kpi.hero { grid-column: 1 / -1; background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.kpi.hero .k, .kpi.hero .s { color: inherit; opacity: .85; }
.kpi.hero .v { font-size: 36px; }
@media (min-width: 760px) { .kpi.hero { grid-column: auto; } }

.section-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { min-height: 36px; padding: 4px 12px; border: none; border-radius: 8px; background: none; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.chart { position: relative; }
.bars {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px;
  align-items: end; height: 220px; padding-top: 22px;
  border-bottom: 1px solid var(--line);
  background-image: linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% 25%; background-position: 0 22px;
  background-clip: content-box;
}
.bar-col { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: default; outline: none; }
.bar-col .bar {
  width: min(28px, 70%); min-height: 0; border-radius: 4px 4px 0 0; background: var(--bar);
  transition: height .35s ease;
}
.bar-col .val { font-size: 11px; font-weight: 700; color: var(--ink-2); margin-bottom: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-col:hover .bar, .bar-col:focus-visible .bar, .bar-col.active .bar { filter: brightness(1.12); }
.bar-col.zero .val { color: var(--muted); }
.xaxis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; margin-top: 6px; }
.xaxis span { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.xaxis span.now { color: var(--ink); font-weight: 800; }
.tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 150px; padding: 8px 10px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 13px; line-height: 1.45;
  box-shadow: var(--shadow); transform: translate(-50%, -100%);
}
.tip b { font-size: 14px; }
details.table-view { margin-top: 14px; }
details.table-view summary { cursor: pointer; font-weight: 700; color: var(--ink-2); font-size: 14px; }
table.t { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.search { min-height: 48px; font-size: 17px; }
.rank { list-style: none; margin: 12px 0 0; padding: 0; display: grid; }
.rank li {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 2px 10px; align-items: center;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.rank .pos { font: 800 15px/1 var(--font-display); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rank li:nth-child(-n+3):not(.zero) .pos { color: var(--accent); }
.rank .name { font-weight: 700; overflow-wrap: anywhere; }
.rank .money { font: 800 17px/1.2 var(--font-display); text-align: right; font-variant-numeric: tabular-nums; }
.rank .units { grid-column: 2; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank .track { grid-column: 2 / 4; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.rank .track i { display: block; height: 100%; border-radius: 99px; background: var(--bar); }
.rank li.zero .name, .rank li.zero .money { color: var(--muted); font-weight: 600; }
.foot-note { font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
