/* === Finanzas Personales — Sistema de diseño === */
:root {
  --primary: #2563EB;
  --primary-700: #1D4ED8;
  --secondary: #0EA5E9;
  --bg: #0F172A;
  --bg-2: #131f38;
  --surface: #1E293B;
  --surface-2: #243349;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --border: #334155;
  --success: #22C55E;
  --destructive: #EF4444;
  --warning: #F59E0B;
  --radius-card: 12px;
  --radius-input: 8px;
  --shadow: 0 4px 16px rgba(0,0,0,.25);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, #1b2a4a 0%, var(--bg) 55%);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; }

a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: rgba(15,23,42,.85); border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.sidebar .brand { font-size: 19px; font-weight: 700; padding: 8px 10px 16px; letter-spacing: -.3px; }
.sidebar .brand span { color: var(--primary); }
.navlink {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500; transition: all .15s ease;
}
.navlink:hover { background: var(--surface); color: var(--text); }
.navlink.active { background: var(--primary); color: #fff; }
.navlink .ic { width: 18px; text-align: center; }
.sidebar .spacer { flex: 1; }
.sidebar .userbox { font-size: 13px; color: var(--muted); padding: 10px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(15,23,42,.7); backdrop-filter: blur(8px); z-index: 10;
}
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.content { padding: 24px 28px; max-width: 1200px; margin: 0 auto; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 18px; box-shadow: var(--shadow);
}
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .value.pos { color: var(--success); }
.stat .value.neg { color: var(--destructive); }
.stat-action {
  width: 100%; text-align: left; color: var(--text);
  transition: border-color .15s ease, background .15s ease, transform .05s ease;
}
.stat-action:hover { background: var(--surface-2); border-color: rgba(37,99,235,.65); }
.stat-action:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,.25); border-color: var(--primary); }
.stat-action:active { transform: translateY(1px); }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* ---- Floating label inputs ---- */
.field { position: relative; margin-bottom: 18px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-input); padding: 16px 12px 8px; font-size: 15px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea { min-height: 70px; resize: vertical; }
/* El select siempre muestra un valor → más espacio arriba para el label flotante. */
.field select { padding: 22px 12px 8px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.25);
}
.field label {
  position: absolute; left: 12px; top: 13px; color: var(--muted); font-size: 15px;
  pointer-events: none; transition: all .15s ease; background: transparent;
}
.field input:focus + label, .field input:not(:placeholder-shown) + label,
.field textarea:focus + label, .field textarea:not(:placeholder-shown) + label {
  top: 5px; font-size: 11px; color: var(--primary); font-weight: 600; letter-spacing: .2px;
}
/* El label de un select va SIEMPRE arriba (nunca se superpone al texto del valor). */
.field select + label {
  top: 5px; font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .2px;
}
.field select:focus + label { color: var(--primary); }
.field input::placeholder, .field textarea::placeholder { color: transparent; }

/* ---- Buttons ---- */
.btn {
  background: var(--primary); color: #fff; border: none; border-radius: var(--radius-input);
  padding: 11px 18px; font-weight: 600; font-size: 14px; transition: background .15s ease, transform .05s;
}
.btn:hover { background: var(--primary-700); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--destructive); }
.btn.success { background: var(--success); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Tables / lists ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tr:hover td { background: rgba(255,255,255,.02); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.pending { background: rgba(245,158,11,.18); color: var(--warning); }
.badge.approved { background: rgba(234,179,8,0.15); color: #EAB308; }
.badge.active { background: rgba(34,197,94,.18); color: var(--success); }
.badge.disabled { background: rgba(148,163,184,.18); color: var(--muted); }
.badge.rejected { background: rgba(239,68,68,0.15); color: #EF4444; }
.badge.income { background: rgba(34,197,94,.18); color: var(--success); }
.badge.expense { background: rgba(239,68,68,.18); color: var(--destructive); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---- Month switcher ---- */
.month-switch { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; }
.month-switch button { background: transparent; border: none; color: var(--text); width: 32px; height: 32px; border-radius: 50%; font-size: 16px; }
.month-switch button:hover { background: var(--surface-2); }
.month-switch .label { padding: 0 10px; font-weight: 600; min-width: 120px; text-align: center; text-transform: capitalize; }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 24px; width: 100%; max-width: 460px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 19px; margin-bottom: 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.subscriptions-modal { max-width: 640px; }
.subscription-summary {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-input);
  padding: 12px 14px; margin-bottom: 14px;
}
.subscription-summary strong { font-size: 20px; }
.subscription-detail-table { max-height: 52vh; overflow: auto; }
.subscription-empty { padding: 34px 16px; }

/* ---- Auth pages ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 4px; letter-spacing: -.5px; }
.auth-card .brand span { color: var(--primary); }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.btn-google { width: 100%; background: #fff; color: #1f2937; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn-google:hover { background: #f3f4f6; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-foot { text-align: center; margin-top: 18px; font-size: 14px; color: var(--muted); }

/* ---- Toast ---- */
.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--primary); padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); min-width: 240px; animation: slidein .2s ease; }
.toast.error { border-left-color: var(--destructive); }
.toast.success { border-left-color: var(--success); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---- Misc ---- */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .ic { font-size: 40px; margin-bottom: 10px; opacity: .5; }
.loading { text-align: center; color: var(--muted); padding: 40px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions-inline { display: flex; gap: 6px; }
.section-title { font-size: 16px; font-weight: 700; margin: 6px 0 12px; }
.tree-child { padding-left: 26px; }
.category-tree { display: grid; gap: 6px; }
.category-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 8px 6px calc(8px + (var(--level, 0) * 24px));
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  transition: background .15s ease, border-color .15s ease;
}
.category-row:hover { background: rgba(255,255,255,.025); border-color: rgba(148,163,184,.18); }
.category-row.is-disabled .chip { opacity: .58; }
.category-row.is-disabled .dot { filter: grayscale(1); opacity: .65; }
.category-toggle {
  width: 28px; height: 28px; border: none; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 15px; line-height: 1; transition: background .15s ease, color .15s ease;
}
.category-toggle:not(:disabled):hover { background: var(--surface-2); color: var(--text); }
.category-toggle:disabled { cursor: default; opacity: .5; }
.category-main {
  display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer;
}
.category-main .chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-count { font-size: 12px; white-space: nowrap; }
.category-children { display: grid; gap: 6px; }
.error-text { color: var(--destructive); font-size: 13px; margin-top: -10px; margin-bottom: 12px; }
.amount-pos { color: var(--success); }
.amount-neg { color: var(--destructive); }
canvas { max-height: 280px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s ease; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex !important; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .category-row { grid-template-columns: 28px minmax(0, 1fr); }
  .category-row .actions-inline { grid-column: 2; flex-wrap: wrap; }
}
.menu-toggle { display: none; background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 38px; height: 38px; font-size: 18px; }

.nav-group-header { cursor: pointer; }
.nav-group-header .caret { margin-left: auto; transition: transform .15s ease; font-size: 11px; }
.nav-group.open .nav-group-header .caret { transform: rotate(90deg); }
.nav-sub { display: none; flex-direction: column; gap: 4px; margin: 2px 0 2px 14px; padding-left: 10px; border-left: 1px solid var(--border); }
.nav-group.open .nav-sub { display: flex; }
.navlink.navsub { padding: 8px 10px; font-size: 14px; }
