/* ===== VARIABLES ===== */
:root {
  --bg: #0c0c0f;
  --surface: #131318;
  --surface2: #1c1c24;
  --border: #232330;
  --red: #e53e3e;
  --red-dark: #c53030;
  --red-soft: rgba(229,62,62,0.1);
  --green: #38a169;
  --green-soft: rgba(56,161,105,0.12);
  --yellow: #d97706;
  --yellow-soft: rgba(217,119,6,0.12);
  --text: #f0f0f5;
  --text2: #9090a8;
  --text3: #50506a;
  --shadow: 0 8px 24px rgba(0,0,0,0.5);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface2: #e8e8f0;
  --border: #d8d8e8;
  --text: #0a0a14;
  --text2: #44445a;
  --text3: #9090a8;
  --shadow: 0 8px 24px rgba(0,0,0,0.1);
}

/* ===== BASE ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Plus Jakarta Sans', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; font-size: 15px; transition: background .2s, color .2s; }
a { color: var(--red); text-decoration: none; font-weight: 600; }
select option { background: var(--surface); color: var(--text); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 700; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.06em; }
.form-input {
  width: 100%; background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 14px;
  font-family: inherit; color: var(--text); outline: none; transition: border-color .2s, background .2s;
}
.form-input:focus { border-color: var(--red); }
.form-select {
  width: 100%; background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 11px; font-size: 13px;
  font-family: inherit; color: var(--text); outline: none; cursor: pointer; transition: border-color .2s;
}
.form-select:focus { border-color: var(--red); }
.form-error { color: #fc8181; font-size: 13px; margin-top: 8px; display: none; }

/* ===== BUTTONS ===== */
.btn-red {
  padding: 12px 20px; background: var(--red); border: none; border-radius: var(--radius-sm);
  color: white; font-size: 14px; font-weight: 700; font-family: inherit; cursor: pointer; transition: background .2s, transform .1s;
}
.btn-red:hover { background: var(--red-dark); }
.btn-red:active { transform: scale(0.99); }
.btn-red.full { width: 100%; }
.btn-ghost {
  padding: 10px 18px; background: none; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2); font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: all .2s;
}
.btn-ghost:hover { border-color: var(--text2); color: var(--text); }
.btn-danger {
  padding: 10px 18px; background: none; border: 1.5px solid var(--red);
  border-radius: var(--radius-sm); color: var(--red); font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: all .2s;
}
.btn-danger:hover { background: var(--red-soft); }

/* ===== LOGIN ===== */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 40%, rgba(229,62,62,0.08) 0%, transparent 55%), var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 44px 38px; width: 100%; max-width: 400px; box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand h1 { font-size: 34px; font-weight: 800; letter-spacing: -1px; color: var(--red); }
.login-brand p { font-size: 14px; color: var(--text2); margin-top: 4px; }
.login-link { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text2); }

/* ===== APP HEADER ===== */
#app-screen { display: none; }
.header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 20px; display: flex; align-items: center; justify-content: space-between;
  height: 58px; position: sticky; top: 0; z-index: 100; transition: background .2s;
}
.brand { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; color: var(--red); flex-shrink: 0; }
.header-nav { display: flex; gap: 4px; }
.nav-btn {
  padding: 7px 16px; border-radius: 7px; border: none; background: none;
  color: var(--text2); font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer; transition: all .2s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--red-soft); color: var(--red); }
.header-right { display: flex; align-items: center; gap: 8px; }

/* Install button */
.btn-install {
  display: none; align-items: center; gap: 6px; padding: 7px 14px;
  background: var(--red-soft); border: 1px solid var(--red);
  border-radius: var(--radius-sm); color: var(--red); font-size: 13px; font-weight: 700;
  font-family: inherit; cursor: pointer; transition: all .2s; flex-shrink: 0;
}
.btn-install:hover { background: var(--red); color: white; }
.btn-install.visible { display: flex; }

/* Theme toggle */
.btn-theme {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: none; color: var(--text2); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .2s; flex-shrink: 0;
}
.btn-theme:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }

/* Desktop user info */
.desktop-user { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--red);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: white; flex-shrink: 0;
}
.uname { font-size: 14px; font-weight: 600; color: var(--text2); }
.btn-out {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text3); font-size: 13px; font-family: inherit; padding: 5px 10px; cursor: pointer; transition: all .2s;
}
.btn-out:hover { border-color: var(--red); color: var(--red); }

/* Hamburger (mobile only) */
.btn-hamburger {
  display: none; width: 38px; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: none; color: var(--text2);
  font-size: 20px; cursor: pointer; align-items: center; justify-content: center; transition: all .2s;
}
.btn-hamburger:hover { border-color: var(--red); color: var(--red); }

