/* Solo tema claro (pedido de Gabriel: el oscuro no lo usaría). */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #1a1d23;
  --muted: #6b7280;
  --line: #e7e9ee;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --accent-text: #ffffff;
  --out: #c4372d;
  --in: #16804a;
  --warn-bg: #fff6dc;
  --warn-text: #7a5300;
  --shadow: 0 6px 24px rgba(15, 20, 30, .12);
  --radius: 14px;
  --tabs-h: 60px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabs-h) + 80px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 24px 16px 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; }

button, input, select { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 24px 16px; }
.pad-x { padding: 0 16px; }
.err { color: var(--out); }
.ok { color: var(--in); }
[hidden] { display: none !important; }

/* ---------- barra superior: mes */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.app-title { font-size: 22px; font-weight: 750; letter-spacing: -.01em; }
.month-nav { display: flex; align-items: center; }
#month-label { font-size: 15px; font-weight: 600; min-width: 108px; text-align: center; }
.month-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; font-size: 24px; cursor: pointer;
}
.month-btn:active { background: var(--surface-2); }
body.no-month .month-nav { display: none; }
.top { min-height: calc(56px + env(safe-area-inset-top)); }

main { max-width: 720px; margin: 0 auto; }

/* ---------- navegación inferior */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabs a .ico { font-size: 18px; line-height: 1; }
.tabs a.active { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed; z-index: 6;
  right: max(16px, calc(50% - 344px));
  bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
  /* Semitransparente para no tapar lo que hay detrás. */
  background: rgba(37, 99, 235, .72); color: var(--accent-text);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(15, 20, 30, .18); cursor: pointer;
  transition: background .15s;
}
.fab:hover, .fab:focus-visible { background: rgba(37, 99, 235, .9); }
.fab svg { display: block; }
.fab:active { transform: scale(.95); }

/* ---------- sub-pestañas */

.subtabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 12px 16px 4px;
  scrollbar-width: none;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtabs a {
  flex: none; padding: 7px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 14px;
}
.subtabs a.active { background: var(--accent); color: var(--accent-text); }

/* ---------- tarjetas y totales */

.cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px 16px 0;
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.card span { font-size: 13px; color: var(--muted); }
.card b { font-size: 19px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card.out b { color: var(--out); }
.card.in b { color: var(--in); }

.hero { padding: 16px; display: flex; flex-direction: column; }
.hero span { color: var(--muted); font-size: 14px; }
.hero b { font-size: 30px; font-variant-numeric: tabular-nums; }
.hero small { color: var(--muted); }

.alert {
  display: block; margin: 16px 16px 0; padding: 12px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn-text); text-decoration: none;
}

.bars { list-style: none; margin: 0; padding: 0 16px; }
.bars li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 0;
}
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-val { font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.accounts { list-style: none; margin: 0; padding: 0 16px; }
.acc { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.acc b { font-variant-numeric: tabular-nums; }
.acc.parent { font-weight: 600; }
.acc.child { padding-left: 16px; color: var(--muted); font-size: 15px; }
.acc.child b { color: var(--text); font-weight: 500; }

/* ---------- movimientos */

.tx-list { list-style: none; margin: 0; padding: 0 16px; }
.tx {
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line); min-height: 58px;
}
.tx-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 8px 0; text-align: left; cursor: pointer;
}
.tx-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
div.tx-main { cursor: default; }
.tx-title { font-weight: 550; }
.tx-meta { font-size: 13px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tx-amt small { font-size: 12px; color: var(--muted); font-weight: 400; }
.tx-amt.out { color: var(--out); }
.tx-amt.in { color: var(--in); }
.tx-amt.neutral { color: var(--muted); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 500; padding: 1px 6px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); vertical-align: middle;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

.icon-btn {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 18px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- botones */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  text-decoration: none; cursor: pointer; font-weight: 550;
}
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--out); }
.btn:disabled { opacity: .6; }
.btn.grow { flex: 1; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; font-size: 14px; }
.link.danger { color: var(--out); }

/* ---------- hoja de carga rápida */

.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 94dvh; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(20, 24, 32, .35); }
.sheet form { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.sheet.small form { gap: 12px; }
.sheet.small h2 { margin: 0; text-transform: none; letter-spacing: 0; color: var(--text); font-size: 17px; }
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 20px; }
}

.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head .seg { flex: 1; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  font-size: 15px; font-weight: 550; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }

/* Cada paso: pregunta + respuesta */
.field { display: flex; flex-direction: column; gap: 6px; }
.field .q { font-size: 15px; font-weight: 600; color: var(--text); }
.date-field { flex-direction: row; align-items: center; justify-content: space-between; }
.date-field input { width: auto; }

