/* Finanzando — sistema de diseño
   Cálido, tipo libro de cuentas moderno. Ver notas de paleta/tipografía en el README de diseño (memoria del proyecto). */

:root {
  --paper: #faf7f1;
  --paper-raised: #ffffff;
  --ink: #1b2422;
  --ink-soft: #5b6664;
  --ink-faint: #8b9492;
  --teal: #0e4f52;
  --teal-strong: #0a3a3c;
  --teal-soft: #e4eeee;
  --gold: #a8752c;
  --gold-soft: #f3e6cf;
  --moss: #2f6b47;
  --moss-soft: #e7f2ea;
  --brick: #9a3b3b;
  --brick-soft: #f7e8e6;
  --line: #e4ddd0;
  --shadow: 0 1px 2px rgba(27, 36, 34, 0.04), 0 4px 16px rgba(27, 36, 34, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --paper: #14181a;
  --paper-raised: #1b2124;
  --ink: #ede9e2;
  --ink-soft: #a5adab;
  --ink-faint: #6f7876;
  --teal: #58c2c4;
  --teal-strong: #7fd4d5;
  --teal-soft: #16292a;
  --gold: #dcae63;
  --gold-soft: #2b2413;
  --moss: #78c896;
  --moss-soft: #17251b;
  --brick: #e28a8a;
  --brick-soft: #2b1a1a;
  --line: #2a2f31;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 20px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14181a;
    --paper-raised: #1b2124;
    --ink: #ede9e2;
    --ink-soft: #a5adab;
    --ink-faint: #6f7876;
    --teal: #58c2c4;
    --teal-strong: #7fd4d5;
    --teal-soft: #16292a;
    --gold: #dcae63;
    --gold-soft: #2b2413;
    --moss: #78c896;
    --moss-soft: #17251b;
    --brick: #e28a8a;
    --brick-soft: #2b1a1a;
    --line: #2a2f31;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 20px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
  margin: 0 0 4px;
}

h1 { font-size: 1.7rem; }
h2 {
  font-size: 1.15rem;
  margin-top: 32px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--line);
  position: relative;
}
h2::after {
  content: "";
  position: absolute;
  left: 0; bottom: -2px;
  width: 46px; height: 2px;
  background: var(--gold);
}
h3 { font-size: 1rem; color: var(--ink-soft); }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

em { color: var(--ink-soft); font-style: normal; }

/* ---------- Shell ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  white-space: nowrap;
}
.topbar-brand span { color: var(--gold); }
.topbar-user {
  display: flex; align-items: center; gap: 12px;
  font-size: 0.85rem; color: var(--ink-soft);
  white-space: nowrap;
}
.topbar-user a { color: var(--ink-soft); }

.tabbar {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tabbar::-webkit-scrollbar { height: 4px; }
.tabbar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.tabbar a {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
}
.tabbar a:hover { background: var(--teal-soft); text-decoration: none; color: var(--teal); }
.tabbar a.active { background: var(--teal); color: var(--paper-raised); }
.tabbar a.badge-tab::after {
  content: attr(data-count);
  margin-left: 6px;
  background: var(--brick);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.7rem;
}

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.page-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 4px; flex-wrap: wrap;
}
.back-link { font-size: 0.85rem; color: var(--ink-soft); }

/* ---------- Cards / panels ---------- */

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin: 16px 0;
}

.hero-figure {
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 600;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.hero-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 2px;
}

.alert {
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 16px 0;
  border-left: 4px solid;
}
.alert-warn { background: var(--brick-soft); border-color: var(--brick); }
.alert-good { background: var(--moss-soft); border-color: var(--moss); }
.alert-info { background: var(--teal-soft); border-color: var(--teal); }

/* ---------- Grid of hub tiles (dashboard) ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.tile {
  display: block;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  color: var(--ink);
  position: relative;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.tile:hover { text-decoration: none; border-color: var(--teal); transform: translateY(-1px); }
.tile-label { font-weight: 600; font-size: 0.92rem; }
.tile-sub { font-size: 0.78rem; color: var(--ink-soft); margin-top: 3px; }
.tile .pill { position: absolute; top: 12px; right: 12px; }

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 560px;
  font-size: 0.88rem;
  background: var(--paper-raised);
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 600;
  background: color-mix(in srgb, var(--teal) 5%, var(--paper-raised));
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: color-mix(in srgb, var(--teal) 4%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; }
.row-highlight td { font-weight: 600; }

/* ---------- Forms ---------- */

form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
form.stack { display: flex; flex-direction: column; gap: 10px; max-width: 420px; margin: 12px 0; }

label { font-size: 0.85rem; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }

input, select, textarea {
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); }

button, .btn {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--paper-raised);
  background: var(--teal);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease;
}
button:hover, .btn:hover { background: var(--teal-strong); text-decoration: none; }
button.secondary, .btn.secondary {
  background: transparent; color: var(--ink-soft); border: 1px solid var(--line);
}
button.secondary:hover { background: var(--teal-soft); color: var(--teal); }
button.danger { background: var(--brick); }
button.danger:hover { background: color-mix(in srgb, var(--brick) 80%, black); }
form { margin: 0; }
td form { display: inline-block; margin: 0; }

/* ---------- Pills / badges ---------- */

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill-good { background: var(--moss-soft); color: var(--moss); }
.pill-bad { background: var(--brick-soft); color: var(--brick); }
.pill-neutral { background: var(--teal-soft); color: var(--teal); }
.pill-muted { background: var(--line); color: var(--ink-soft); }

/* ---------- Flash messages ---------- */

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.9rem; }
.flash.error { background: var(--brick-soft); color: var(--brick); }
.flash.ok { background: var(--moss-soft); color: var(--moss); }

/* ---------- Login ---------- */

.login-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%; max-width: 340px;
}
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .hero-label { text-align: center; margin-bottom: 20px; }

/* ---------- Bar chart (gasto por categoría) ---------- */

.barchart { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.barrow { display: flex; align-items: center; gap: 10px; }
.barrow-label {
  width: 34%;
  min-width: 88px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.barrow-track {
  flex: 1;
  height: 18px;
  background: var(--teal-soft);
  border-radius: 4px;
  overflow: hidden;
}
.barrow-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 0 4px 4px 0;
  min-width: 2px;
}
.barrow-fill.leader { background: var(--gold); }
.barrow-value {
  min-width: 76px;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.insight-list { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.insight-list li {
  padding: 10px 14px;
  background: var(--gold-soft);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }
.stat-row .card { flex: 1; min-width: 140px; margin: 0; }

.filter-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 10px; }
.filter-row select { width: auto; min-width: 160px; margin: 0; }

.period-nav {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 18px; font-size: 0.9rem;
}
.period-nav a { white-space: nowrap; }
.period-nav strong { color: var(--ink); }

/* ---------- Utility ---------- */

.muted { color: var(--ink-soft); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.stack-sm > * + * { margin-top: 8px; }

@media (max-width: 480px) {
  main { padding: 16px 12px 56px; }
  h1 { font-size: 1.4rem; }
  .hero-figure { font-size: 1.7rem; }
  .login-card { padding: 28px 20px; }
}
