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

[hidden] { display: none !important; }

:root {
  --primary: #667eea;
  --primary-dark: #5568d3;
  --accent: #764ba2;
  --bg: #f4f6fb;
  --panel-bg: #ffffff;
  --sidebar-bg: #1a202c;
  --sidebar-hover: #2d3748;
  --sidebar-active: #667eea;
  --text: #2d3748;
  --muted: #718096;
  --border: #e2e8f0;
  --danger: #e53e3e;
  --success: #38a169;
}

[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --accent: #a78bfa;
  --bg: #0f172a;
  --panel-bg: #1e293b;
  --sidebar-bg: #020617;
  --sidebar-hover: #1e293b;
  --sidebar-active: #6366f1;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --danger: #f87171;
  --success: #4ade80;
}

[data-theme="rosa"] {
  --primary: #ec4899;
  --primary-dark: #db2777;
  --accent: #f472b6;
  --bg: #fff1f7;
  --panel-bg: #ffffff;
  --sidebar-bg: #831843;
  --sidebar-hover: #9d174d;
  --sidebar-active: #ec4899;
  --text: #500724;
  --muted: #9d174d;
  --border: #fbcfe8;
  --danger: #e11d48;
  --success: #10b981;
}

[data-theme="verde"] {
  --primary: #10b981;
  --primary-dark: #059669;
  --accent: #34d399;
  --bg: #f0fdf4;
  --panel-bg: #ffffff;
  --sidebar-bg: #064e3b;
  --sidebar-hover: #065f46;
  --sidebar-active: #10b981;
  --text: #022c22;
  --muted: #047857;
  --border: #bbf7d0;
  --danger: #dc2626;
  --success: #16a34a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: white;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}

.logo-icon {
  font-size: 1.8rem;
}

.logo-text {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-item {
  background: transparent;
  color: #cbd5e0;
  border: none;
  padding: 12px 14px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.menu-item:hover {
  background: var(--sidebar-hover);
  color: white;
}

.menu-item.active {
  background: var(--sidebar-active);
  color: white;
}

.menu-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

/* CONTENT */
.content {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
}

.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  margin-bottom: 24px;
}

.view-header h1 {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.view-header p {
  color: var(--muted);
  font-size: 0.95rem;
}

/* CARDS */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--panel-bg);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card .value {
  font-size: 1.7rem;
  font-weight: 700;
}

.card.total .value { color: var(--danger); }
.card.month .value { color: var(--primary); }
.card.avg .value { color: var(--accent); }
.card.count .value { color: var(--text); }

/* HERO CARD (Inicio) */
.hero-card {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 24px 28px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(102, 234, 130, 0.12), rgba(118, 75, 162, 0.06));
  border: 1px solid var(--border);
  margin-bottom: 24px;
}
.hero-icon {
  font-size: 2.6rem;
  width: 68px;
  height: 68px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 16px;
  border: 1px solid var(--border);
}
.hero-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.hero-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 700;
}
.hero-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.hero-sub {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 2px;
}

@media (max-width: 480px) {
  .hero-card { padding: 18px 20px; gap: 14px; }
  .hero-icon { width: 56px; height: 56px; font-size: 2rem; }
  .hero-value { font-size: 1.8rem; }
}

/* PANELS */
.panel {
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: var(--text);
}

/* FORM */
form .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex: 1;
}

label.inline select,
label.inline input {
  flex: 1;
}

input,
select {
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--panel-bg);
  color: var(--text);
  transition: border-color 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

button {
  cursor: pointer;
  border: none;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.2s, background 0.15s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  width: 100%;
}

.btn-primary.small {
  width: auto;
  padding: 9px 16px;
  margin-top: 10px;
}

