/* Centavo — paleta "libreta contable peruana"
   tinta:   #142B26 (verde tinta profundo)
   papel:   #F4F5F0
   sol:     #D8A13A (dorado, moneda)
   ahorro:  #2E7D5B
   exceso:  #BF4530
*/
:root {
  --ink: #142b26;
  --ink-soft: #3d554e;
  --paper: #f4f5f0;
  --card: #ffffff;
  --line: #e2e5dc;
  --sol: #d8a13a;
  --sol-deep: #b9821f;
  --good: #2e7d5b;
  --bad: #bf4530;
  --radius: 14px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Instrument Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
.muted { color: var(--ink-soft); font-weight: 400; font-size: 0.85em; }

/* ---------- Acceso ---------- */
.auth {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(170deg, var(--ink) 0%, #1d4038 100%);
  padding: 1.2rem;
}
.auth-card {
  background: var(--card); border-radius: 20px; padding: 2rem 1.6rem;
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.brand { text-align: center; margin-bottom: 1.4rem; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto .6rem;
  background: var(--sol); color: var(--ink);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 2.2rem; font-weight: 800;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15);
}
.brand h1 { font-family: var(--font-display); font-weight: 800; margin: 0; font-size: 1.9rem; }
.brand-sub { margin: .2rem 0 0; color: var(--ink-soft); font-size: .95rem; }

form label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .8rem; color: var(--ink-soft); }
form input[type="text"], form input[type="password"], form input[type="date"] {
  display: block; width: 100%; margin-top: .3rem;
  padding: .7rem .8rem; font-size: 1rem; font-family: var(--font-body);
  border: 1.5px solid var(--line); border-radius: 10px; background: #fbfbf9; color: var(--ink);
}
form input:focus { outline: 2px solid var(--sol); border-color: var(--sol); }

.btn-primary {
  width: 100%; padding: .85rem; border: none; border-radius: 12px;
  background: var(--ink); color: #fff; font-family: var(--font-display);
  font-size: 1.05rem; font-weight: 600; cursor: pointer;
}
.btn-primary:active { transform: scale(.98); }
.btn-primary.big { padding: 1rem; font-size: 1.15rem; margin-top: .4rem; }
.btn-secondary {
  padding: .6rem 1rem; border: 1.5px solid var(--ink); border-radius: 10px;
  background: transparent; color: var(--ink); font-weight: 600; cursor: pointer; font-family: var(--font-body);
}
.btn-danger {
  padding: .6rem 1rem; border: 1.5px solid var(--bad); border-radius: 10px;
  background: transparent; color: var(--bad); font-weight: 600; cursor: pointer; font-family: var(--font-body);
}
.link {
  background: none; border: none; color: var(--ink-soft); text-decoration: underline;
  margin-top: 1rem; cursor: pointer; font-size: .9rem; display: block; width: 100%; text-align: center;
  font-family: var(--font-body);
}
.error { color: var(--bad); font-size: .9rem; margin: .4rem 0; }

/* ---------- Estructura app ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--ink); color: #fff;
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem 1rem calc(.7rem);
  padding-top: calc(.7rem + env(safe-area-inset-top));
}
.topbar-brand { font-family: var(--font-display); font-weight: 800; letter-spacing: .02em; }
.topbar-user { font-size: .85rem; opacity: .85; }

.view { padding: 1rem 1rem 6rem; max-width: 560px; margin: 0 auto; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; padding: .55rem 0 .5rem; border: none; background: none;
  font-size: .68rem; font-weight: 600; color: var(--ink-soft); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  font-family: var(--font-body);
}
.tab-icon { font-size: 1.15rem; line-height: 1; }
.tab.active { color: var(--ink); }
.tab.active .tab-icon { color: var(--sol-deep); }

/* ---------- Registrar ---------- */
.amount-block {
  background: var(--ink); border-radius: var(--radius);
  padding: 1.1rem 1rem; margin-bottom: 1.1rem;
  display: flex; align-items: center; gap: .9rem;
}
#amount {
  flex: 1; background: transparent; border: none; color: #fff;
  font-family: var(--font-display); font-size: 2.6rem; font-weight: 800;
  text-align: right; width: 100%; min-width: 0;
}
#amount::placeholder { color: rgba(255,255,255,.35); }
#amount:focus { outline: none; }

.currency-toggle { display: inline-flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 3px; }
.currency-toggle.center { display: flex; width: fit-content; margin: 0 auto 1rem; background: var(--line); }
.cur-btn {
  border: none; background: transparent; color: rgba(255,255,255,.7);
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  padding: .35rem .8rem; border-radius: 999px; cursor: pointer;
}
.currency-toggle.center .cur-btn { color: var(--ink-soft); }
.cur-btn.active { background: var(--sol); color: var(--ink); }

