/* Finanzas — sistema de diseño (ver DESIGN.md en el root de finanzas) */
/* Fonts: Inter 400-800 (display + UI), JetBrains Mono 400-600 (datos tabulares) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* ── Superficies ── */
  --bg: #0a0a0a;
  --surface: #151515;
  --surface-2: #1f1f1f;
  --surface-3: #2a2a2a;
  --border: #2a2a2a;

  /* ── Texto ── */
  --text: #E8E6E1;
  --text-muted: #888888;
  --text-dim: #5a5a5a;
  --data-muted: #5a5a5a;

  /* ── Color semántico ── */
  --accent: #B87EFF;        /* morado Kinetic Noir — solo acciones primarias */
  --accent-2: #9461d8;
  --positive: #4ADE80;      /* ingresos y metas */
  --warning: #FBBF24;       /* gap, Real ≠ Est, próximo a vencer */
  --danger: #F87171;        /* overdue, alerta (1% casos) */

  /* ── Aliases legacy (no usar en código nuevo, solo para compat) ── */
  --amber: #FBBF24;
  --blue: #4D9FFF;
  --purple: #B87EFF;
  --pink: #FF6B9D;

  /* ── Tipografía ── */
  --font-display: "Inter", system-ui, -apple-system, sans-serif;
  --font-ui:      "Inter", system-ui, -apple-system, sans-serif;
  --font-data:    "JetBrains Mono", "SF Mono", Menlo, monospace;

  /* ── Radius ── */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Paper mode toggle: <body data-mode="paper"> */
[data-mode="paper"] {
  --bg: #F5F2EA;
  --surface: #EEEAE0;
  --surface-2: #E0D9C9;
  --surface-3: #C9C0AD;
  --border: #C9C0AD;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-dim: #9a9a9a;
  --data-muted: #9a9a9a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { background: var(--bg); color: var(--text); }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(80px + var(--safe-bottom));
}

/* Layout */
.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* Typography — ver DESIGN.md */
.page-sub   { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; font-family: var(--font-ui); }
.page-title { font-family: var(--font-display); font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; }
.label-xs   { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; font-family: var(--font-ui); }
.label-sm   { font-size: 12px; color: var(--text-muted); font-family: var(--font-ui); }

/* Cifras: usan font-data con tabular-nums */
.value-xl { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 32px; font-weight: 500; letter-spacing: -0.02em; line-height: 1; }
.value-lg { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.1; }
.value-md { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 500; }
.value-sm { font-family: var(--font-ui); font-size: 14px; font-weight: 500; }
.value-xs { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 500; }

/* Display headings (secciones, fechas) */
.display-lg { font-family: var(--font-display); font-weight: 800; font-size: 42px; line-height: 1.05; letter-spacing: -0.02em; }
.display-md { font-family: var(--font-display); font-weight: 800; font-size: 28px; line-height: 1;    letter-spacing: -0.02em; }
.display-sm { font-family: var(--font-display); font-weight: 700; font-size: 16px; line-height: 1.2;  letter-spacing: -0.01em; }

/* Page header */
.page-header {
  padding: 12px 0 20px;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}
.card-elevated { background: var(--surface-2); }
.card-hero {
  background: var(--surface-2);
  border-color: var(--border);
  padding: 20px 18px;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-start { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 500;
}
.chip.accent   { background: rgba(184, 126, 255, 0.12); color: var(--accent);   border-color: rgba(184, 126, 255, 0.3); }
.chip.positive { background: rgba(74, 222, 128, 0.12);  color: var(--positive); border-color: rgba(74, 222, 128, 0.3); }
.chip.amber    { background: rgba(251, 191, 36, 0.12);  color: var(--warning);  border-color: rgba(251, 191, 36, 0.3); }
.chip.blue     { background: rgba(77, 159, 255, 0.12);  color: var(--blue);     border-color: rgba(77, 159, 255, 0.3); }
.chip.purple   { background: rgba(184, 126, 255, 0.12); color: var(--purple);   border-color: rgba(184, 126, 255, 0.3); }
.chip.danger   { background: rgba(248, 113, 113, 0.12); color: var(--danger);   border-color: rgba(248, 113, 113, 0.3); }

/* Progress */
.progress {
  height: 6px; background: rgba(255, 255, 255, 0.06);
  border-radius: 3px; overflow: hidden; margin-top: 10px;
}
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s; }
.progress-bar.positive { background: var(--positive); }
.progress-bar.amber { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }
.progress-bar.blue { background: var(--blue); }
.progress-bar.purple { background: var(--purple); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
  border: 0;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); border-color: transparent; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 10px 0 calc(10px + var(--safe-bottom));
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-dim);
  font-size: 10px; font-weight: 500;
  flex: 1;
  text-decoration: none;
  padding: 4px 0;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 22px; line-height: 1; }

