:root {
  --bg: #111315;
  --bg-alt: #1a1d20;
  --panel: #171b1f;
  --panel-soft: #20262b;
  --line: rgba(255,255,255,0.08);
  --text: #f3f4f7;
  --muted: #afb6c2;
  --gold: #f5c95b;
  --gold-2: #efb744;
  --green: #7bdca0;
  --red: #f39a8a;
  --blue: #77c0f6;
  --violet: #b6a9ff;
  --shadow: 0 24px 60px rgba(0,0,0,0.48);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #0d1013; color: var(--text); font-family: 'Inter', sans-serif; }
button, input, textarea { font: inherit; }
a { color: inherit; }

.app-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
}

.mobile-shell {
  width: min(100vw, 460px);
  min-height: 100vh;
  background: linear-gradient(180deg, #111315 0%, #191d21 100%);
  position: relative;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Sidebar de navegación: en móvil es un cajón deslizable, en escritorio
   queda fija y siempre visible (ver breakpoint de 900px más abajo). */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 270px;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 26px 18px; gap: 4px;
  transform: translateX(-100%); transition: transform 0.25s ease; z-index: 40;
}
.sidebar.open { transform: translateX(0); }
.sidebar-brand { font-weight: 800; font-size: 1.25rem; margin-bottom: 22px; letter-spacing: -0.03em; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-nav button {
  display: flex; align-items: center; gap: 12px; text-align: left; background: transparent; border: none;
  color: var(--muted); font-weight: 700; font-size: 1rem; padding: 12px 14px; border-radius: 12px; cursor: pointer;
}
.sidebar-nav button:hover, .sidebar-nav button.active { background: rgba(255,255,255,0.07); color: var(--text); }
.sidebar-nav button.sidebar-add {
  margin-top: 12px; background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #121518; justify-content: center;
}
.sidebar-nav button.sidebar-add:hover { background: linear-gradient(135deg, var(--gold), var(--gold-2)); }
.sidebar-logout {
  display: block; color: var(--muted); text-decoration: none; font-weight: 700; padding: 14px; margin-top: 10px;
  border-top: 1px solid var(--line); cursor: pointer;
}
.sidebar-logout:hover { color: var(--text); }
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 35; display: none;
}
.sidebar-overlay.show { display: block; }

/* Buscador desplegable en el topbar */
.search-bar { max-height: 0; overflow: hidden; padding: 0 18px; transition: max-height 0.2s ease, padding 0.2s ease; }
.search-bar.open { max-height: 60px; padding: 0 18px 14px; }
.search-bar input {
  width: 100%; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--text);
  border-radius: 14px; padding: 11px 14px;
}

/* Navegador de mes (funcional vía enlaces ?month=) */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 6px 0 16px; font-weight: 700; }
.month-arrow {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  display: grid; place-items: center; text-decoration: none; font-size: 1.3rem; color: var(--text);
}
.month-arrow:hover { background: rgba(255,255,255,0.1); }
.month-label { min-width: 160px; text-align: center; color: var(--text); }

