/* FinanzasDOT — mobile first, pensado para iPhone instalado como app */
/* Paleta de marca: negro #1D1D1B (principal), amarillo #FFED00, violeta #63318A */
:root {
  --black: #1d1d1b;
  --yellow: #ffed00;
  --purple: #63318a;

  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #ecebe6;
  --ink: #1d1d1b;
  --ink-2: #5c5b56;
  --ink-3: #8f8e88;
  --line: #e2e0d9;
  --brand: #1d1d1b;        /* botones y elementos principales */
  --brand-ink: #ffed00;    /* texto sobre --brand */
  --accent: #63318a;       /* enlaces, avance, seleccionado */
  --accent-ink: #ffffff;
  --accent-soft: #ece3f4;
  --hero-bg: #1d1d1b;
  --hero-ink: #ffffff;
  --hero-big: #ffed00;
  --warn: #6e5b00;
  --warn-soft: #fff6b0;
  --danger: #c0392b;
  --danger-soft: #f9e0dc;
  --ok: #63318a;
  --ok-soft: #ece3f4;
  /* colores del desglose */
  --c-fixed: #8b5cc0;
  --c-personal: #c9b3e3;
  --c-inst: #9b9a93;
  --c-save: #ffed00;
  --c-free: #ffffff;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(29, 29, 27, .05), 0 4px 16px rgba(29, 29, 27, .05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1d1d1b;
    --surface-2: #2a2a27;
    --ink: #f4f3ee;
    --ink-2: #b3b2ab;
    --ink-3: #7d7c76;
    --line: #33322e;
    --brand: #ffed00;
    --brand-ink: #1d1d1b;
    --accent: #b48be0;
    --accent-ink: #1d1d1b;
    --accent-soft: #2e2240;
    --hero-bg: #63318a;
    --hero-ink: #ffffff;
    --hero-big: #ffed00;
    --warn: #ffed00;
    --warn-soft: #36330f;
    --danger: #ff7a6b;
    --danger-soft: #3d201c;
    --ok: #b48be0;
    --ok-soft: #2e2240;
    --c-fixed: #d2b8f0;
    --c-personal: #9d79c4;
    --c-inst: #8a8983;
    --c-save: #ffed00;
    --c-free: #ffffff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  padding-bottom: calc(84px + var(--safe-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.hidden { display: none !important; }

/* ---------- Encabezado ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  display: flex; align-items: center; gap: 8px;
}
.topbar h1 { font-size: 28px; font-weight: 750; flex: 1; }
.topbar .sub { display: block; font-size: 13px; color: var(--ink-3); font-weight: 500; letter-spacing: 0; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
  cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch button { background: none; border: 0; color: var(--accent); font-size: 22px; padding: 4px 8px; cursor: pointer; }
.month-switch button:disabled { color: var(--ink-3); opacity: .4; }

main { padding: 4px 16px 16px; max-width: 560px; margin: 0 auto; }
section { margin-top: 22px; }
.section-title {
  font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); margin: 0 4px 8px; display: flex; justify-content: space-between; align-items: baseline;
}
.section-title a, .section-title button { text-transform: none; letter-spacing: 0; font-size: 15px; font-weight: 600; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px;
}
.card + .card { margin-top: 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; color: var(--ink-3); }

.hero {
  background: var(--hero-bg); color: var(--hero-ink); border: 0;
  padding: 20px 18px 18px; border-radius: 22px;
}
.hero .label { font-size: 14px; opacity: .85; font-weight: 550; }
.hero .big { color: var(--hero-big); font-size: 44px; font-weight: 780; letter-spacing: -.03em; line-height: 1.05; margin: 4px 0 6px; }
.hero .meta { font-size: 14px; opacity: .9; }
.hero.negative { background: var(--danger); }
.hero.negative .big { color: #fff; }

/* barra apilada del destino del ingreso */
.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); margin: 14px 0 10px; }
.stack span { display: block; height: 100%; }
.hero .stack { background: rgba(255,255,255,.2); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.hero .legend { color: inherit; opacity: .92; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }

/* ---------- Listas ---------- */
.list { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; min-height: 56px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .emoji { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .detail { font-size: 13px; color: var(--ink-3); }
.row .amount { font-weight: 650; white-space: nowrap; }
.row.tappable { cursor: pointer; }
.row.tappable:active { background: var(--surface-2); }
.row.done .title, .row.done .amount { color: var(--ink-3); }
.row.done .title { text-decoration: line-through; }
.empty { padding: 22px 16px; text-align: center; color: var(--ink-3); font-size: 15px; }

.kv { display: flex; justify-content: space-between; padding: 7px 0; gap: 12px; }
.kv + .kv { border-top: 1px dashed var(--line); }
.kv.total { border-top: 1px solid var(--ink-3); font-weight: 700; margin-top: 4px; padding-top: 10px; }
.kv .neg { color: var(--ink-2); }

/* ---------- Pastillas de estado ---------- */
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.pill.pagado { background: var(--ok-soft); color: var(--ok); }
.pill.vencido { background: var(--danger-soft); color: var(--danger); }
.pill.hoy, .pill.pronto { background: var(--warn-soft); color: var(--warn); }
.pill.pendiente { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Progreso ---------- */
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 14px; border: 0;
  font: inherit; font-weight: 650; cursor: pointer;
  background: var(--brand); color: var(--brand-ink);
}
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 2px 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 17px; /* 17px evita el zoom automático de iOS */
  padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; margin: 4px 0 12px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); -webkit-appearance: auto; appearance: auto; }

/* input de monto dentro de una fila */
.amount-input {
  width: 128px; text-align: right; font-weight: 650; padding: 8px 10px; font-size: 17px;
  background: var(--surface-2); border-color: transparent;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; font: inherit; font-size: 14px; font-weight: 600; padding: 8px 6px; border-radius: 9px; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Avisos ---------- */
.notice { border-radius: 14px; padding: 12px 14px; font-size: 14px; margin-top: 12px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--surface-2); color: var(--ink-2); }
.notice b { color: inherit; }

/* ---------- Pasos (Armar el mes) ---------- */
.step-head { display: flex; align-items: center; gap: 10px; margin: 26px 4px 10px; }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 750; font-size: 14px; flex: none; }
.step-head h2 { font-size: 19px; flex: 1; }
.step-head .step-total { font-weight: 650; color: var(--ink-2); }
.group-label { font-size: 13px; font-weight: 650; color: var(--ink-3); margin: 14px 6px 6px; }