.btn-primary:hover {
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

.btn-danger {
  background: #fed7d7;
  color: var(--danger);
}

.btn-danger:hover { background: #feb2b2; }

.btn-ghost {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: #edf2f7; }

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* FILTERS */
.filter-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* LIST */
ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.expense-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #f7fafc;
  border-radius: 10px;
  border-left: 4px solid var(--primary);
  transition: transform 0.1s;
}

.expense-item:hover {
  transform: translateX(2px);
}

.expense-info { flex: 1; }
.expense-desc { font-weight: 600; margin-bottom: 4px; }
.expense-meta { font-size: 0.82rem; color: var(--muted); }
.expense-amount {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--danger);
  margin-right: 12px;
  white-space: nowrap;
}

.btn-delete {
  background: transparent;
  color: #a0aec0;
  padding: 6px 10px;
  font-size: 1.1rem;
}

.btn-delete:hover { background: #fed7d7; color: var(--danger); }

.btn-edit {
  background: transparent;
  color: #a0aec0;
  padding: 6px 10px;
  font-size: 1.05rem;
  border: none;
  cursor: pointer;
  border-radius: 6px;
}
.btn-edit:hover { background: #e6f6ec; color: var(--primary); }
.btn-edit-mini {
  padding: 1px 6px;
  font-size: 0.85em;
  margin-left: 4px;
  vertical-align: baseline;
  border: 1px solid var(--border);
}

.empty {
  text-align: center;
  color: #a0aec0;
  padding: 30px 0;
  font-style: italic;
}

.empty.hidden { display: none; }

/* CATEGORIES */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.cat-card {
  background: #f7fafc;
  padding: 18px;
  border-radius: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.cat-card .cat-icon { font-size: 2rem; margin-bottom: 6px; }
.cat-card .cat-name { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.cat-card .cat-amount { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.cat-card .cat-percent { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

/* PROGRESS */
.progress-wrap { margin-top: 8px; }

.progress {
  width: 100%;
  height: 14px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.4s ease;
  width: 0%;
}

.progress-bar.warn { background: linear-gradient(90deg, #f6ad55, #ed8936); }
.progress-bar.over { background: linear-gradient(90deg, #fc8181, var(--danger)); }

.progress-text {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* CAMERA / PHOTO */
.camera-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 0;
  text-align: center;
}

.camera-panel .btn-primary {
  width: auto;
  padding: 16px 28px;
  font-size: 1.05rem;
}

.photo-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.photo-preview img {
  max-width: 100%;
  max-height: 360px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: #000;
}

.photo-preview .button-row {
  width: 100%;
  justify-content: center;
}

.photo-preview .btn-primary,
.photo-preview .btn-ghost {
  width: auto;
  flex: 1;
  max-width: 220px;
}

/* CAMERA / PHOTO */
#camera-panel .button-row { justify-content: center; }
.photo-preview {
  display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px;
}
.photo-preview img {
  max-width: 100%; max-height: 320px; border-radius: 12px;
  border: 1px solid var(--border); object-fit: contain; background: #000;
}

/* RECIENTES en form */
.recent-mini-list { gap: 6px; }
.recent-mini-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  padding: 10px 12px;
  background: #f7fafc;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  cursor: pointer;
  transition: background 0.15s;
}
.recent-mini-item:hover { background: var(--bg); }
.recent-mini-desc { font-weight: 600; font-size: 0.9rem; }
.recent-mini-meta { grid-column: 1; font-size: 0.78rem; color: var(--muted); }
.recent-mini-amount {
  grid-column: 2; grid-row: 1 / span 2;
  align-self: center; font-weight: 700; color: var(--danger);
}

[data-theme="dark"] .recent-mini-item,
[data-theme="dark"] .expense-item,
[data-theme="dark"] .cat-card { background: #0f172a; }

/* COLAPSABLES (Por mes y Categorías) */
.month-header.collapsible { cursor: pointer; -webkit-user-select: none; user-select: none; }
.month-header.collapsible:hover .caret { color: var(--primary); }
.caret { display: inline-block; transition: transform 0.15s; color: var(--muted); margin-left: 6px; }

.cat-months-list { display: flex; flex-direction: column; gap: 6px; }
.cat-month-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7fafc;
  overflow: hidden;
}
.cat-month-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.cat-month-header:hover { background: var(--bg); }
.cat-month-title { font-weight: 600; }
.cat-month-total { font-size: 0.85rem; color: var(--muted); }
.cat-month-body { padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--border); }

[data-theme="dark"] .cat-month-item { background: #0f172a; }

/* PRESUPUESTOS POR CATEGORÍA (vista budget) */
.cat-budgets-list { display: flex; flex-direction: column; gap: 10px; }
.cat-budget-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto 1fr;
  gap: 12px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cat-budget-row:last-child { border-bottom: none; }
.cat-budget-name { font-weight: 500; }
.cat-budget-input { display: flex; gap: 6px; align-items: center; }
.cat-budget-input input { width: 110px; padding: 8px 10px; }
.cat-budget-input .btn-primary.small { width: auto; padding: 8px 12px; margin: 0; }
.cat-budget-progress { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cat-budget-text { font-size: 0.8rem; color: var(--muted); }
.cat-budget-text.muted { font-style: italic; }

@media (max-width: 768px) {
  .cat-budget-row { grid-template-columns: 1fr; gap: 6px; }
  .cat-budget-input input { flex: 1; width: auto; }
}

/* PRESUPUESTOS MINI (dashboard) */
.cat-budgets-mini { display: flex; flex-direction: column; gap: 10px; }
.cat-budget-mini-head {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; margin-bottom: 4px;
}

/* ADMIN VIEW */
.adm-table { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.adm-row {
  display: grid;
  grid-template-columns: 50px 1.5fr 2fr 70px 70px 100px 50px auto;
  gap: 8px; align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f7fafc;
}
.adm-row.adm-head {
  background: transparent;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.adm-row-users { grid-template-columns: 50px 2fr 1.5fr 1.5fr 80px auto; }
.adm-actions { display: flex; gap: 4px; justify-content: flex-end; }
.adm-actions .btn-ghost.small,
.adm-actions .btn-danger.small {
  width: auto; padding: 4px 8px; font-size: 0.75rem; margin: 0;
}
[data-theme="dark"] .adm-row { background: #0f172a; }

.adm-audit {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 400px; overflow-y: auto;
  font-size: 0.8rem; font-family: ui-monospace, monospace;
}
.adm-audit-item {
  display: grid;
  grid-template-columns: 150px 180px 200px 1fr;
  gap: 10px; padding: 4px 8px;
  border-bottom: 1px dashed var(--border);
}
.adm-audit-time { color: var(--muted); }
.adm-audit-action { color: var(--primary); font-weight: 600; }

@media (max-width: 768px) {
  .adm-row, .adm-row-users { grid-template-columns: 1fr; }
  .adm-row.adm-head { display: none; }
  .adm-audit-item { grid-template-columns: 1fr; gap: 2px; }
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--sidebar-bg);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 1000;
  font-size: 0.9rem;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* MENU TOGGLE (mobile) */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  background: var(--sidebar-bg);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-size: 1.3rem;
  padding: 0;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    transition: left 0.25s ease;
    z-index: 50;
    height: 100vh;
  }

  .sidebar.open { left: 0; }

  .content { padding: 70px 20px 24px; }

  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  form .row { grid-template-columns: 1fr; }

  .filter-row { flex-direction: column; }

  label.inline { width: 100%; }
}

/* AUTH SCREEN */
.auth-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.auth-card {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.auth-logo h1 {
  font-size: 1.4rem;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.auth-tab.active {
  background: var(--panel-bg);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.auth-form.active {
  display: flex;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  background: #fee;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 0;
}

/* USER CHIP */
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  margin-bottom: 12px;
  color: white;
  font-size: 0.85rem;
}

.user-chip-avatar {
  font-size: 1.1rem;
}

.user-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-hint {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 16px;
}

.auth-legal {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  margin-top: 18px;
  line-height: 1.4;
}
.auth-legal a {
  color: var(--primary);
  text-decoration: underline;
}

.auth-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}
.auth-form input {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
.auth-form input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: transparent;
}
.auth-submit { width: 100%; margin-top: 6px; padding: 12px; font-size: 0.95rem; }

.auth-switch {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}
.auth-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 2px 4px;
  margin-left: 4px;
  text-decoration: underline;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.users-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.users-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.users-list .user-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.users-list .user-name { font-weight: 600; color: var(--text); }
.users-list .user-meta { font-size: 0.8rem; color: var(--muted); }
.users-list .user-badge {
  font-size: 0.7rem;
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 14px 0 4px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.magic-link-form,
.password-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.magic-link-form input,
.password-form input {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  background: var(--panel-bg);
  color: var(--text);
}
.magic-link-form input:focus,
.password-form input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}
.magic-link-form button,
.password-form button {
  padding: 12px 16px;
}
.password-form-buttons {
  display: flex;
  gap: 8px;
}
.password-form-buttons button {
  flex: 1;
}

.auth-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.auth-separator::before,
.auth-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.manage-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin: 8px 0 12px;
}
.manage-form input[type="text"]:first-child {
  width: 70px;
  text-align: center;
  font-size: 1.2rem;
}
.manage-form input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
}
.manage-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.manage-list li.empty {
  color: var(--muted);
  font-style: italic;
  padding: 8px;
}
.manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.manage-icon { font-size: 1.3rem; }
.manage-name { flex: 1; }

.manage-edit-icon, .manage-edit-name {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
}
.manage-edit-icon { width: 56px; text-align: center; }
.manage-edit-name { flex: 1; min-width: 0; }
.manage-edit-icon:focus, .manage-edit-name:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: transparent;
}

.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.google-btn-wrap {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  min-height: 44px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.google-btn-wrap iframe { max-width: 100% !important; }

.oauth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: transform 0.1s, box-shadow 0.15s, filter 0.15s;
  border: 1px solid transparent;
}
.oauth-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.oauth-btn:active { transform: translateY(0); }

.oauth-btn-github {
  background: #24292f;
  color: #fff;
}
.oauth-btn-github:hover { filter: brightness(1.1); }
.oauth-btn-discord {
  background: #5865F2;
  color: #fff;
}
.oauth-btn-discord:hover { filter: brightness(1.1); }
.oauth-btn-icon { width: 20px; height: 20px; }

.sidebar-logout {
  background: transparent;
  color: #cbd5e0;
  padding: 4px 8px;
  font-size: 1rem;
  border-radius: 6px;
  margin-left: auto;
  transition: background 0.15s, color 0.15s;
}
.sidebar-logout:hover { background: rgba(255,255,255,0.12); color: #fed7d7; }

/* MONTHS VIEW */
.month-card { padding: 20px 24px; }
.month-header { margin-bottom: 16px; }
.month-header h2 { font-size: 1.2rem; margin-bottom: 6px; color: var(--text); }
.month-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
}
.month-stats strong { color: var(--primary); font-size: 1.05rem; }

.months-search { margin-bottom: 16px; }
.months-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
.months-search input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: transparent;
}

.month-cats { display: flex; flex-direction: column; gap: 8px; }

.month-cat-row {
  display: grid;
  grid-template-columns: minmax(180px, 200px) 1fr 140px;
  gap: 12px;
  align-items: center;
  font-size: 0.88rem;
}
.month-cat-name { font-weight: 500; }
.month-cat-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  display: block;
}
.month-cat-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
}
.month-cat-amount { text-align: right; font-weight: 600; color: var(--text); }
.month-cat-amount small { color: var(--muted); font-weight: 400; }

.collapsible-cat {
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 8px;
  margin: 0 -8px;
  transition: background 0.15s;
}
.collapsible-cat:hover { background: var(--border); }
.caret-cat { color: var(--muted); font-size: 0.85em; margin-left: 2px; }

.month-cat-items {
  list-style: none;
  margin: 4px 0 12px 28px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  border-left: 2px solid var(--border);
  padding-left: 12px;
}
.month-cat-items li {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "desc amt" "meta amt";
  column-gap: 12px;
  align-items: center;
}
.mci-desc { grid-area: desc; font-weight: 500; color: var(--text); }
.mci-meta { grid-area: meta; font-size: 0.78rem; color: var(--muted); }
.mci-amt  { grid-area: amt;  font-weight: 600; color: var(--text); white-space: nowrap; }

@media (max-width: 640px) {
  .month-cat-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .month-cat-amount { text-align: left; }
  .month-cat-items { margin-left: 12px; padding-left: 8px; }
}

.month-separator {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 8px;
  margin-top: 8px;
  background: transparent;
  border-left: none;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}
.month-separator:first-child { margin-top: 0; }
.month-separator-title { font-weight: 700; color: var(--text); }
.month-separator-total { font-weight: 600; }
.month-separator:hover { transform: none; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  animation: fadeIn 0.15s ease-out;
}
.modal-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  animation: modalIn 0.2s ease-out;
}
@keyframes modalIn { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 4px;
}
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}
.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}
.modal-body input,
.modal-body select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
.modal-body input:focus,
.modal-body select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: transparent;
}

.modal-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 480px) {
  .modal { padding: 18px; }
  .modal-row-2 { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
}

/* RECEIPT LIGHTBOX */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
  animation: fadeIn 0.15s ease-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }

.btn-receipt {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.85em;
  cursor: pointer;
  margin-left: 4px;
  vertical-align: baseline;
  transition: background 0.15s;
}
.btn-receipt:hover { background: var(--border); }

/* MINI RESUMEN MES (Nuevo gasto) */
.month-summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.ms-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: transform 0.15s, box-shadow 0.15s;
}
.ms-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06); }
.ms-card-month { background: linear-gradient(135deg, rgba(102, 234, 130, 0.08), rgba(118, 234, 162, 0.04)); }
.ms-card-cat   { background: linear-gradient(135deg, rgba(102, 126, 234, 0.08), rgba(118, 75, 162, 0.04)); }
.ms-card-icon {
  font-size: 2rem;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.ms-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ms-card-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ms-card-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.ms-card-sub { font-size: 0.78rem; color: var(--muted); }

@media (max-width: 480px) {
  .month-summary-cards { grid-template-columns: 1fr; gap: 8px; }
  .ms-card-value { font-size: 1.25rem; }
  .ms-card-icon { width: 44px; height: 44px; font-size: 1.6rem; }
}

/* CAPTURA RÁPIDA */
.quick-capture { padding: 20px 22px; }
.quick-capture-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.quick-capture-sub {
  margin: 0 0 16px;
  font-size: 0.85rem;
  color: var(--muted);
}
.capture-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.capture-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 22px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--card);
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
}
.capture-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}
.capture-photo:hover { border-color: var(--primary); }
.capture-voice:hover { border-color: #ef4444; }
.capture-icon {
  font-size: 2.4rem;
  line-height: 1;
  margin-bottom: 4px;
}
.capture-title {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text);
}
.capture-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}

