:root {
  --bg: #f9f7f3;
  --surface: #ffffff;
  --text: #264653;
  --muted: #6b8a93;
  --border: #e5e2d8;
  --accent: #2a9d8f;
  --accent-contrast: #ffffff;
  --danger: #b91c1c;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16262b;
    --surface: #264653;
    --text: #f9f7f3;
    --muted: #9dbec7;
    --border: #35545f;
    --accent: #0fa3b1;
    --accent-contrast: #06181b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 28px; height: 28px; border-radius: 8px; display: block; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--border); }

.view { padding: 16px; max-width: 900px; margin: 0 auto; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.pocket-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.pocket-card h3 { margin: 0 0 6px; font-size: 0.95rem; }
.pocket-card .balance-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.02em; }
.pocket-card .balance { font-size: 1.3rem; font-weight: 700; }
.pocket-card .balance.negative { color: var(--danger); }
.pocket-card .budget { color: var(--muted); font-size: 0.8rem; margin-top: 4px; margin-bottom: 8px; }
.pocket-card .secondary-balance {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 999px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 1rem; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-header h2 { margin: 0; }

.txn-list { display: flex; flex-direction: column; gap: 10px; }
.txn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.txn-row:last-child { border-bottom: none; }
.txn-meta { display: flex; flex-direction: column; }
.txn-meta .desc { font-size: 0.85rem; color: var(--muted); }
.txn-amount.gasto { color: var(--danger); font-weight: 700; }
.txn-amount.ingreso { color: var(--accent); font-weight: 700; }

.month-nav { gap: 10px; }
.month-nav h2 { flex: 1; text-align: center; }

.totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.total-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.total-tile .label { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.total-tile .value { font-size: 1.15rem; font-weight: 700; }
.total-tile.highlight { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: var(--accent); }

/* Tabla tipo hoja de calculo: bordes en todas las celdas, encabezado fijo visualmente */
.sheet-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.sheet-table th, .sheet-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: right;
}
.sheet-table th:first-child, .sheet-table td:first-child { text-align: left; }
.sheet-table thead th { background: var(--bg); color: var(--muted); font-weight: 600; }
.sheet-table tfoot td { font-weight: 700; background: var(--bg); }
.sheet-table .muted-col { color: var(--muted); }
.sheet-table .diff-pos { color: var(--accent); }
.sheet-table .diff-neg { color: var(--danger); }

.progress-inline { display: flex; align-items: center; gap: 8px; }
.progress-inline .progress-track { flex: 1; min-width: 60px; }
.progress-inline span { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

.primary-btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
}
.danger-link { color: var(--danger); cursor: pointer; background: none; border: none; font-size: 0.85rem; }

.filters { margin-bottom: 12px; }
select, input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.9rem;
}

dialog {
  border: none;
  border-radius: 14px;
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  max-width: 420px;
  width: 90vw;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  font-size: 1.1rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.tab-btn span { font-size: 0.65rem; }
.tab-btn.active { color: var(--accent); }

.qr-box { text-align: center; padding: 20px 0; }
.qr-box img { max-width: 260px; width: 100%; border-radius: 12px; border: 1px solid var(--border); }
.status-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-pill.ready { background: #d1fae5; color: #065f46; }
.status-pill.qr { background: #fef3c7; color: #92400e; }
.status-pill.disconnected, .status-pill.starting { background: #fee2e2; color: #991b1b; }
.status-pill.not_linked { background: var(--border); color: var(--muted); }

/* Landing / login / registro / onboarding -- misma paleta que el resto de la app (slate oscuro +
   teal), solo que aqui el fondo siempre es el slate oscuro sin importar el tema del sistema. */
:root {
  --navy-deep: #16262b;
  --navy-mid: #264653;
  --indigo: #2a9d8f;
  --indigo-hover: #23897d;
  --indigo-soft: #b5e2fa;
}

.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 20% 100%, rgba(15, 163, 177, 0.35), transparent 55%),
    linear-gradient(160deg, var(--navy-deep), var(--navy-mid));
}
.auth-view[hidden] { display: none; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.auth-back-link {
  position: absolute;
  top: 16px;
  left: 18px;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}
.auth-logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 8px; }
.auth-card h1 { font-size: 1.15rem; margin: 0 0 16px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; text-align: left; margin-bottom: 12px; }
.auth-form[hidden] { display: none; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.auth-form .primary-btn { margin-top: 4px; }
.auth-error {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

.indigo-btn { background: var(--indigo); }
.indigo-btn:hover { background: var(--indigo-hover); }
.outline-indigo-btn { border-color: var(--indigo); color: #b5e2fa; }

/* ---------- Landing ---------- */
.landing-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
}
.landing-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.landing-nav-links { display: flex; align-items: center; gap: 20px; }
.landing-nav-links a { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.landing-nav-links a:hover { color: var(--text); }

.landing-hero {
  background: radial-gradient(circle at 15% 110%, rgba(15, 163, 177, 0.45), transparent 55%),
    linear-gradient(160deg, var(--navy-deep), var(--navy-mid));
  padding: 56px 24px 80px;
}
.landing-hero-inner { max-width: 640px; margin: 0 auto; }
.eyebrow {
  color: #b5e2fa;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 14px;
}
.eyebrow-dark { color: var(--indigo); text-align: center; }
.landing-hero h1 {
  color: #fff;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  line-height: 1.15;
  margin: 0 0 16px;
  font-weight: 800;
}
.landing-subtext { color: #d6ecf2; font-size: 1rem; line-height: 1.6; margin: 0 0 28px; }
.landing-cta-row { display: flex; flex-wrap: wrap; gap: 12px; }
.landing-cta-row .primary-btn, .landing-cta-row .ghost-btn { padding: 12px 22px; font-size: 0.95rem; }

.landing-demo { padding: 64px 24px; max-width: 720px; margin: 0 auto; text-align: center; }
.landing-demo h2 { font-size: clamp(1.4rem, 4vw, 1.8rem); margin: 6px 0 10px; }
.landing-section-subtext { color: var(--muted); margin: 0 0 28px; }

.demo-window {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  text-align: left;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}
.demo-window-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.demo-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.demo-window-title { margin-left: 8px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.demo-chat { padding: 20px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); }
.demo-bubble { padding: 10px 14px; border-radius: 14px; font-size: 0.9rem; line-height: 1.5; max-width: 80%; }
.demo-bubble-user {
  align-self: flex-end;
  background: var(--indigo);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.demo-bubble-bot {
  align-self: flex-start;
  background: var(--indigo-soft);
  color: #17323a;
  border-bottom-left-radius: 4px;
}

.landing-features { background: var(--bg); padding: 64px 24px; }
.landing-features h2 { text-align: center; font-size: clamp(1.4rem, 4vw, 1.8rem); margin: 0 0 32px; }
.landing-features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  max-width: 960px;
  margin: 0 auto;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.feature-icon { font-size: 1.6rem; margin-bottom: 10px; }
.feature-card h3 { margin: 0 0 8px; font-size: 1rem; }
.feature-card p { margin: 0; color: var(--muted); font-size: 0.85rem; line-height: 1.5; }

.landing-cta-final {
  text-align: center;
  padding: 64px 24px;
  background: linear-gradient(160deg, var(--navy-deep), var(--navy-mid));
}
.landing-cta-final h2 { color: #fff; margin: 0 0 20px; font-size: clamp(1.3rem, 4vw, 1.7rem); }

.landing-footer { text-align: center; padding: 32px 24px; background: var(--surface); }
.landing-footer p { margin: 4px 0; font-size: 0.85rem; }

.toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  z-index: 100;
}
.toast[hidden] { display: none; }

.onboarding-steps { text-align: left; padding-left: 20px; margin: 16px 0; line-height: 1.6; }
.onboarding-code {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 14px;
  margin: 12px 0;
}
#onboarding-screen .ghost-btn { margin: 6px 4px 0; }