.sticky-result {
  position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-bottom)); z-index: 9;
  padding: 10px 16px; pointer-events: none;
}
.sticky-result .inner {
  max-width: 528px; margin: 0 auto; pointer-events: auto;
  background: var(--hero-bg); color: var(--hero-ink); border-radius: 16px; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.sticky-result .inner.negative { background: var(--danger); color: #fff; }
.sticky-result b { font-size: 22px; letter-spacing: -.02em; color: var(--hero-big); }
.sticky-result .inner.negative b { color: #fff; }
body.has-sticky { padding-bottom: calc(160px + var(--safe-bottom)); }

/* ---------- Gráfico de barras de cuotas ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; margin-top: 12px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars .bar i { display: block; width: 100%; background: var(--accent); border-radius: 6px 6px 3px 3px; min-height: 3px; }
.bars .bar.now i { background: var(--brand); }
.bars .bar small { font-size: 11px; color: var(--ink-3); }
.bars .bar em { font-style: normal; font-size: 10px; color: var(--ink-2); font-weight: 600; }

/* ---------- Barra de navegación inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 600; color: var(--ink-3); padding: 4px 0; }
.tabbar a svg { width: 25px; height: 25px; }
.tabbar a.on { color: var(--accent); }

/* ---------- Hoja inferior (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; opacity: 0; transition: opacity .2s; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .25s ease;
  max-width: 600px; margin: 0 auto;
}
.sheet.open { transform: none; }
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { font-size: 20px; margin-bottom: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); z-index: 60;
  transform: translateX(-50%) translateY(20px); opacity: 0; transition: all .25s;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- Login ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: calc(var(--safe-top) + 48px) 20px 40px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 18px; }
.auth h1 { font-size: 30px; margin-bottom: 6px; }
.auth p { color: var(--ink-2); margin: 0 0 24px; }
.auth fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.auth legend { font-weight: 700; margin-bottom: 10px; }

.tip { display: flex; gap: 12px; align-items: flex-start; }
.tip .emoji { font-size: 22px; line-height: 1; }
.tip p { margin: 2px 0 0; font-size: 14px; color: var(--ink-2); }

details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