#audio-btn.capture-card.recording {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: #dc2626;
  color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
#audio-btn.capture-card.recording .capture-title,
#audio-btn.capture-card.recording .capture-desc { color: #fff; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.85; }
}

.audio-preview {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

@media (max-width: 480px) {
  .capture-options { grid-template-columns: 1fr; }
  .capture-card { padding: 18px 14px; }
  .capture-icon { font-size: 2rem; }
}

/* PREDICTOR DE FIN DE MES */
.forecast-panel { margin-bottom: 24px; }
.forecast-text { margin: 0 0 14px; font-size: 0.95rem; color: var(--text); }
.forecast-bar {
  position: relative;
  height: 14px;
  background: var(--border);
  border-radius: 99px;
  overflow: visible;
  margin: 6px 0 12px;
}
.forecast-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width 0.4s ease-out;
}
.forecast-bar-budget {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 2px;
  background: var(--danger);
}
.forecast-bar-budget::after {
  content: "🎯";
  position: absolute;
  top: -22px;
  left: -10px;
  font-size: 0.9rem;
}
#forecast-budget-msg.warning { color: var(--danger); }

/* SEPARADOR "o llena manual" */
.manual-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.manual-divider::before,
.manual-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* =========================================================
   MOBILE OPTIMIZATIONS
   ========================================================= */

