/* Estructura y componentes. Los colores vienen de theme.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 var(--font-body);
}
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums lining-nums; }
.soft { color: var(--ink-soft); }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.shell { max-width: 1180px; margin: 0 auto; padding: 0 20px 64px; }

/* ── Barra superior ───────────────────────────────────────── */
.topnav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px;
  padding: 18px 0 14px; border-bottom: 2px solid var(--ink);
}
.brand {
  font: 700 1.375rem/1 var(--font-display); text-decoration: none; letter-spacing: -0.01em;
}
.tabs { display: flex; gap: 4px; flex: 1 1 auto; overflow-x: auto; }
.tabs a {
  padding: 7px 14px; border-radius: var(--radius); text-decoration: none;
  color: var(--ink-soft); font-weight: 500; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); background: var(--paper-deep); }
.tabs a[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }
.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tools form { margin: 0; }
.select, .input {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 7px 10px; min-height: 38px;
}
.select { text-transform: capitalize; }
.btn {
  background: transparent; border: 1px solid var(--ink); border-radius: var(--radius);
  padding: 7px 14px; min-height: 38px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.quiet { border-color: var(--rule); font-weight: 500; color: var(--ink-soft); }
.sync-btn .when-busy { display: none; }
.sync-btn.htmx-request .when-busy { display: inline; }
.sync-btn.htmx-request .when-idle { display: none; }
.sync-meta { font-size: .8125rem; color: var(--ink-soft); }
.sync-error { font-size: .8125rem; color: var(--bad); font-weight: 600; max-width: 34ch; display: inline-block; }

/* ── Títulos y secciones ──────────────────────────────────── */
h1, h2 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; line-height: 1.15; font-weight: 700; }
h2 { font-size: 1.0625rem; font-weight: 600; }
.section { margin-top: 44px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  border-top: 2px solid var(--ink); padding-top: 10px; margin-bottom: 14px;
}
.section-head .soft { font-size: .875rem; }

/* ── Semana: la regla de medir ────────────────────────────── */
.week { padding-top: 30px; }
.week-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 24px; }
.week-range { color: var(--ink-soft); margin: 0; }
.week-fig { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 14px 0 14px; }
.week-fig .big {
  font: 700 clamp(2.75rem, 8vw, 4.75rem)/1 var(--font-display); letter-spacing: -0.03em;
}
.week-fig .of { color: var(--ink-soft); font-size: 1.125rem; }

.ruler {
  position: relative; height: 64px; background: var(--paper-deep);
  border-radius: 3px; overflow: hidden; border-right: 1px solid var(--ink);
}
.ruler-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.ruler-fill.cuidado { background: var(--warn); }
.ruler-fill.pasado { background: var(--bad); }
.ruler::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px 10%) left bottom / 100% 26px no-repeat,
    repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 2%) left bottom / 100% 12px no-repeat;
  opacity: .55;
}
.ruler-marks {
  display: flex; justify-content: space-between; margin-top: 6px;
  font-size: .8125rem; color: var(--ink-soft);
}
.week-msg { margin: 14px 0 0; font-weight: 500; }
.week-msg strong { font-weight: 700; }
.week-msg.pasado { color: var(--bad); }
.week-msg.cuidado { color: var(--warn); }

/* ── Cifras del mes ───────────────────────────────────────── */
.figures { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 40px; border-top: 2px solid var(--ink); }
.fig { padding: 14px 24px 4px 0; display: flex; flex-direction: column; gap: 2px; }
.fig + .fig { padding-left: 24px; border-left: 1px solid var(--rule); }
.fig-label { color: var(--ink-soft); font-size: .9375rem; }
.fig-num { font: 700 clamp(1.5rem, 3.4vw, 2.125rem)/1.15 var(--font-display); letter-spacing: -0.02em; }
.fig-note { color: var(--ink-soft); font-size: .875rem; }

/* ── Columnas ─────────────────────────────────────────────── */
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 0 48px; }
.chart-box { position: relative; height: 270px; }

/* ── Listas con barras (categorías) ───────────────────────── */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bar-row a, .bar-row > div { display: block; text-decoration: none; }
.bar-line { display: flex; justify-content: space-between; gap: 12px; font-size: .9375rem; }
.bar-line span:first-child { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.bar-track { height: 6px; background: var(--paper-deep); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 2px; }
.bar-row a:hover .bar-line span:first-child { text-decoration: underline; }

/* ── Tablas ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
th {
  text-align: left; font-weight: 500; color: var(--ink-soft); font-size: .8125rem;
  padding: 6px 12px 8px 0; border-bottom: 1px solid var(--ink);
}
td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
th.right, td.right { padding-right: 0; text-align: right; }
td.fecha { white-space: nowrap; color: var(--ink-soft); width: 1%; }
td.detalle { max-width: 38ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .cat { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
td .orig { display: block; font-size: .75rem; color: var(--ink-soft); }
tr.pasado td { color: var(--ink-soft); }
tfoot td { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; padding-top: 12px; }

/* ── Filtros ──────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 16px; }
.filters .input { flex: 1 1 220px; min-width: 0; }

/* ── Avisos y estados vacíos ──────────────────────────────── */
.notice {
  border: 1px solid var(--rule); border-left: 4px solid var(--warn); background: var(--surface);
  padding: 14px 16px; border-radius: var(--radius); margin: 24px 0 0;
}
.notice.error { border-left-color: var(--bad); }
.notice p { margin: 0; }
.notice p + p { margin-top: 6px; color: var(--ink-soft); font-size: .9375rem; }
.empty { padding: 28px 0; color: var(--ink-soft); }
.empty strong { color: var(--ink); display: block; margin-bottom: 4px; }
code { background: var(--paper-deep); padding: 1px 6px; border-radius: 3px; font-size: .875em; }

/* ── Login ────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--rule);
  border-top: 4px solid var(--accent); border-radius: var(--radius); padding: 28px; display: grid; gap: 14px;
}
.login .brand { font-size: 1.75rem; }
.login label { display: grid; gap: 6px; font-weight: 500; }
.login .btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.login .err { color: var(--bad); font-weight: 600; margin: 0; }

/* ── Móvil ────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; }
  .cols > * + * { margin-top: 36px; }
  .figures { grid-template-columns: 1fr; }
  .fig, .fig + .fig { padding: 12px 0; border-left: 0; }
  .fig + .fig { border-top: 1px solid var(--rule); }
  .tools { width: 100%; }
  .tabs { order: 3; width: 100%; }
}
@media (max-width: 520px) {
  .shell { padding: 0 14px 48px; }
  td.detalle { max-width: 18ch; }
  .ruler { height: 52px; }
}
@media (prefers-reduced-motion: no-preference) {
  .ruler-fill { transition: width .6s cubic-bezier(.2, .7, .2, 1); }
}
