/* Diseño: columna única tipo formulario por pasos; el resultado se abre más ancho.
   Neutros azulados con acento verde azulado; ámbar y rojo solo para avisos y errores. */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #16202b;
  --muted: #566372;
  --line: #d6dde4;
  --accent: #0b5d63;
  --accent-ink: #ffffff;
  --accent-soft: #dcecee;
  --warn: #7a4a00;
  --warn-bg: #fbf1dc;
  --err: #a8201a;
  --err-bg: #fbe8e6;
  --ok: #1d6b3a;
  --ok-bg: #e2f3e8;
  --focus: #0b5d63;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --surface: #172027;
    --surface-2: #1e2a32;
    --ink: #e7edf1;
    --muted: #9aa8b4;
    --line: #2a3943;
    --accent: #5ec3ca;
    --accent-ink: #052a2d;
    --accent-soft: #15353a;
    --warn: #f1c46f;
    --warn-bg: #36290f;
    --err: #ff9188;
    --err-bg: #3b1916;
    --ok: #7fd49c;
    --ok-bg: #123221;
    --focus: #5ec3ca;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font);
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- cabecera y pasos ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
  padding-top: env(safe-area-inset-top, 0px); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1040px; margin: 0 auto; padding: 10px 16px 6px; }
.brand h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.005em; }
.brand p { font-size: 0.78rem; color: var(--muted); }
.top-actions { display: flex; gap: 2px; flex-shrink: 0; }
.btn-text { background: none; border: 0; color: var(--accent); font-size: 0.85rem; font-weight: 600;
  padding: 8px 8px; border-radius: 6px; cursor: pointer; }
.btn-text:hover { background: var(--accent-soft); }
.btn-text.armed { background: var(--warn-bg); color: var(--warn); }

.steps { display: flex; gap: 4px; max-width: 1040px; margin: 0 auto; padding: 4px 16px 10px; }
.steps button { flex: 1 1 0; min-width: 0; background: none; border: 0; border-top: 3px solid var(--line);
  padding: 6px 2px 0; text-align: left; cursor: pointer; color: var(--muted); font-size: 0.75rem; line-height: 1.2; }
.steps button .n { font-weight: 700; margin-right: 4px; font-variant-numeric: tabular-nums; }
.steps button .lbl { display: none; }
.steps button.done { border-top-color: var(--accent); color: var(--ink); }
.steps button.current { border-top-color: var(--accent); color: var(--accent); font-weight: 700; flex: 2.2 1 0; }
.steps button.current .lbl { display: inline; }
.steps button:disabled { cursor: default; }
@media (min-width: 640px) { .steps button .lbl { display: inline; } .steps button { font-size: 0.82rem; } }