/* Tap highlight transparente (azul de iOS feo) */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Evita zoom auto al hacer focus en inputs en iOS (requiere font-size ≥ 16px) */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* Mejoras solo en pantallas mobile/tablet */
@media (max-width: 640px) {

  /* Padding más justo en main para aprovechar el ancho */
  main { padding: 12px !important; }

  /* Headers de view más compactos */
  .view-header h1 { font-size: 1.4rem; }
  .view-header p { font-size: 0.85rem; }

  /* Panels con menos padding */
  .panel { padding: 16px !important; }

  /* Hit targets mínimos 44x44 (Apple/Google guidelines) */
  .btn-delete, .btn-edit, .btn-receipt {
    min-width: 40px;
    min-height: 40px;
    padding: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Modales: usar dynamic viewport height (cuenta la barra URL iOS) */
  .modal {
    max-height: calc(100dvh - 32px);
    border-radius: 14px;
  }
  .modal-actions {
    position: sticky;
    bottom: -24px;
    background: var(--bg);
    padding-top: 12px;
    margin: 8px -24px -24px;
    padding: 12px 24px 16px;
    border-top: 1px solid var(--border);
  }

  /* Lightbox: dvh para que la imagen no quede tapada por barra URL */
  .lightbox {
    padding: 16px;
    /* fallback */
    height: 100vh;
    /* moderno */
    height: 100dvh;
  }
  .lightbox-close {
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
  }

  /* Sidebar: ocupa todo el ancho cuando se abre en mobile */
  .sidebar.open {
    width: 85%;
    max-width: 320px;
  }

  /* Cerrar sidebar con tap fuera más fácil (overlay sutil) */
  .sidebar.open ~ main {
    pointer-events: auto;
  }

  /* Items de expense con tap target generoso */
  .expense-item {
    padding: 14px 12px !important;
    gap: 10px;
  }
  .expense-desc { font-size: 0.95rem; }
  .expense-meta { font-size: 0.78rem; }
  .expense-amount { font-size: 1rem; }

  /* Forms en columna siempre */
  .row {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Selectores y inputs más altos para fingers */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="search"],
  input[type="password"],
  input[type="email"],
  select {
    min-height: 44px;
    padding: 10px 12px;
  }

  /* Botones primarios y ghost min-height 44 */
  .btn-primary, .btn-ghost, .btn-danger {
    min-height: 44px;
    padding: 10px 16px;
  }
  .btn-primary.small {
    min-height: 38px;
    padding: 8px 14px;
  }

  /* Capture cards más compactas pero usables */
  .capture-card {
    padding: 20px 14px;
  }
  .capture-icon { font-size: 2.2rem; }

  /* Toast más arriba para no chocar con teclado */
  .toast {
    bottom: 80px;
  }

  /* Forecast bar text más legible */
  .forecast-text { font-size: 0.88rem; }
}

/* iPhone notch / safe areas */
@supports (padding: max(0px)) {
  .sidebar { padding-top: max(16px, env(safe-area-inset-top)); }
  main {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .toast {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

