/* ============================================================
   Caudal — finanzas personales
   Identidad: verde pino sobre papel salvia, dorado para metas,
   arcilla para deudas. Display Fraunces, cuerpo Inter.
   ============================================================ */

:root {
  --bg: #E9EDE6;
  --bg-grain: #E3E8DF;
  --surface: #FBFCFA;
  --surface-2: #F2F5EF;
  --ink: #17231C;
  --ink-soft: #586A5D;
  --ink-faint: #8A9A8E;

  --brand: #1C6B47;       /* ahorro / positivo */
  --brand-deep: #0E4730;
  --brand-tint: #DCE9E0;
  --gold: #B98A2E;        /* objetivos */
  --gold-tint: #F0E6CF;
  --clay: #B24A34;        /* deudas / déficit */
  --clay-tint: #F1DBD3;

  --line: rgba(23, 35, 28, 0.10);
  --line-strong: rgba(23, 35, 28, 0.18);
  --shadow: 0 1px 2px rgba(23,35,28,.04), 0 8px 24px -12px rgba(23,35,28,.18);

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;

  --display: "Fraunces", Georgia, serif;
  --body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-feature-settings: "tnum" 1, "cv05" 1;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

body {
  background-image:
    radial-gradient(120% 80% at 100% 0%, rgba(28,107,71,.06), transparent 60%),
    radial-gradient(80% 60% at 0% 100%, rgba(185,138,46,.05), transparent 55%);
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, button { font-size: 1rem; }

[hidden] { display: none !important; }

/* ---------------- Marca ---------------- */
.auth-brand { display: inline-flex; align-items: center; gap: 10px; }
.mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
  position: relative; flex: none;
}
.mark::after {
  content: ""; position: absolute; inset: 6px 5px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  border-bottom-left-radius: 5px; opacity: .9;
}
.wordmark {
  font-family: var(--display); font-weight: 600; font-size: 1.25rem;
  letter-spacing: -0.02em; color: var(--ink);
}

/* ---------------- Botones ---------------- */
.btn {
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 10px 16px; font-weight: 600; font-size: .95rem;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: .88rem; }
.link {
  background: none; border: none; color: var(--brand); font-weight: 600;
  padding: 0; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------------- Auth ---------------- */
.auth-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 36px 32px; box-shadow: var(--shadow);
}
.auth-card .auth-brand { margin-bottom: 28px; }
.auth-title { font-size: 1.7rem; margin-bottom: 6px; }
.auth-sub { color: var(--ink-soft); margin: 0 0 24px; font-size: .95rem; }
.auth-form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--ink-soft); }
.field input {
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 11px 13px; background: var(--surface); color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .inline-form input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.auth-error {
  background: var(--clay-tint); color: var(--clay); font-size: .88rem;
  padding: 9px 12px; border-radius: var(--r-sm); margin: 2px 0 0;
}
.auth-switch { margin: 20px 0 0; text-align: center; color: var(--ink-soft); font-size: .9rem; }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(233,237,230,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-name { color: var(--ink-soft); font-size: .9rem; font-weight: 500; }

/* ---------------- Contenedor ---------------- */
.container { max-width: 1080px; margin: 0 auto; padding: 28px 24px 64px; }

/* ---------------- Hero ---------------- */
.hero {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 30px 32px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.eyebrow {
  text-transform: uppercase; letter-spacing: .14em; font-size: .72rem;
  font-weight: 700; color: var(--ink-faint); margin: 0 0 8px;
}
.hero-number {
  font-family: var(--display); font-weight: 600; font-size: clamp(2.6rem, 7vw, 4rem);
  line-height: 1; letter-spacing: -0.03em; margin: 0; color: var(--brand-deep);
}
.hero-number.negative { color: var(--clay); }
.hero-note { color: var(--ink-soft); margin: 12px 0 0; font-size: .95rem; max-width: 52ch; }

/* Barra de flujo: el reparto del dinero */
.flow {
  display: flex; height: 30px; border-radius: 8px; overflow: hidden;
  margin-top: 24px; background: var(--surface-2); gap: 2px;
}
.flow-seg { height: 100%; transition: flex-grow .4s ease; min-width: 2px; }
.flow-seg.expenses { background: var(--clay); }
.flow-seg.debt { background: #C98A4B; }
.flow-seg.goals { background: var(--gold); }
.flow-seg.free { background: var(--brand); }
.flow-legend {
  list-style: none; display: flex; flex-wrap: wrap; gap: 16px 22px;
  margin: 14px 0 0; padding: 0;
}
.flow-legend li { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink-soft); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.dot.expenses { background: var(--clay); }
.dot.debt { background: #C98A4B; }
.dot.goals { background: var(--gold); }
.dot.free { background: var(--brand); }
.flow-legend b { color: var(--ink); font-weight: 600; }

/* ---------------- KPIs ---------------- */
.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 16px 18px;
}
.kpi .k-label { font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); font-weight: 600; }
.kpi .k-value { font-family: var(--display); font-size: 1.5rem; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.kpi .k-value.pos { color: var(--brand); }
.kpi .k-value.neg { color: var(--clay); }

/* ---------------- Grid de paneles ---------------- */
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
}
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 22px 22px 18px; box-shadow: var(--shadow);
}
.panel-wide { grid-column: 1 / -1; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { font-size: 1.2rem; }
.panel-total { font-family: var(--display); font-weight: 600; font-size: 1.1rem; color: var(--ink); }
.panel-hint { font-size: .8rem; color: var(--ink-faint); }

/* Listas simples (ingresos / gastos) */
.list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 2px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px; border-radius: var(--r-sm); gap: 10px;
}
.list-row:hover { background: var(--surface-2); }
.list-row .row-name { font-weight: 500; }
.list-row .row-amount { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.row-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.list-row:hover .row-actions, .card:hover .row-actions { opacity: 1; }
.icon-btn {
  border: none; background: none; color: var(--ink-faint); font-size: .82rem;
  padding: 4px 7px; border-radius: 6px; font-weight: 600;
}
.icon-btn:hover { background: var(--surface); color: var(--ink); }
.icon-btn.danger:hover { background: var(--clay-tint); color: var(--clay); }
.empty { color: var(--ink-faint); font-size: .88rem; padding: 8px 10px; font-style: italic; }

/* Tarjetas (objetivos / deudas) */
.cards { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card {
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px; background: var(--surface-2); position: relative;
}
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-name { font-weight: 600; font-size: 1.02rem; }
.card-sub { font-size: .82rem; color: var(--ink-soft); margin-top: 2px; }
.badge {
  display: inline-block; font-size: .82rem; font-weight: 700; padding: 4px 10px;
  border-radius: 999px; font-variant-numeric: tabular-nums;
}
.badge.gold { background: var(--gold-tint); color: var(--gold); }
.badge.clay { background: var(--clay-tint); color: var(--clay); }
.badge.brand { background: var(--brand-tint); color: var(--brand-deep); }

.progress { height: 7px; border-radius: 999px; background: rgba(23,35,28,.08); overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.card-meta { display: flex; justify-content: space-between; font-size: .8rem; color: var(--ink-soft); margin-top: 8px; }

.payoff { margin-top: 12px; display: grid; gap: 8px; }
.payoff-row { display: flex; align-items: center; justify-content: space-between; font-size: .88rem; }
.payoff-row .pay-label { color: var(--ink-soft); }
.payoff-row .pay-value { font-weight: 600; }
.payoff-accel { background: var(--brand-tint); border-radius: var(--r-sm); padding: 10px 12px; font-size: .84rem; color: var(--brand-deep); }
.payoff-accel b { font-weight: 700; }
.warn { color: var(--clay); font-size: .84rem; margin-top: 8px; }

/* ---------------- Formularios inline ---------------- */
.inline-form { display: flex; gap: 8px; align-items: stretch; border-top: 1px solid var(--line); padding-top: 14px; }
.inline-form-wrap { flex-wrap: wrap; }
.inline-form input {
  flex: 1 1 120px; min-width: 0; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); padding: 9px 12px; background: var(--surface); color: var(--ink);
}
.inline-form input[name="name"] { flex: 2 1 160px; }
.inline-form button { flex: none; white-space: nowrap; }

/* ---------------- Varios ---------------- */
.disclaimer { color: var(--ink-faint); font-size: .8rem; margin-top: 28px; max-width: 70ch; line-height: 1.6; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 500; box-shadow: var(--shadow); z-index: 50;
  animation: toast-in .2s ease;
}
.toast.error { background: var(--clay); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .container { padding: 20px 16px 48px; }
  .hero { padding: 24px 20px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .inline-form { flex-wrap: wrap; }
}

/* Accesibilidad */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