.flash {
  margin: 0 18px 12px;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.88rem;
}
.flash-error { background: rgba(240,90,80,0.16); color: #ff9a90; border: 1px solid rgba(240,90,80,0.4); }
.flash-success { background: rgba(97,208,149,0.16); color: #7ee7ac; border: 1px solid rgba(97,208,149,0.4); }

.screen { display: none; min-height: calc(100vh - 52px); padding-bottom: 88px; }
.screen.active { display: block; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 10px;
}
.topbar h1, .add-topbar h2 { margin: 0; letter-spacing: -0.05em; font-size: clamp(2rem, 5vw, 2.3rem); }
.icon-btn, .back, .cancel { background: transparent; border: none; color: var(--text); font-size: 2rem; cursor: pointer; }
.header-right { display: flex; align-items: center; gap: 8px; }
.icon-btn.round { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.04); border: 1px solid var(--line); font-size: 1.4rem; }

.section-shell, .add-screen { padding: 0 18px; }

.switcher {
  display: flex; background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 18px; padding: 4px; margin-bottom: 18px;
}
.switcher button {
  flex: 1; background: transparent; border: none; color: var(--muted); font-weight: 700; padding: 12px 8px; border-radius: 12px; cursor: pointer;
}
.switcher button.active { background: #f2f4f5; color: #111315; }

.summary-row { display: flex; gap: 10px; margin-top: 12px; }
.summary-card {
  flex: 1; background: rgba(255,255,255,0.03); border: 1px solid var(--line); border-radius: 18px; padding: 12px 12px;
}
.summary-card .label { color: var(--muted); font-size: 0.73rem; display: block; margin-bottom: 8px; }
.summary-card .value { display: block; font-weight: 800; letter-spacing: -0.04em; font-size: clamp(0.9rem, 3vw, 1.5rem); }
.summary-card .value.income { color: var(--green); }
.summary-card .value.expense { color: var(--red); }
.summary-card .value.balance { color: var(--text); }

.promo-banner {
  margin-top: 18px; background: rgba(255,255,255,0.035); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.promo-banner strong { display: block; font-size: 0.95rem; line-height: 1.25; }
.cta-btn, .gold-button, .modal-cta, .save {
  border: none; border-radius: 14px; padding: 11px 16px; font-weight: 800; cursor: pointer;
}
.cta-btn { background: rgba(245,201,91,0.18); color: var(--gold); }
.gold-button, .save, .modal-cta { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #121518; }

.transaction-list { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.txn-item {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.txn-icon {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 1.3rem;
}
.txn-main { font-weight: 700; }
.txn-meta { margin-top: 2px; color: var(--muted); font-size: 0.78rem; }
.txn-value { font-weight: 800; letter-spacing: -0.04em; }
.txn-value.expense { color: var(--text); }

.fab-btn {
  position: absolute; right: 26px; bottom: 86px; width: 74px; height: 74px; border-radius: 50%; border: none; background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #121518; font-size: 3rem; font-weight: 700; box-shadow: 0 18px 32px rgba(245,201,91,0.35); cursor: pointer;
}

.bottom-nav {
  position: absolute; left: 0; right: 0; bottom: 0; background: rgba(12,15,18,0.97); border-top: 1px solid rgba(255,255,255,0.06); display: flex; justify-content: space-between; padding: 12px 18px 16px; backdrop-filter: blur(10px);
}
.bottom-nav button {
  width: 25%; background: transparent; border: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 0.8rem; cursor: pointer;
}
.bottom-nav button.active { color: var(--text); }
.nav-icon { font-size: 1.8rem; line-height: 1; }

.add-topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 0 14px;
}
.add-topbar .settings-mini { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.04); border: 1px solid var(--line); display: grid; place-items: center; }
.type-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 16px; padding: 5px; margin-bottom: 18px;
}
.type-tabs button {
  background: transparent; border: none; color: var(--muted); border-radius: 12px; font-weight: 700; padding: 10px 6px; cursor: pointer;
}
.type-tabs button.active { background: #f1f3f5; color: #101315; }

.category-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px 6px; margin-top: 18px;
}
.category-item { text-align: center; cursor: pointer; }
.category-item .circle {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center; font-size: 1.5rem; background: rgba(255,255,255,0.02); border: 2px solid rgba(255,255,255,0.24);
}
.category-item.active .circle {
  background: var(--gold); color: #121518; border-color: var(--gold); box-shadow: 0 16px 24px rgba(245,201,91,0.26);
}
.category-item span { display: block; font-weight: 600; font-size: 0.72rem; line-height: 1.2; }

.add-modal {
  position: fixed; inset: 0; background: rgba(8,10,12,0.8); display: none; place-items: center; padding: 24px; z-index: 30;
}
.add-modal.open { display: grid; }
.add-modal-card { width: min(100%, 480px); background: #1f2630; color: #ffffff; border: 1px solid #404856; max-height: 90vh; overflow-y: auto; border-radius: 16px; }
.add-modal-header {
  display: flex; align-items: center; justify-content: space-between; padding: 22px 22px 18px 22px; font-weight: 800; font-size: 1.3rem; border-bottom: 1px solid #404856; position: sticky; top: 0; background: #1f2630; color: #ffffff;
}
.add-modal-header .modal-close { background: transparent; border: none; color: #8a9ab0; font-size: 1.4rem; cursor: pointer; padding: 0; transition: color 0.2s; }
.add-modal-header .modal-close:hover { color: #ffffff; }

/* Gestión de categorías */
.category-manage-list { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.category-manage-item {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.category-manage-name { font-weight: 700; }
.category-manage-actions { display: flex; align-items: center; gap: 6px; }
.category-manage-actions form { display: contents; }
.category-manage-actions .icon-btn.round { font-size: 1.1rem; }

/* Estilos específicos para el modal de categorías */
#cat-form .form-box {
  padding: 24px 20px; display: flex; flex-direction: column; gap: 20px; background: #1a1d20;
}
#cat-form .field {
  display: flex; flex-direction: column; gap: 10px;
}
#cat-form .field label {
  font-weight: 700; font-size: 1rem; color: #ffffff; text-transform: uppercase; letter-spacing: 0.8px; display: block;
}
#cat-form .field input,
#cat-form .field select {
  width: 100%; border: 2px solid #404856; background: #232a32; color: #ffffff; border-radius: 12px; padding: 14px 16px; font-size: 1rem; font-family: 'Inter', sans-serif; box-sizing: border-box; transition: all 0.2s;
}
#cat-form .field input::placeholder {
  color: #8a9ab0;
}
#cat-form .field select option {
  background: #1a1d20; color: #ffffff;
}
#cat-form .field input:focus,
#cat-form .field select:focus {
  outline: none; border-color: #f5c95b; background: #2a3240; box-shadow: 0 0 0 3px rgba(244,185,66,0.2);
}
#cat-form .field input[type="color"] {
  height: 60px; cursor: pointer; padding: 6px; border: 2px solid #404856; border-radius: 12px;
}
#cat-form .emoji-palette {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-top: 12px;
}
#cat-form .emoji-btn {
  width: 100%; aspect-ratio: 1; border-radius: 12px; background: #232a32; border: 2px solid #404856; font-size: 1.8rem; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; padding: 0;
}
#cat-form .emoji-btn:hover {
  background: #f5c95b; border-color: #f5c95b; transform: scale(1.08);
}
#cat-form .emoji-btn:active {
  transform: scale(0.92);
}
#cat-form .form-actions {
  padding: 0 20px 24px 20px; display: flex; gap: 12px; background: #1a1d20;
}
#cat-form .form-actions button {
  flex: 1; padding: 14px 16px; border-radius: 12px; font-weight: 700; border: 2px solid #404856; cursor: pointer; font-size: 1rem; transition: all 0.2s; text-transform: uppercase; letter-spacing: 0.8px;
}
#cat-form .form-actions .secondary {
  background: #232a32; color: #ffffff;
}
#cat-form .form-actions .secondary:hover {
  background: #2a3240; border-color: #505d6b;
}
#cat-form .form-actions .save {
  background: #f5c95b; color: #121518; border-color: #f5c95b;
}
#cat-form .form-actions .save:hover {
  background: #f5c95b; box-shadow: 0 4px 12px rgba(244,185,66,0.3);
}

