/* Gastos de Casa — mobile-first */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;      /* tarjetas / superficie de gráfico */
  --page: #f9f9f7;
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  --ingreso: #008300;
  --gasto: #e34948;
  --balance: #2a78d6;
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --ink-1: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --ingreso: #008300;
    --gasto: #e66767;
    --balance: #3987e5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink-1);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
}
main { max-width: 640px; margin: 0 auto; padding: 12px 12px 24px; }
h1 { font-size: 1.25rem; margin: 10px 4px 4px; }
h2 { font-size: 1rem; margin: 20px 4px 8px; color: var(--ink-2); font-weight: 600; }
a { color: var(--accent); text-decoration: none; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px; }
.topbar .hello { color: var(--muted); font-size: .85rem; }

/* Tarjetas */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.cards-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cards-3 .card { margin-bottom: 0; padding: 10px 8px; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.05rem; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.stat-value.pos, .delta.pos { color: var(--good); }
.stat-value.neg, .delta.neg { color: var(--bad); }
.delta { font-size: .72rem; margin-top: 2px; color: var(--muted); }

.hero { text-align: center; padding: 20px 14px; }
.hero .stat-value { font-size: 2rem; }
.hero .stat-label { font-size: .8rem; }

/* Gráficos */
.chart-box { position: relative; width: 100%; }
.chart-box.h220 { height: 220px; }
.chart-box.h180 { height: 180px; }
.chart-toggle { display: flex; gap: 6px; margin-bottom: 8px; }
.chart-toggle button {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 999px; padding: 4px 12px; font-size: .8rem;
}
.chart-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Listas de movimientos */
.day-header { font-size: .78rem; color: var(--muted); margin: 14px 6px 4px; font-weight: 600; }
.mov {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
  width: 100%; text-align: left; color: inherit; font: inherit; cursor: pointer;
}
.mov .emoji {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.mov .info { flex: 1; min-width: 0; }
.mov .concept { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov .meta { font-size: .75rem; color: var(--muted); }
.mov .amount { font-weight: 700; white-space: nowrap; font-size: .95rem; }
.mov .amount.ingreso { color: var(--good); }
.mov .amount.gasto { color: var(--ink-1); }

/* Barras por categoría (leyenda con etiquetas visibles) */
.cat-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: .85rem; }
.cat-row .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cat-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-row .val { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Formularios */
label { display: block; font-size: .8rem; color: var(--ink-2); margin: 10px 2px 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); color: var(--ink-1);
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 12px 16px; font-size: 1rem; font-weight: 600;
  background: var(--accent); color: #fff; cursor: pointer; width: 100%;
}
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.small { width: auto; padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg button {
  flex: 1; padding: 10px; border: none; background: transparent; color: var(--ink-2);
  font-size: .95rem; font-weight: 600; cursor: pointer;
}
.seg button.active.gasto { background: var(--gasto); color: #fff; }
.seg button.active.ingreso { background: var(--ingreso); color: #fff; }
.seg button.active.aporte { background: var(--ingreso); color: #fff; }
.seg button.active.retirada { background: var(--gasto); color: #fff; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  display: none; align-items: flex-end; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--page); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 16px 16px 24px;
  max-height: 92vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 4px; display: flex; justify-content: space-between; align-items: center; }
.modal h3 .close { background: none; border: none; font-size: 1.4rem; color: var(--muted); cursor: pointer; }

/* OCR */
.ocr-zone { display: flex; gap: 8px; margin: 12px 0 2px; }
.ocr-status { font-size: .8rem; color: var(--muted); margin: 6px 2px; min-height: 1em; }
.receipt-thumb { max-width: 96px; max-height: 96px; border-radius: 10px; border: 1px solid var(--border); }

/* Nav inferior */
nav.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface-1); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
nav.bottom a, nav.bottom button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .65rem; color: var(--muted); background: none; border: none; cursor: pointer;
  padding: 6px 0;
}
nav.bottom .icon { font-size: 1.3rem; line-height: 1; }
nav.bottom a.active { color: var(--accent); font-weight: 700; }
nav.bottom .add-btn .icon {
  background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.6rem; margin-top: -18px;
  box-shadow: 0 4px 10px rgba(0,0,0,.25);
}

/* Login */
.login-wrap { min-height: 85vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .logo { text-align: center; font-size: 3rem; margin-bottom: 4px; }
.error { color: var(--bad); font-size: .85rem; margin: 8px 2px; }

/* Toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 20px); z-index: 60;
  background: var(--ink-1); color: var(--page);
  padding: 10px 18px; border-radius: 999px; font-size: .85rem;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }

/* Ajustes */
.settings-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 4px;
  border-bottom: 1px solid var(--grid); font-size: .9rem;
}
.settings-item:last-child { border-bottom: none; }
.settings-item .grow { flex: 1; min-width: 0; }
.settings-item .sub { color: var(--muted); font-size: .75rem; }
.inactive { opacity: .45; }

table.simple { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.simple td { padding: 6px 4px; border-bottom: 1px solid var(--grid); }
table.simple td.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: .9rem; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .72rem; border: 1px solid var(--border); color: var(--ink-2); }