.field-label { font-size: .85rem; font-weight: 600; color: var(--ink-soft); margin: .9rem 0 .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: .45rem .8rem; font-size: .9rem; cursor: pointer;
  font-family: var(--font-body); font-weight: 500;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.row-2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: .7rem; margin-top: 1rem; }

.today-box { margin-top: 1.6rem; }
.section-title {
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 800;
  margin: 1.4rem 0 .6rem; text-transform: uppercase; letter-spacing: .04em;
}

/* ---------- Listas de gastos ---------- */
.expense-list { display: flex; flex-direction: column; gap: .5rem; }
.date-group { font-size: .8rem; font-weight: 700; color: var(--ink-soft); margin: .8rem 0 .1rem; text-transform: uppercase; letter-spacing: .03em; }
.expense-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: .6rem .8rem; display: flex; align-items: center; gap: .7rem;
}
.expense-emoji { font-size: 1.3rem; }
.expense-info { flex: 1; min-width: 0; }
.expense-cat { font-weight: 600; font-size: .92rem; }
.expense-sub { color: var(--ink-soft); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-amt { font-family: var(--font-display); font-weight: 700; white-space: nowrap; }
.expense-actions { display: flex; gap: .3rem; }
.icon-btn {
  border: none; background: none; cursor: pointer; font-size: 1rem;
  color: var(--ink-soft); padding: .3rem;
}
.icon-btn:hover { color: var(--bad); }
.empty { color: var(--ink-soft); font-size: .9rem; text-align: center; padding: 1.2rem 0; }

/* ---------- Movimientos ---------- */
.month-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .8rem;
}
.month-nav button {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 10px;
  width: 2.4rem; height: 2.4rem; font-size: 1.3rem; cursor: pointer; color: var(--ink);
}
#month-label { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; text-transform: capitalize; }
.month-totals { display: flex; gap: .6rem; margin-bottom: 1rem; }
.total-pill {
  flex: 1; background: var(--ink); color: #fff; border-radius: 12px;
  padding: .6rem .8rem; text-align: center;
}
.total-pill .lbl { font-size: .7rem; opacity: .75; display: block; }
.total-pill .val { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }

/* ---------- Estadísticas ---------- */
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: .9rem;
}
.stat-card h3 { margin: 0 0 .6rem; font-family: var(--font-display); font-size: .95rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.big-number { font-family: var(--font-display); font-size: 2rem; font-weight: 800; }
.delta { font-weight: 700; font-size: .95rem; margin-top: .2rem; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.compare-row { display: flex; gap: .8rem; margin-top: .6rem; }
.compare-col { flex: 1; }
.compare-col .lbl { font-size: .75rem; color: var(--ink-soft); }
.compare-col .val { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }

.bar-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .45rem; }
.bar-label { width: 38%; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: var(--paper); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--sol); border-radius: 6px; min-width: 2px; }
.bar-val { font-size: .78rem; font-weight: 700; width: 5.2rem; text-align: right; font-variant-numeric: tabular-nums; }

svg.chart { width: 100%; height: auto; display: block; }
.chart-caption { font-size: .75rem; color: var(--ink-soft); text-align: center; margin-top: .3rem; }

/* ---------- Ajustes ---------- */
.cat-block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; margin-bottom: .6rem; }
.cat-head { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.cat-head .spacer { flex: 1; }
.sub-list { margin: .4rem 0 0 1.9rem; padding: 0; list-style: none; }
.sub-list li { display: flex; align-items: center; gap: .4rem; font-size: .88rem; padding: .15rem 0; color: var(--ink-soft); }
.inline-form { display: flex; gap: .5rem; margin: .6rem 0 1rem; }
.inline-form input { margin-top: 0 !important; }
.sub-add { display: flex; gap: .4rem; margin: .4rem 0 0 1.9rem; }
.sub-add input { flex: 1; padding: .35rem .5rem; font-size: .85rem; border: 1.5px solid var(--line); border-radius: 8px; }
.sub-add button { border: none; background: var(--paper); border-radius: 8px; padding: 0 .7rem; cursor: pointer; font-weight: 700; color: var(--ink); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 5.2rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .6rem 1.1rem; border-radius: 999px;
  font-size: .9rem; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

@media (prefers-reduced-motion: no-preference) {
  .view { animation: fadein .18s ease; }
  @keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
@media (min-width: 600px) {
  .view { padding-top: 1.6rem; }
}
