:root {
  --primary:    #6366f1;
  --primary-d:  #4f46e5;
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #0f172a;
  --text-muted: #64748b;
  --danger:     #ef4444;
  --success:    #22c55e;
  --radius:     12px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --nav-h:      64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; display: flex; flex-direction: column; }

/* ── Navegación inferior ─────────────────────────────── */
.nav-bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color .15s;
}

.nav-btn.active { color: var(--primary); }
.nav-btn svg { width: 22px; height: 22px; stroke-width: 1.8; }

/* ── Contenido principal ─────────────────────────────── */
.page {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--nav-h) + 16px);
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

/* ── Encabezado de página ────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-title { font-size: 22px; font-weight: 700; }
.page-sub   { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Tarjetas ────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

/* ── Resumen total del mes ───────────────────────────── */
.total-card {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.total-card .label { font-size: 13px; opacity: .8; }
.total-card .amount { font-size: 36px; font-weight: 700; line-height: 1.1; margin: 4px 0; }
.total-card .sub    { font-size: 13px; opacity: .8; }

.total-users { display: flex; gap: 16px; margin-top: 12px; }
.total-users .u { flex: 1; background: rgba(255,255,255,.15); border-radius: 8px; padding: 8px 12px; }
.total-users .u .name { font-size: 12px; opacity: .8; }
.total-users .u .val  { font-size: 18px; font-weight: 600; }

/* ── Barras de categoría ─────────────────────────────── */
.cat-list { display: flex; flex-direction: column; gap: 10px; }

.cat-item { display: flex; flex-direction: column; gap: 6px; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cat-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cat-name { flex: 1; font-size: 14px; font-weight: 500; }
.cat-vals { font-size: 13px; color: var(--text-muted); text-align: right; white-space: nowrap; }
.cat-vals strong { color: var(--text); }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
}

.progress-fill.over { background: var(--danger); }

/* ── FAB ─────────────────────────────────────────────── */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-h) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99,102,241,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: transform .15s, box-shadow .15s;
}

.fab:active { transform: scale(.93); box-shadow: 0 2px 6px rgba(99,102,241,.3); }

/* ── Modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 480px;
  animation: slideUp .2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

/* ── Formulario ──────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }

.input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.input:focus { border-color: var(--primary); }

.amount-input {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  padding: 16px;
}

/* ── Selector de categorías (grid de chips) ──────────── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.cat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--bg);
  cursor: pointer;
  font-size: 11px;
  text-align: center;
  transition: border-color .1s, background .1s;
}

.cat-chip:hover   { background: #eef2ff; }
.cat-chip.selected { border-color: var(--primary); background: #eef2ff; }
.cat-chip .chip-dot { width: 24px; height: 24px; border-radius: 50%; }

/* ── Botones ─────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}

.btn:active { opacity: .85; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-ghost    { background: transparent; color: var(--text-muted); }

/* ── Login ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 32px;
}

.login-logo { font-size: 48px; }
.login-title { font-size: 28px; font-weight: 800; text-align: center; }
.login-sub   { font-size: 15px; color: var(--text-muted); text-align: center; margin-top: 4px; }

.user-select { display: flex; gap: 12px; width: 100%; max-width: 300px; }

.user-btn {
  flex: 1;
  padding: 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s;
}

.user-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #eef2ff;
}

.pin-form { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 300px; }

.pin-input {
  width: 100%;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 8px;
  text-align: center;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 14px;
}

.pin-input:focus { border-color: var(--primary); outline: none; }

/* ── Historial ───────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.month-nav button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
}

.month-nav .month-label { font-size: 16px; font-weight: 600; min-width: 140px; text-align: center; }

.filter-row { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-chip {
  padding: 6px 14px;
  border-radius: 99px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.filter-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.gasto-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.gasto-item:last-child { border-bottom: none; }

.gasto-cat-dot { width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; }
.gasto-info    { flex: 1; min-width: 0; }
.gasto-desc    { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gasto-meta    { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.gasto-monto   { font-size: 16px; font-weight: 700; flex-shrink: 0; }
.gasto-del     { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; font-size: 16px; }

.date-group { font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 12px 0 4px; text-transform: uppercase; letter-spacing: .5px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 14px;
}

/* ── Evolución del gasto ─────────────────────────────── */
.evol-month { margin-bottom: 10px; }
.evol-month:last-child { margin-bottom: 0; }

.evol-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.evol-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 30px;
}

.evol-bar-wrap {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.evol-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width .5s ease;
}

.evol-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 115px;
  justify-content: flex-end;
}

.evol-amount { font-size: 13px; font-weight: 600; }

.evol-trend  { font-size: 11px; font-weight: 700; }
.evol-up     { color: var(--danger); }
.evol-down   { color: var(--success); }

.evol-users {
  font-size: 11px;
  color: var(--text-muted);
  padding-left: 38px;
  margin-top: 3px;
}

/* ── Selector de color (creador de categorías) ───────── */
.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color .1s, transform .1s;
}

.color-swatch:active { transform: scale(.9); }
.color-swatch.selected { border-color: #0f172a; }

/* ── Loading / toast ─────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 80px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px;
  z-index: 999;
  animation: fadeInOut 2.5s ease forwards;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(8px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}
