:root {
  --primary: #2563EB;
  --primary-soft: #DBEAFE;
  --green: #10B981;
  --red: #EF4444;
  --amber: #F59E0B;
  --violet: #8B5CF6;
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --surface-variant: #F1F5F9;
  --text: #0F172A;
  --muted: #64748B;
  --outline: #E2E8F0;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
  --chart-1: #EF4444; --chart-2: #F59E0B; --chart-3: #8B5CF6; --chart-4: #0EA5E9;
  --chart-5: #14B8A6; --chart-6: #6366F1; --chart-7: #EC4899; --chart-8: #F97316;
  --chart-9: #3B82F6; --chart-10: #84CC16; --chart-11: #64748B; --chart-12: #22C55E;
}

/* Tema oscuro: se puede forzar (Ajustes → Apariencia) o seguir al teléfono.
   Los valores oscuros se aplican una vez, sin duplicar: con [data-theme="oscuro"]
   siempre, y con el sistema cuando el tema es "automático". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='claro']) {
    --bg: #0B1120;
    --surface: #1E293B;
    --surface-variant: #334155;
    --text: #E2E8F0;
    --muted: #94A3B8;
    --outline: #475569;
    --primary-soft: #1E3A8A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

:root[data-theme='oscuro'] {
  --bg: #0B1120;
  --surface: #1E293B;
  --surface-variant: #334155;
  --text: #E2E8F0;
  --muted: #94A3B8;
  --outline: #475569;
  --primary-soft: #1E3A8A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

body { padding-bottom: env(safe-area-inset-bottom); }

button { font: inherit; color: inherit; }

.view {
  padding: max(env(safe-area-inset-top), 12px) 14px calc(96px + env(safe-area-inset-bottom)) 14px;
  max-width: 720px;
  margin: 0 auto;
}

.screen { display: flex; flex-direction: column; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------------------------------------------------------------- cabecera */

.app-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.app-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.5px; }
.app-head p { margin: 2px 0 0; font-size: 14px; }
.head-actions { display: flex; gap: 2px; }