/* ===== MOBILE DRAWER ===== */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
.drawer-overlay.open { opacity: 1; pointer-events: all; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 280px;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 201; transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; padding: 0;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-close {
  background: none; border: none; font-size: 22px; color: var(--text2);
  cursor: pointer; padding: 4px; border-radius: 6px; transition: color .2s;
}
.drawer-close:hover { color: var(--red); }
.drawer-user { display: flex; align-items: center; gap: 12px; }
.drawer-avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--red);
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; color: white;
}
.drawer-name { font-size: 16px; font-weight: 700; color: var(--text); }
.drawer-body { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.drawer-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-size: 14px; font-weight: 600; color: var(--text); background: var(--bg);
}
.drawer-item span { color: var(--text2); font-size: 13px; }
.theme-toggle-row { cursor: pointer; transition: border-color .2s; }
.theme-toggle-row:hover { border-color: var(--red); }
.toggle-switch {
  width: 44px; height: 24px; border-radius: 12px; background: var(--border);
  position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle-switch.on { background: var(--red); }
.toggle-knob {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: white; transition: left .2s;
}
.toggle-switch.on .toggle-knob { left: 23px; }
.drawer-install {
  display: none; align-items: center; gap: 10px; padding: 14px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--red);
  background: var(--red-soft); font-size: 14px; font-weight: 600; color: var(--red);
  cursor: pointer; transition: all .2s;
}
.drawer-install.visible { display: flex; }
.drawer-install:hover { background: var(--red); color: white; }
.drawer-footer { padding: 20px; border-top: 1px solid var(--border); }
.btn-out-drawer {
  width: 100%; padding: 12px; background: none; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2); font-size: 14px; font-weight: 700;
  font-family: inherit; cursor: pointer; transition: all .2s;
}
.btn-out-drawer:hover { border-color: var(--red); color: var(--red); }

/* ===== PANELS ===== */
.panel { display: none; padding: 24px 20px; max-width: 1100px; margin: 0 auto; }
.panel.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; transition: background .2s; }
.card-title { font-size: 13px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 18px; }

/* ===== REGISTRO ===== */
.reg-grid { display: grid; grid-template-columns: 390px 1fr; gap: 20px; align-items: start; }
.type-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.type-btn {
  padding: 12px; border-radius: var(--radius-sm); border: 2px solid var(--border);
  background: none; color: var(--text2); font-size: 14px; font-weight: 700;
  font-family: inherit; cursor: pointer; transition: all .2s; text-align: center;
}
.type-btn.ingreso.active { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.type-btn.gasto.active { border-color: var(--yellow); background: var(--yellow-soft); color: var(--yellow); }
.cat-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 6px; margin-bottom: 4px; }
.cat-btn {
  padding: 9px 10px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: none; color: var(--text2); font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: all .15s; text-align: left;
}
.cat-btn:hover { border-color: var(--red); color: var(--text); }
.cat-btn.active { border-color: var(--yellow); background: var(--yellow-soft); color: var(--yellow); }
.date-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.amt-wrap { position: relative; }
.amt-prefix { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; font-weight: 700; color: var(--text2); font-family: 'Space Mono', monospace; }
.form-input.amt { padding-left: 30px; font-family: 'Space Mono', monospace; font-size: 14px; }

/* ===== TX LIST (recent) ===== */
.tx-list { display: flex; flex-direction: column; gap: 7px; }
.tx-item {
  display: flex; align-items: center; padding: 12px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); gap: 10px;
}
.tx-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tx-dot.ingreso { background: var(--green); box-shadow: 0 0 6px var(--green); }
.tx-dot.gasto { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.tx-info { flex: 1; min-width: 0; }
.tx-desc { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.tx-amt { font-family: 'Space Mono', monospace; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.tx-amt.ingreso { color: var(--green); }
.tx-amt.gasto { color: var(--yellow); }
.tx-edit {
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-size: 15px; padding: 4px 6px; border-radius: 5px; transition: all .2s; flex-shrink: 0;
}
.tx-edit:hover { color: var(--red); background: var(--red-soft); }
.empty { text-align: center; padding: 30px; color: var(--text3); font-size: 14px; }
.loader { text-align: center; padding: 20px; color: var(--text2); font-size: 14px; }

/* ===== EDIT MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 440px; box-shadow: var(--shadow);
  transform: translateY(20px); transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-title { font-size: 17px; font-weight: 800; margin-bottom: 22px; color: var(--text); }
.modal-footer { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 6px; }

/* ===== DASHBOARD ===== */
.month-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.mnav-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); padding: 8px 14px; cursor: pointer; font-family: inherit; font-size: 20px; transition: all .2s;
}
.mnav-btn:hover { border-color: var(--red); color: var(--red); }
.month-lbl { flex: 1; text-align: center; font-size: 20px; font-weight: 800; letter-spacing: -0.3px; text-transform: capitalize; }

/* Summary cards */
.sum-cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; margin-bottom: 20px; }
.sum-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; position: relative; overflow: hidden; transition: background .2s; }
.sum-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.sum-card.in::before { background: var(--green); }
.sum-card.out::before { background: var(--yellow); }
.sum-card.bal::before { background: var(--red); }
.sum-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text2); margin-bottom: 8px; }
.sum-val { font-family: 'Space Mono', monospace; font-size: 21px; font-weight: 700; }
.sum-card.in .sum-val { color: var(--green); }
.sum-card.out .sum-val { color: var(--yellow); }
.sum-card.bal .sum-val { color: var(--red); }
.sum-sub { font-size: 13px; color: var(--text2); margin-top: 4px; }
.prog-wrap { margin-top: 10px; }
.prog-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text2); margin-bottom: 5px; }
.prog-label span:last-child { font-weight: 700; color: var(--yellow); }
.prog-label span:last-child.over { color: var(--red); }
.prog-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 3px; background: var(--yellow); transition: width .5s; }
.prog-fill.over { background: var(--red); }

