:root {
  color-scheme: light;
  --page:           #f7f9f7;
  --surface-1:      #ffffff;
  --surface-2:      #eef1ee;
  --text-primary:   #151a15;
  --text-secondary: #565c53;
  --text-muted:     #878d84;
  --border:         rgba(20, 40, 20, 0.08);
  --border-strong:  rgba(20, 40, 20, 0.15);
  --success:        #087f4b;
  --danger:         #d03b3b;
  --warning:        #b47804;

  --accent:         #008300;
  --accent-hover:   #006300;
  --accent-ring:    rgba(0, 131, 0, 0.20);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --shadow-sm: 0 1px 2px rgba(15, 30, 15, 0.05);
  --shadow-card: 0 1px 2px rgba(15, 30, 15, 0.04), 0 12px 28px -10px rgba(15, 30, 15, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --font-display: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Blanco es la identidad visual del producto — un solo look, deliberado,
   sin variante oscura automática por preferencia de sistema. */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, .balance-value, .brand, .brand-small {
  font-family: var(--font-display);
  text-wrap: balance;
}

.app-shell { min-height: 100vh; }

.muted { color: var(--text-secondary); font-size: 0.9rem; }

.eyebrow {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Brand mark — icono ilustrado del mayordomo */
.mark {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.mark-sm { width: 30px; height: 30px; }

/* Icono de línea (categorías, listas) */
.icon {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
  z-index: 20;
}

.spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.4s; }
  .view { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

.view { animation: rise 0.35s ease both; }

.view-dashboard.is-loading { opacity: 0.6; pointer-events: none; transition: opacity 0.15s ease; }

/* ── Login ───────────────────────────────────────────────── */

.view-login {
  max-width: 600px;
  margin: 0 auto;
  padding: 28px 18px 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 86vh;
}

.login-card {
  width: 100%;
  max-width: 372px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.login-banner {
  display: flex;
  justify-content: center;
  padding: 24px 20px 4px;
}

.login-banner img { width: 100%; max-width: 240px; height: auto; display: block; }

.login-body { padding: 8px 30px 32px; }

.brand-small { font-family: var(--font-display); font-weight: 800; font-size: 0.98rem; letter-spacing: -0.01em; }
.brand-row { display: flex; align-items: center; gap: 10px; }

.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.84rem; color: var(--text-secondary); font-weight: 500; }

.field input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder { color: var(--text-muted); }

.field input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.btn {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.65; cursor: default; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(23, 18, 46, 0.08), 0 4px 12px -4px var(--accent-ring);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-weight: 550;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}
.btn-ghost:hover { border-color: var(--text-muted); }

.link-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.btn-link {
  background: none;
  color: var(--accent);
  font-weight: 550;
  font-size: 0.83rem;
  padding: 4px 0;
}
.btn-link:hover { color: var(--accent-hover); }

.error { color: var(--danger); font-size: 0.83rem; margin: 0; }

/* ── Dashboard ───────────────────────────────────────────── */

.dash-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar { display: none; }

.dash-main {
  flex: 1;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 16px calc(88px + env(safe-area-inset-bottom));
}

.topbar-mobile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

/* Barra inferior (móvil) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}

.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 6px 2px;
  font-family: var(--font-body);
  font-size: 0.64rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.bottom-nav .nav-item .icon { width: 20px; height: 20px; }
.bottom-nav .nav-item.is-active { color: var(--accent); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (min-width: 900px) {
  .dash-shell {
    flex-direction: row;
    max-width: 1180px;
    margin: 0 auto;
  }

  .topbar-mobile,
  .bottom-nav { display: none; }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 224px;
    flex-shrink: 0;
    padding: 32px 16px;
    border-right: 1px solid var(--border);
    min-height: 100vh;
    position: sticky;
    top: 0;
  }

  .sidebar-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 30px; padding: 0 10px; }

  .sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

  .sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: none;
    border: none;
    font-family: var(--font-body);
    font-size: 0.87rem;
    font-weight: 550;
    color: var(--text-secondary);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
  }
  .sidebar .nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
  .sidebar .nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
  .sidebar .nav-item.is-active { background: var(--accent); color: #fff; }

  .sidebar-footer {
    padding: 14px 10px 0;
    border-top: 1px solid var(--border);
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .dash-main { max-width: 720px; padding: 36px 44px 48px; margin: 0; }
}

.range-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tab.is-active {
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Hero balance */
.balance-hero {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px 22px 20px;
  margin-bottom: 14px;
}

.balance-value {
  font-size: clamp(2.15rem, 8.5vw, 2.65rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
  margin-bottom: 16px;
  line-height: 1.05;
}

.balance-row { display: flex; gap: 8px; flex-wrap: wrap; }

.balance-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.balance-chip strong {
  color: var(--text-primary);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
}

.chip-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.chip-positive .chip-dot { background: var(--success); }
.chip-negative .chip-dot { background: var(--danger); }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 18px 20px;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  margin: 0 0 15px;
}

/* Bar list (categorías) */
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  margin-bottom: 12px;
}

.bar-row:last-child { margin-bottom: 0; }

.bar-row .bar-name {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-primary);
  grid-column: 1;
}

.bar-row .bar-amount {
  font-size: 0.84rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  grid-column: 2;
}

.bar-track {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  min-width: 4px;
  transition: width 0.4s ease;
}

/* Listas de lanzamientos */
.entry-list { list-style: none; margin: 0; padding: 0; }

.entry-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.entry-list li:last-child { border-bottom: none; padding-bottom: 0; }
.entry-list li:first-child { padding-top: 0; }

.entry-main { display: flex; align-items: center; gap: 11px; min-width: 0; }
.entry-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.entry-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.entry-desc { color: var(--text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { color: var(--text-muted); font-size: 0.76rem; }
.entry-amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry-amount.is-income { color: var(--success); }

/* Insights del Mayordomo */
.insights-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.insights-head .panel-title { margin: 0; }

.insights-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.insights-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.insight-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.insight-dot.critical { background: var(--danger); }
.insight-dot.warning { background: var(--warning); }
.insight-dot.good { background: var(--success); }

/* Gráfico de evolución (SVG dibujado a mano, sin librería) */
.evolution-chart { width: 100%; height: 120px; }
.evolution-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.evolution-chart .ev-area { fill: var(--accent); opacity: 0.10; }
.evolution-chart .ev-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.evolution-chart .ev-baseline { stroke: var(--border-strong); stroke-width: 1; }
.evolution-chart .ev-dot { fill: var(--accent); }
.evolution-chart .ev-empty { fill: var(--text-muted); font-size: 12px; font-family: var(--font-body); }

/* Transacciones: búsqueda y filtro */
.tx-search {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.88rem;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--page);
  color: var(--text-primary);
  margin-bottom: 12px;
}
.tx-search::placeholder { color: var(--text-muted); }
.tx-search:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

.tx-filters { display: flex; gap: 6px; margin-bottom: 16px; }

.tx-filter {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: none;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.tx-filter.is-active { background: var(--accent); color: #fff; }
.tx-filter:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Formularios inline (presupuesto, metas) */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.inline-input {
  flex: 1 1 160px;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.86rem;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--page);
  color: var(--text-primary);
}
.inline-input::placeholder { color: var(--text-muted); }
.inline-input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.inline-input-amount { flex: 0 1 110px; font-variant-numeric: tabular-nums; }

.btn-sm { padding: 9px 16px; font-size: 0.86rem; flex-shrink: 0; }

/* Metas */
.goals-list { display: flex; flex-direction: column; gap: 16px; }

.goal-card + .goal-card { padding-top: 16px; border-top: 1px solid var(--border); }

.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.goal-name { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }
.goal-amounts { font-size: 0.8rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }

.goal-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.goal-input {
  width: 90px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--page);
  color: var(--text-primary);
}
.goal-input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

@media (max-width: 380px) {
  .login-body { padding: 8px 20px 26px; }
}