.icon-btn {
  border: 0; background: transparent; padding: 8px; border-radius: 12px;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.icon-btn:active { background: var(--surface-variant); }

h2, h3, h4 { margin: 0; }
h3 { font-size: 16px; }
h4.day-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 6px 2px 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.big { font-size: 17px; }
.huge { font-size: 30px; letter-spacing: -0.8px; }
.note { font-size: 12.5px; color: var(--primary); margin: 6px 0 0; }
.note.warn { color: var(--amber); }
.body-text { font-size: 15px; margin: 0; }
.link {
  border: 0; background: transparent; color: var(--primary); font-size: 13px;
  font-weight: 600; padding: 6px 2px; cursor: pointer;
}
.link.danger { color: var(--red); }

/* ------------------------------------------------------------------ tarjetas */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-head p { margin: 2px 0 0; font-size: 13px; }

.gradient-card {
  background: linear-gradient(135deg, #1D4ED8, #2563EB 55%, #0EA5E9);
  color: #fff;
  box-shadow: 0 10px 30px rgba(37, 99, 235, .28);
}
.gradient-card .muted, .gradient-card .tiny { color: rgba(255, 255, 255, .82); }
.big-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.mini-row { display: flex; gap: 8px; margin-top: 6px; }
.mini {
  flex: 1; background: rgba(255, 255, 255, .16); border-radius: 12px; padding: 8px 10px;
  display: flex; flex-direction: column; overflow: hidden;
}
.mini .small { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }
.stat-grid.three .huge { font-size: 22px; }
.stat-grid.three .stat-value { font-size: 15px; }
.stat-grid.three .stat-label { font-size: 11px; }
.stat {
  background: var(--surface); border-radius: 16px; padding: 12px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
  overflow: hidden;
}
.stat-label { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; padding: 10px 0; text-align: left;
}
.row.clickable:active { background: var(--surface-variant); border-radius: 12px; }
.row-emoji { font-size: 18px; width: 26px; text-align: center; }
.row-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.row-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-right { display: flex; flex-direction: column; align-items: flex-end; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.total-row { border-top: 1px solid var(--outline); padding-top: 10px; margin-top: 4px; }

.chips-row, .chips-wrap { display: flex; gap: 8px; flex-wrap: wrap; }
.chips-row { overflow-x: auto; padding-bottom: 2px; flex-wrap: nowrap; }
.chip {
  border: 1px solid var(--outline); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.quick-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.quick-row .chip { padding: 9px 4px; font-size: 12px; text-align: center; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-variant); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .25s ease; }
.mini-progress { display: flex; flex-direction: column; gap: 6px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 10px; text-align: center; }
.empty-icon { font-size: 26px; }
.empty p { margin: 0; font-size: 13px; }

.dot { width: 10px; border-radius: 3px; height: 10px; display: inline-block; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-name { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.donut-wrap { position: relative; display: flex; justify-content: center; padding: 6px 0; }
.donut { width: 190px; height: 190px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.donut-center strong { font-size: 19px; }
.donut-center span { font-size: 12px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; height: 100%; }
.bar { width: 9px; border-radius: 4px 4px 0 0; }
.bar.income { background: var(--green); }
.bar.expense { background: var(--red); }
.bar-label { font-size: 10px; color: var(--muted); }

.table { display: flex; flex-direction: column; gap: 2px; }
.table-row {
  display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 6px;
  font-size: 13px; padding: 5px 0; border-bottom: 1px solid var(--surface-variant);
}
.table-row.head { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border: 0; }

.strategy { background: var(--surface-variant); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.budget-item { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--surface-variant); }
.inline-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.month-selector { display: flex; align-items: center; justify-content: space-between; }
.month-label { border: 0; background: transparent; font-size: 17px; font-weight: 600; cursor: pointer; }

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

.btn {
  border: 1px solid var(--outline); background: var(--surface); color: var(--text);
  border-radius: 14px; padding: 13px 16px; font-weight: 600; cursor: pointer; flex: 1;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: var(--surface-variant); }
.btn.small-btn { padding: 9px 14px; font-size: 13px; flex: 0 0 auto; }
.btn:disabled { opacity: .6; }

.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--primary); color: #fff; font-size: 26px; cursor: pointer;
  box-shadow: 0 10px 24px rgba(37, 99, 235, .35); z-index: 20;
}

/* ----------------------------------------------------------- barra inferior */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--outline);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; border: 0; background: transparent; padding: 8px 2px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.nav-icon { font-size: 18px; }
.nav-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.nav-item.active .nav-label { color: var(--primary); font-weight: 700; }

/* ------------------------------------------------------------------ campos */

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field > span { color: var(--muted); font-size: 12px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--outline); border-radius: 12px;
  padding: 13px 14px; font-size: 16px; background: var(--surface-variant); color: var(--text);
}
.field input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.switch-row { flex-direction: row; align-items: center; justify-content: space-between; }
.switch-row input { width: auto; }
.hidden-input { display: none; }

.amount-wrap { display: flex; align-items: center; gap: 6px; background: var(--surface-variant); border: 1px solid var(--outline); border-radius: 12px; padding-left: 12px; }
.amount-wrap input { border: 0; background: transparent; padding: 13px 12px 13px 0; }
.amount-wrap .prefix { color: var(--muted); }

.picker {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--outline); border-radius: 12px; padding: 14px;
  background: var(--surface-variant); text-align: left; cursor: pointer;
}
.picker .chevron { color: var(--muted); }
.segmented { display: flex; gap: 8px; }
.segmented-item {
  flex: 1; border: 1px solid var(--outline); background: var(--surface-variant);
  border-radius: 12px; padding: 12px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer;
}
.segmented-item.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.receipt-img { width: 100%; border-radius: 12px; max-height: 240px; object-fit: cover; }

/* --------------------------------------------------------- hojas y avisos */

.sheet-host, .toast-host { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.sheet-overlay {
  position: absolute; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-end; opacity: 0; transition: opacity .18s ease;
  pointer-events: auto;
}
.sheet-overlay.visible { opacity: 1; }
.sheet-panel {
  width: 100%; max-width: 720px; margin: 0 auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; display: flex; flex-direction: column; gap: 10px;
  transform: translateY(14px); transition: transform .18s ease;
}
.sheet-overlay.visible .sheet-panel { transform: translateY(0); }
.sheet-grab { width: 40px; height: 4px; border-radius: 4px; background: var(--outline); margin: 6px auto 2px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sheet-head h2 { font-size: 19px; }
.sheet-head p { margin: 2px 0 0; font-size: 13px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-right: 2px; }
.sheet-actions { display: flex; gap: 10px; padding-top: 4px; }
.option {
  width: 100%; text-align: left; border: 0; background: transparent; padding: 15px 6px;
  border-bottom: 1px solid var(--surface-variant); font-size: 16px; cursor: pointer;
}
.option:active { background: var(--surface-variant); }

.toast-host { display: flex; align-items: flex-end; justify-content: center; padding: 0 16px 96px; }
.toast-host .toast {
  background: #0F172A; color: #fff; padding: 13px 16px; border-radius: 14px;
  font-size: 14px; max-width: 520px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0; transform: translateY(8px); transition: all .2s ease;
}
.toast-host.visible { pointer-events: auto; }
.toast-host.visible .toast { opacity: 1; transform: translateY(0); }
.toast.warn { background: #92400E; }
.toast.error { background: #7F1D1D; }

.offline-badge {
  position: fixed; top: max(env(safe-area-inset-top), 0); left: 0; right: 0; z-index: 60;
  background: var(--amber); color: #fff; text-align: center; font-size: 12px;
  padding: 5px; display: none;
}
.offline-badge.visible { display: block; }

/* ------------------------------------------------------------ acceso (login) */

.acceso {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: none; overflow-y: auto;
}
.acceso.visible { display: flex; align-items: center; justify-content: center; padding: 24px; }
body.con-acceso .nav, body.con-acceso .fab { display: none; }

.acceso-card {
  width: 100%; max-width: 420px; display: flex; flex-direction: column;
  gap: 16px; align-items: center; text-align: center;
}
.acceso-card h1 { font-size: 26px; margin: 0; letter-spacing: -0.5px; }
.acceso-card h2 { font-size: 20px; margin: 0; }
.acceso-card p { margin: 0; }
.acceso-card img.logo {
  width: 88px; height: 88px; border-radius: 22px;
  box-shadow: 0 10px 30px rgba(37, 99, 235, .28);
}
.acceso-puntos { text-align: left; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; color: var(--muted); }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; background: #fff; color: #1f2937; border: 1px solid var(--outline);
  border-radius: 14px; padding: 15px; font-weight: 700; font-size: 15px; cursor: pointer;
}
.google-btn:disabled { opacity: .65; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='claro']) .google-btn { background: #f8fafc; }
}
:root[data-theme='oscuro'] .google-btn { background: #f8fafc; }

pre.codigo {
  margin: 0; padding: 12px; border-radius: 12px; background: var(--surface-variant);
  font-size: 12px; line-height: 1.5; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