.calc-delete-btn {
  width: 100%; margin-top: 10px; background: rgba(243,154,138,0.14); color: var(--red); border: 1px solid rgba(243,154,138,0.35);
  border-radius: 14px; padding: 12px 0; font-weight: 800; cursor: pointer;
}

/* Panel de calculadora para registrar el monto (estilo "hoja inferior") */
.calc-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #15181b; border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0; box-shadow: 0 -20px 50px rgba(0,0,0,0.5);
  padding: 16px 18px 20px; max-width: 460px; margin: 0 auto;
  transform: translateY(100%); transition: transform 0.28s ease;
}
.calc-sheet.open { transform: translateY(0); }

.calc-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.calc-cat {
  width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,0.06); display: grid; place-items: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.calc-display {
  flex: 1; text-align: right; font-size: 2.2rem; font-weight: 800; letter-spacing: -0.03em; overflow-x: auto; white-space: nowrap;
}
.calc-display.error { animation: calc-shake 0.3s; color: var(--red); }
@keyframes calc-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.calc-note-row {
  display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; margin-bottom: 14px;
}
.calc-note-label { color: var(--muted); font-weight: 700; font-size: 0.85rem; white-space: nowrap; }
.calc-note-row input { flex: 1; background: transparent; border: none; color: var(--text); outline: none; min-width: 0; }
.calc-date-native { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

.calc-keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-key {
  background: rgba(255,255,255,0.05); border: 1px solid var(--line); color: var(--text);
  border-radius: 14px; padding: 14px 0; font-size: 1.2rem; font-weight: 700; cursor: pointer;
}
.calc-key:active { background: rgba(255,255,255,0.12); }
.calc-key[data-op] { color: var(--gold); }

.calc-actions { display: flex; gap: 8px; margin-top: 8px; }
.calc-actions button {
  flex: 1; padding: 14px 0; border-radius: 14px; font-weight: 800; cursor: pointer; border: 1px solid var(--line);
  background: rgba(255,255,255,0.05); color: var(--text); font-size: 0.95rem;
}
.calc-date-btn { color: var(--gold); }
.calc-confirm { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #121518; border: none; }

.form-box { margin-top: 28px; display: grid; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text); border-radius: 14px; padding: 12px 14px;
}
.field textarea { min-height: 82px; resize: vertical; }
.form-actions { margin-top: 18px; display: flex; gap: 12px; }
.form-actions button { flex: 1; }
.form-actions .secondary { background: rgba(255,255,255,0.05); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 14px 18px; font-weight: 800; cursor: pointer; }

.login-wrap {
  padding: 18px 20px 30px;
}
.avatar-circle {
  width: 84px; height: 84px; border-radius: 50%; background: rgba(255,255,255,0.12); display: grid; place-items: center; font-size: 2.8rem; margin: 10px 0 20px;
}
.login-wrap h2 {
  margin: 0 0 20px; font-size: clamp(2rem, 5vw, 2.5rem); letter-spacing: -0.05em;
}
.login-wrap h2 span { display: block; font-size: 1.1rem; color: var(--muted); margin-top: 6px; }
.login-form { display: grid; gap: 14px; }
.login-form .field input { background: rgba(255,255,255,0.04); }
.login-links { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.link-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line); color: var(--text); border-radius: 16px; padding: 14px 18px; text-align: left; font-weight: 700; cursor: pointer;
}
.login-nav { position: fixed; }