/* Charts */
.charts-grid { display: grid; grid-template-columns: 1fr 360px; gap: 14px; margin-bottom: 20px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: background .2s; }
.chart-card h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text2); margin-bottom: 14px; }
.chart-wrap { position: relative; height: 210px; }

/* Custom pie legend (list) */
.pie-legend { margin-top: 16px; display: flex; flex-direction: column; gap: 7px; }
.pie-legend-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--border);
}
.pie-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.pie-legend-name { flex: 1; font-size: 13px; font-weight: 500; color: var(--text); }
.pie-legend-amt { font-family: 'Space Mono', monospace; font-size: 13px; font-weight: 700; color: var(--yellow); flex-shrink: 0; }

/* Month tx list */
.month-txs { display: flex; flex-direction: column; gap: 6px; max-height: 400px; overflow-y: auto; }
.mtx { display: flex; align-items: center; padding: 10px 14px; border-radius: var(--radius-sm); gap: 10px; }
.mtx.ingreso { background: var(--green-soft); border: 1px solid rgba(56,161,105,0.2); }
.mtx.gasto { background: var(--yellow-soft); border: 1px solid rgba(217,119,6,0.2); }
.mtx-day { font-size: 12px; font-family: 'Space Mono', monospace; color: var(--text2); min-width: 26px; }
.mtx-cat { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; flex-shrink: 0; }
.ingreso .mtx-cat { background: rgba(56,161,105,0.2); color: var(--green); }
.gasto .mtx-cat { background: rgba(217,119,6,0.2); color: var(--yellow); }
.mtx-desc { flex: 1; font-size: 13px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.mtx-amt { font-family: 'Space Mono', monospace; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.ingreso .mtx-amt { color: var(--green); }
.gasto .mtx-amt { color: var(--yellow); }
.no-data { text-align: center; padding: 42px; color: var(--text3); font-size: 14px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 22px; right: 22px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 9px; padding: 13px 18px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  transform: translateY(70px); opacity: 0; transition: all .3s; z-index: 999; color: var(--text);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.ok { border-color: var(--green); color: var(--green); }
.toast.err { border-color: var(--red); color: var(--red); }

/* ===== REGISTER PAGE ===== */
.register-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 70% 30%, rgba(229,62,62,0.07) 0%, transparent 55%), var(--bg);
}
.register-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 44px 38px; width: 100%; max-width: 400px; box-shadow: var(--shadow);
}
.register-brand { text-align: center; margin-bottom: 28px; }
.register-brand h1 { font-size: 30px; font-weight: 800; letter-spacing: -1px; color: var(--red); }
.register-brand p { font-size: 14px; color: var(--text2); margin-top: 4px; }
.success-msg { color: #68d391; font-size: 14px; text-align: center; margin-top: 10px; display: none; }

/* ===== RESPONSIVE ===== */
@media (max-width: 860px) {
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .reg-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .sum-cards { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .desktop-user { display: none; }
  .btn-install { display: none !important; }
  .btn-theme { display: none; }
  .btn-hamburger { display: flex; }
  .header { padding: 0 16px; }
  .panel { padding: 16px; }
  .card { padding: 16px; }
  .login-card, .register-card { padding: 32px 24px; margin: 16px; }
  .modal-footer { grid-template-columns: 1fr; }
  .month-lbl { font-size: 16px; }
  .sum-val { font-size: 18px; }
}