/* ---------- contenido ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 18px 16px 24px; outline: none; }
.wrap.wide { max-width: 1040px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.page-title { font-size: 1.3rem; font-weight: 750; letter-spacing: -0.01em; }
.page-lead { color: var(--muted); margin-top: 4px; max-width: 62ch; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.card > h2 { font-size: 0.95rem; font-weight: 700; margin-bottom: 12px; }
.card .fields { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .lab { font-size: 0.86rem; font-weight: 600; }
.opt { font-weight: 400; color: var(--muted); font-size: 0.78rem; margin-left: 4px; }
.hint { font-size: 0.8rem; color: var(--muted); max-width: 62ch; }
.msg { font-size: 0.82rem; color: var(--err); font-weight: 600; display: none; }
.field.invalid .msg { display: block; }
.field.invalid input, .field.invalid select { border-color: var(--err); }

input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%; min-height: 44px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px; }
input::placeholder { color: var(--muted); opacity: 0.7; }
.row { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.row.eq { grid-template-columns: 1fr 1fr; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 380px) { .row.eq { grid-template-columns: 1fr; } }
.unit-input { position: relative; }
.unit-input span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.85rem; pointer-events: none; }
.unit-input input { padding-right: 44px; }

.check, .radio { display: flex; gap: 10px; align-items: flex-start; font-size: 0.92rem; padding: 4px 0; cursor: pointer; }
.check input, .radio input { width: 20px; height: 20px; margin: 1px 0 0; flex-shrink: 0; accent-color: var(--accent); }
.radios { display: flex; flex-direction: column; gap: 2px; }
.inline-day { display: flex; align-items: center; gap: 8px; margin: 2px 0 6px 30px; font-size: 0.88rem; }
.inline-day input { width: 76px; min-height: 40px; }

.sub { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }

/* ---------- vigencias ---------- */
.vig { display: grid; gap: 10px; }
.vig-row { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 10px; background: var(--surface-2); }
.vig-row .head { display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.vig-row.invalid { border-color: var(--err); }
.vig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .vig-grid { grid-template-columns: 1fr; } }
.vig-grid .full { grid-column: 1 / -1; }
.mini { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.status { border-radius: 8px; padding: 10px 12px; font-size: 0.88rem; }
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.bad { background: var(--err-bg); color: var(--err); }
.status.neutral { background: var(--surface-2); color: var(--muted); }
.status b { font-weight: 700; }

/* ---------- botones ---------- */
.btn { min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 6;
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.bar-in { max-width: 760px; margin: 0 auto; padding: 12px 16px; display: flex; gap: 10px; justify-content: space-between; }
.bar-in .btn { flex: 0 0 auto; }
.bar-in .btn.primary { flex: 1 1 auto; max-width: 340px; margin-left: auto; }
body.wide-bar .bar-in { max-width: 1040px; }

/* ---------- errores y avisos ---------- */
.errbox { background: var(--err-bg); color: var(--err); border-radius: 10px; padding: 12px 14px; font-size: 0.9rem; }
.errbox b { display: block; margin-bottom: 4px; }
.errbox ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.errbox a, .linklike { color: inherit; font-weight: 700; text-decoration: underline; background: none; border: 0; padding: 0; cursor: pointer; font-size: inherit; }
.warnbox { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 12px 14px; font-size: 0.88rem; }
.warnbox b { display: block; margin-bottom: 4px; }
.warnbox ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }

/* ---------- confirmación ---------- */
dl.kv { margin: 0; display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 7px 14px; font-size: 0.9rem; }
dl.kv dt { color: var(--muted); font-weight: 600; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dt { margin-top: 8px; font-size: 0.78rem; } }
.confirm { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; }

/* ---------- resultado ---------- */
.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.fig { padding: 14px 16px; min-width: 0; }
.fig + .fig { border-left: 1px solid var(--line); }
.fig .k { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.fig .v { font-size: 1.25rem; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.fig .v small { font-size: 0.7rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.fig.total { background: var(--accent-soft); border-radius: 0 10px 10px 0; }
.fig.total .v { color: var(--accent); font-size: 1.45rem; }
@media (max-width: 640px) {
  .figures { grid-template-columns: 1fr; }
  .fig + .fig { border-left: 0; border-top: 1px solid var(--line); }
  .fig.total { border-radius: 0 0 10px 10px; }
  .fig { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table.det { border-collapse: collapse; width: 100%; font-size: 0.84rem; font-variant-numeric: tabular-nums; }
.det th { text-align: left; background: var(--surface-2); font-size: 0.74rem; font-weight: 700; color: var(--muted); padding: 8px 10px; white-space: nowrap; position: sticky; top: 0; border-bottom: 1px solid var(--line); }
.det td { padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.det .r { text-align: right; }
.det tbody tr:last-child td { border-bottom: 0; }
.det td.per, .det th.per { position: sticky; left: 0; background: var(--surface); font-weight: 600; }
.det th.per { background: var(--surface-2); z-index: 1; }
.det .sm { display: block; font-size: 0.72rem; color: var(--muted); }
.det tr.future td { color: var(--muted); }
.det tr.future td.per { color: var(--muted); }
.det tfoot td { font-weight: 750; border-top: 2px solid var(--ink); border-bottom: 0; background: var(--surface-2); }
.det tfoot td.per { background: var(--surface-2); }
details.datos { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
details.datos > summary { padding: 12px 16px; font-weight: 700; cursor: pointer; font-size: 0.92rem; }
details.datos > .in { padding: 0 16px 16px; }
.legend { font-size: 0.8rem; color: var(--muted); max-width: 80ch; }

/* ---------- impresión ---------- */
@page { size: A4 landscape; margin: 12mm; }
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f1f1f1; --ink: #000; --muted: #444; --line: #bbb; --accent: #000; --accent-soft: #eee; --warn: #000; --warn-bg: #fff; --ok: #000; --ok-bg: #fff; }
  body { padding: 0; font-size: 11px; }
  .top, .bar, .toolbar, .noprint { display: none !important; }
  .wrap, .wrap.wide { max-width: none; padding: 0; }
  .tablewrap { overflow: visible; border: 0; }
  .det th { position: static; }
  .det td.per, .det th.per { position: static; }
  .card, .figures, details.datos { break-inside: avoid; }
  .warnbox { border: 1px solid #999; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

@media (max-width: 560px) {
  .brand h1 { font-size: 0.95rem; }
  .brand p { display: none; }
  .btn-text { padding: 8px 6px; font-size: 0.8rem; }
}

/* ======================= CuotalegalPy: cuentas y administración ======================= */
.brand h1 span { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; margin-inline: auto; }
.strong { font-weight: 700; font-size: 0.9rem; margin-bottom: 2px; }
.stack.narrow { max-width: 440px; margin-inline: auto; }
.msg.shown { display: block; }
.msg.ok { color: var(--ok); }

/* navegación principal */
.mainnav { display: flex; gap: 2px; max-width: 1040px; margin: 0 auto; padding: 0 12px 4px; overflow-x: auto; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav button { flex: 0 0 auto; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; font-weight: 600; font-size: 0.86rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.mainnav button:hover { color: var(--ink); }
.mainnav button.on { color: var(--accent); border-bottom-color: var(--accent); }
.mainnav .out { margin-left: auto; }

/* pantallas fuera de la calculadora */
body:not([data-screen="calc"]) .steps,
body:not([data-screen="calc"]) .bar,
body:not([data-screen="calc"]) #calc-actions { display: none; }
body:not([data-screen="calc"]) { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
body[data-screen="admin"] .wrap, body[data-screen="history"] .wrap { max-width: 900px; }

.login-brand { text-align: center; padding: 18px 0 4px; }
.login-brand h2 { font-size: 1.9rem; letter-spacing: -0.02em; font-weight: 800; }
.login-brand h2 span { color: var(--accent); }
.login-brand p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

/* listas */
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; min-width: 0; }
.item-main { flex: 1 1 280px; min-width: 0; }
.item-title { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; overflow-wrap: anywhere; }
.item-meta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.item-figs { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 0.86rem; color: var(--muted); }
.item-figs b { color: var(--ink); }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 0 1 auto; }

.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--err-bg); color: var(--err); border-color: transparent; }
.chip.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 14px; font-weight: 700; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters select, .filters input { flex: 1 1 200px; min-width: 0; min-height: 44px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.filters select { appearance: none; -webkit-appearance: none; }

.creds { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.creds h2 { font-size: 0.98rem; }
.creds code { font: 600 1.05rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.04em; user-select: all; }
input[type="password"], input[type="search"] { width: 100%; min-height: 44px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; appearance: none; -webkit-appearance: none; }
input[type="password"]:focus-visible, input[type="search"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.stack > div:empty { display: none; }
body[data-screen="login"] .top, body[data-screen="boot"] .top { display: none; }