.settings-list { padding: 10px 0 0; }
.setting-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.setting-left { display: flex; align-items: center; gap: 14px; }
.setting-icon { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: rgba(255,255,255,0.04); border: 1px solid var(--line); }
.setting-label { font-weight: 600; }
.toggle {
  width: 52px; height: 30px; border-radius: 999px; background: rgba(255,255,255,0.2); border: 1px solid var(--line); position: relative;
}
.toggle::before { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #f5f5f5; top: 3px; left: 4px; }
.toggle.on { background: var(--gold); }
.toggle.on::before { left: 24px; }

.premium-modal {
  position: absolute; inset: 0; background: rgba(8,10,12,0.7); display: none; place-items: center; padding: 24px; z-index: 25;
}
.modal-card {
  width: min(100%, 420px); background: #f3f1ef; color: #121518; border-radius: 24px; padding: 26px 22px 18px; box-shadow: var(--shadow);
}
.modal-header { text-align: center; font-weight: 800; font-size: clamp(1.9rem, 4vw, 2.6rem); letter-spacing: -0.05em; margin-bottom: 14px; }
.modal-list { list-style: none; margin: 18px 0 10px; padding: 0; display: grid; gap: 14px; }
.modal-list li { display: flex; align-items: center; gap: 12px; font-size: 1.05rem; }
.check { width: 24px; height: 24px; border-radius: 50%; background: var(--gold); display: grid; place-items: center; font-weight: 900; }
.pricing { text-align: center; margin: 18px 0 14px; font-size: 1.2rem; }
.pricing strong { font-size: 2.2rem; }
.modal-cta { width: 100%; font-size: 1.7rem; }
.modal-small { text-align: center; margin-top: 12px; color: #383d41; font-weight: 700; cursor: pointer; }

@media (min-width: 640px) and (max-width: 899px) {
  .app-layout { padding: 30px 0; }
  .mobile-shell { min-height: 820px; border-radius: 26px; }
}

/* A partir de aquí ya no es un teléfono: navegación lateral fija,
   contenido a lo ancho y sin la barra de estado falsa de un móvil. */
@media (min-width: 900px) {
  .app-layout { justify-content: flex-start; align-items: stretch; }
  .sidebar { position: sticky; top: 0; height: 100vh; transform: none; }
  .sidebar-overlay { display: none !important; }
  #menu-toggle { display: none; }

  .mobile-shell {
    width: auto; flex: 1; max-width: 980px; margin: 0 auto; min-height: 100vh;
    border-radius: 0; box-shadow: none; overflow: visible;
  }
  .app-layout.guest .mobile-shell { max-width: 460px; margin: 40px auto; min-height: auto; border-radius: 26px; box-shadow: var(--shadow); }

  .screen { min-height: auto; padding-bottom: 60px; }
  .topbar { padding: 34px 40px 14px; }
  .section-shell, .add-screen { padding: 0 40px; max-width: 720px; }
  .search-bar { padding: 0 40px; }
  .search-bar.open { padding: 0 40px 14px; }

  .bottom-nav { display: none; }
  .fab-btn { position: fixed; right: 48px; bottom: 48px; }
  .category-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .calc-sheet { left: 270px; right: 0; max-width: 640px; margin: 0 auto; }
}