.amount-row { display: flex; align-items: center; gap: 10px; }
.amount {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px;
  border-bottom: 2px solid var(--accent); padding: 2px;
}
.amount .cur { font-size: 22px; color: var(--muted); }
.amount-row .amount input {
  flex: 1; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 0; width: auto;
  background: transparent; outline: none;
  font-size: 34px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.pill {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--accent);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 550; cursor: pointer;
}
.fx-row { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.fx-row input { width: 90px; min-height: 36px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 13px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.more { border-style: dashed; color: var(--accent); }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 8px; }
input:not([type]), input[type="date"], input[type="password"], input[inputmode], select {
  min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 16px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.hint { margin: 0; font-size: 13px; padding: 8px 10px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); }
.sheet .err { margin: 0; }
.sheet-actions { display: flex; gap: 10px; }

/* ---------- toast */

.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + 90px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 650; cursor: pointer; padding: 4px; }
.toast button { color: #8fb0ff; }

/* ---------- ajustes */

.settings { padding: 0 16px; }
.settings h2 { margin-left: 0; margin-right: 0; }
.set-list { list-style: none; margin: 0; padding: 0; }
.set-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.set-list li.child { padding-left: 16px; }
.set-list li.archived > span:first-child { opacity: .5; text-decoration: line-through; }
.row-actions { display: flex; gap: 12px; flex: none; }
.inline-form { display: flex; align-items: flex-end; gap: 10px; }
.inline-form label { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; color: var(--text); }
.inline-form input { width: 110px; }
.export { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- login / instalación */

body.auth { padding: 0; min-height: 100dvh; display: grid; place-items: center; }
.auth-box { width: 100%; max-width: 360px; padding: 24px 16px; }
.auth-box h1 { margin-bottom: 16px; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- inicio: cuánto queda y cuánto aguanta la empresa */

.big-card {
  display: flex; flex-direction: column; gap: 6px; margin: 16px 16px 0; padding: 16px;
  border-radius: var(--radius); background: var(--accent-soft); color: var(--text); text-decoration: none;
}
.big-card > span:first-child { font-size: 14px; color: var(--muted); }
.big-card b { font-size: 32px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.big-card small { font-size: 14px; color: var(--muted); }
.big-card.over { background: #fdecea; }
.big-card.over b { color: var(--out); }
.big-card.setup b { font-size: 20px; color: var(--accent); }
.meter { display: block; height: 8px; background: rgba(37, 99, 235, .15); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.big-card.over .meter { background: rgba(196, 55, 45, .15); }
.big-card.over .meter i { background: var(--out); }

.runway {
  display: flex; flex-direction: column; gap: 4px; margin: 10px 16px 0; padding: 12px 14px;
  border-radius: var(--radius); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 15px;
}
.runway small { font-size: 12px; color: var(--muted); }
.runway.good b { color: var(--in); }
.runway.warn b { color: #b26b00; }
.runway.bad b { color: var(--out); }
.runway.setup { color: var(--muted); }
.runway.setup b { color: var(--accent); font-weight: 600; }

.stack-form { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.stack-form label { width: 100%; font-size: 14px; color: var(--text); }

/* ---------- fases 2 y 3 */

button.alert { width: calc(100% - 32px); text-align: left; border: 0; font: inherit; cursor: pointer; }
.alert.bad { background: #fdecea; color: var(--out); }
.badge.ok { background: #e6f4ec; color: var(--in); }
.badge.bad { background: #fdecea; color: var(--out); }
.back { display: inline-block; margin: 12px 16px 0; color: var(--accent); text-decoration: none; font-size: 15px; }

.chart { position: relative; height: 220px; margin: 0 16px; }
.chart.pie { height: 200px; }

.bar-avg { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.meter.over i { background: var(--out); }
.hero .meter { margin: 6px 0 2px; }

.tx > .btn.small { flex: none; }

/* reparto de un cobro */
.reparto { display: flex; flex-direction: column; gap: 12px; padding: 8px 16px 0; }
.step { display: flex; gap: 10px; align-items: flex-start; }
.step-n {
  flex: none; width: 26px; height: 26px; margin-top: 2px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 14px;
}
.step label { flex: 1; color: var(--text); font-size: 15px; }
.step small { font-size: 12px; color: var(--muted); }
.step.short .step-n { background: #fdecea; color: var(--out); }
.step small.err { color: var(--out); }
.reparto > label { color: var(--text); font-size: 15px; }
.reparto-sum { margin: 0; font-size: 14px; }
.reparto-sum.warn { color: #b26b00; }

/* equipos */
.assets { list-style: none; margin: 0; padding: 0 16px; }
.asset { display: flex; flex-direction: column; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.asset-head { display: flex; justify-content: space-between; gap: 8px; }
.asset small { font-size: 13px; color: var(--muted); }
.asset.retired { opacity: .55; }

/* reportes */
.year-nav { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 0 0; font-size: 18px; }
.table-wrap { overflow-x: auto; padding: 0 16px; }
table.report { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.report th, table.report td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.report th:first-child, table.report td:first-child { text-align: left; }
table.report th { font-weight: 600; color: var(--muted); font-size: 12px; }
h2 .link { float: right; text-transform: none; letter-spacing: 0; font-weight: 500; }

/* ajustes */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.grid-2 label { color: var(--text); font-size: 14px; }
.errors { margin: 0; padding-left: 20px; font-size: 13px; color: var(--out); }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }

/* ticket repartido */
.link.left { text-align: left; align-self: flex-start; }
.split-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.split-row { color: var(--text); font-size: 13px; }
.split-row input { min-height: 38px; }
.split-left { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.split-left.err { color: var(--out); }

/* 5 pestañas abajo */
.tabs a { font-size: 11px; }