/* FAB */
.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  right: 20px;
  width: 56px; height: 56px;
  background: var(--accent);
  color: #0a0a0a;
  border: 0;
  border-radius: 50%;
  font-size: 28px; font-weight: 400;
  box-shadow: 0 6px 20px rgba(184, 126, 255, 0.35);
  cursor: pointer;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(0.95); }

/* Sec header */
.sec-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 18px 0 10px;
}
.sec-title { font-family: var(--font-display); font-size: 14px; color: var(--text); font-weight: 700; letter-spacing: -0.01em; }
.sec-link { font-family: var(--font-ui); font-size: 11px; color: var(--accent); font-weight: 500; text-decoration: none; cursor: pointer; text-transform: uppercase; letter-spacing: 0.04em; }

/* Delta */
.delta-up { color: var(--positive); font-size: 13px; font-weight: 500; font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.delta-down { color: var(--danger); font-size: 13px; font-weight: 500; font-family: var(--font-data); font-variant-numeric: tabular-nums; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-brand {
  font-family: var(--font-display);
  font-size: 42px; font-weight: 800; letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 8px;
}
.login-sub { color: var(--text-muted); margin-bottom: 32px; font-size: 14px; }
.login-google {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 24px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px; font-weight: 600;
  text-decoration: none;
}
.login-error {
  padding: 10px 14px;
  background: rgba(255, 71, 71, 0.12);
  border: 1px solid rgba(255, 71, 71, 0.3);
  color: #FFB4A9;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 20px;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-sub { font-size: 13px; line-height: 1.4; }

/* Utilities */
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* Toggle segmented */
.toggle-bar {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 3px;
  margin: 10px 0;
}
.toggle-seg {
  flex: 1; text-align: center; padding: 8px;
  font-size: 12px; color: var(--text-muted);
  border-radius: 9px; cursor: pointer;
  user-select: none;
}
.toggle-seg.active {
  font-weight: 600; background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tab-bar {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 4px;
  margin: 10px 0;
}
.tab-pill {
  flex: 1; padding: 9px 8px; text-align: center;
  font-size: 12px; font-weight: 500;
  color: var(--text-muted);
  border-radius: 9px; cursor: pointer;
  user-select: none;
}
.tab-pill.active {
  background: var(--surface); color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Group total header */
.group-total {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 4px 10px;
}
.group-total-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.group-total-sub { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.group-total-value { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 500; }

/* Account card */
.acct-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: inherit;
  cursor: pointer;
  transition: border-color 150ms ease-out;
}
.acct-card:hover { border-color: var(--surface-3); }
.acct-card:active { transform: scale(0.99); }
.acct-card.debt { border-color: rgba(248, 113, 113, 0.18); }
.acct-logo {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-ui);
  font-size: 14px; font-weight: 600;
  flex-shrink: 0; color: #fff;
  background: var(--surface-3);
}
.acct-body { flex: 1; min-width: 0; }
.acct-name { font-size: 14px; font-weight: 600; font-family: var(--font-ui); }
.acct-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-family: var(--font-ui); }
.acct-value { text-align: right; white-space: nowrap; }
.acct-amt { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 500; }
.acct-delta { font-size: 10px; margin-top: 2px; color: var(--text-muted); font-family: var(--font-ui); }

/* Modal sheet */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  display: flex; align-items: flex-end;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}
.modal-sheet {
  width: 100%;
  background: var(--surface-2);
  border-radius: 28px 28px 0 0;
  padding: 14px 20px calc(28px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  max-height: 92%;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-backdrop.show .modal-sheet { transform: translateY(0); }
.grip { width: 40px; height: 4px; background: #444; border-radius: 2px; margin: 0 auto 16px; }

/* Capture amount display */
.amount-display {
  text-align: center;
  padding: 20px 0 16px;
}
.amount-sign { font-family: var(--font-data); font-size: 24px; color: var(--text-muted); font-weight: 500; vertical-align: top; margin-right: 4px; }
.amount-value {
  font-family: var(--font-data); font-variant-numeric: tabular-nums;
  font-size: 52px; font-weight: 500;
  letter-spacing: -0.02em; line-height: 1.1;
}
.amount-dim { color: var(--text-dim); }

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.num-btn {
  padding: 16px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 22px; font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s;
}
.num-btn:active { transform: scale(0.95); background: var(--surface-2); }
.num-btn.action {
  color: var(--accent);
  font-size: 18px;
}

/* Category chips */
.cat-chips {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 10px 0;
}
.cat-chip {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.cat-chip:active { transform: scale(0.96); }
.cat-chip.suggested {
  background: rgba(184, 126, 255, 0.12);
  color: var(--accent);
  border-color: rgba(184, 126, 255, 0.35);
}
.cat-chip.selected {
  background: var(--accent);
  color: #0a0a0a; font-weight: 600;
  border-color: var(--accent);
}

/* Option rows in modal */
.opt-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  font-size: 13px;
}
.opt-label { color: var(--text-muted); }
.opt-pill {
  padding: 4px 10px;
  background: var(--surface);
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.opt-pill.selected {
  background: rgba(184, 126, 255, 0.12);
  color: var(--accent);
  border-color: rgba(184, 126, 255, 0.35);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 18px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Drill-down overlay */
.drill {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 90;
  overflow-y: auto;
  padding-bottom: calc(80px + var(--safe-bottom));
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.drill.open { transform: translateX(0); }

/* Nav back */
.nav-back {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px 8px;
}
.back-btn {
  width: 36px; height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer;
  color: var(--text);
}

/* Timeline tx */
.tx-row {
  display: flex; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.tx-row:last-child { border: 0; }
.tx-icon {
  width: 38px; height: 38px;
  background: var(--surface-2);
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.tx-body { flex: 1; min-width: 0; }
.tx-title { font-family: var(--font-ui); font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-family: var(--font-ui); font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.tx-amount { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 500; text-align: right; white-space: nowrap; }
.tx-amount.pos { color: var(--positive); }
.tx-amount.neg { color: var(--text); }  /* gastos no se pintan de rojo */

/* Ledger table (vistas tipo planilla: DashBoard, JONA, TDCs) */
.ledger { width: 100%; border-collapse: collapse; font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.ledger thead th {
  text-align: left; font-family: var(--font-ui); font-weight: 500;
  font-size: 10px; color: var(--text-muted);
  padding: 8px 10px; letter-spacing: 0.04em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.ledger thead th.num { text-align: right; }
.ledger thead th.status { text-align: center; width: 36px; }
.ledger tbody td {
  padding: 9px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: baseline;
}
.ledger tbody tr:last-child td { border-bottom: 0; }
.ledger td.concept { font-family: var(--font-ui); font-weight: 500; color: var(--text); }
.ledger td.num { text-align: right; color: var(--text); }
.ledger td.num.muted { color: var(--data-muted); }
.ledger td.num.real { font-weight: 500; }
.ledger td.num.diff { color: var(--warning); }
.ledger td.num.in   { color: var(--positive); }
.ledger td.status { text-align: center; width: 36px; }
.ledger td.status.paid { color: var(--positive); }
.ledger td.status.pending { color: var(--data-muted); }
.ledger td.status.overdue { color: var(--danger); }
.ledger tr.income td.concept { color: var(--positive); }
.ledger tr.total td { border-top: 1px solid var(--text); border-bottom: 0; font-weight: 500; padding-top: 12px; }

/* Institution logos (bank colors) */
.logo-1 { background: linear-gradient(135deg, #EC0000, #B40000); }  /* Santander */
.logo-2 { background: linear-gradient(135deg, #6A00F4, #3D00A8); }  /* Tenpo */
.logo-3 { background: linear-gradient(135deg, #1D3B7A, #0E1F42); }  /* BCI */
.logo-4 { background: linear-gradient(135deg, #64B32C, #3E7F16); }  /* Falabella */
.logo-5 { background: linear-gradient(135deg, #F5A623, #C97A00); }  /* Copec */
.logo-6 { background: linear-gradient(135deg, #F7931A, #C87214); }  /* Bitcoin */
.logo-7 { background: linear-gradient(135deg, #EC7000, #B45000); }  /* Itaú */
.logo-debt { background: linear-gradient(135deg, var(--danger), #B40000); }
