:root {
  --bg: #0f1115;
  --surface: #171a21;
  --border: #2a2e38;
  --text: #e6e8eb;
  --muted: #8b93a3;
  --accent: #4f7cff;
  --danger: #ff5c5c;
  --liquid: #4f7cff;
  --goal: #35b26b;
  --debt: #ff8a4f;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  height: 48px;
  padding: 0 1.5rem;
  font-size: .85rem;
  line-height: 1;
  border-bottom: 1px solid var(--border);
}

.nav a {
  display: inline-flex;
  align-items: center;
  height: 100%;
  color: var(--text);
  text-decoration: none;
}
.nav a:hover { color: var(--accent); }
.nav a.active {
  color: var(--accent);
  font-weight: 600;
}
.nav-brand {
  font-size: 1.05rem;
  font-weight: 700;
  margin-right: auto;
}
.nav-logout {
  display: inline-flex;
  align-items: center;
  height: 100%;
  margin: 0 0 0 auto;
}
.nav-logout button {
  display: inline-flex;
  align-items: center;
  height: 100%;
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}
.nav-logout button:hover { color: var(--accent); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 { margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.card-narrow { max-width: 420px; margin: 3rem auto; }

a.card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s;
}
a.card:hover { border-color: var(--accent); }

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: .9rem;
}
.back-link:hover { color: var(--accent); }

.progress-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: .5rem 0;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin: 1rem 0 1.5rem;
}
.action-row .button,
.action-row .button-secondary {
  margin-top: 0;
}
.action-row-right {
  margin-left: auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.account-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
}

.account-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
}

.account-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 8px;
  object-fit: contain;
  padding: 2px;
}

.account-nickname { font-weight: 600; }

.account-balance { font-size: 1.5rem; font-weight: 700; margin: 0; }

.badge {
  font-size: .75rem;
  padding: .2rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.badge-liquid { color: var(--liquid); border-color: var(--liquid); }
.badge-goal_savings { color: var(--goal); border-color: var(--goal); }
.badge-debt { color: var(--debt); border-color: var(--debt); }
.badge-income { color: var(--goal); border-color: var(--goal); }
.badge-expense { color: var(--danger); border-color: var(--danger); }

label { display: block; margin: 1rem 0 .25rem; font-size: .9rem; color: var(--muted); }

input, select {
  width: 100%;
  padding: .6rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

input[type="color"] {
  width: 60px;
  height: 40px;
  padding: .25rem;
  cursor: pointer;
}

button, .button {
  display: inline-block;
  margin-top: 1.25rem;
  padding: .6rem 1.2rem;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.hint { color: var(--muted); font-size: .85rem; }
.hint code { color: var(--text); }

.error { color: var(--danger); }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
}
.section-header h2 { margin: 0; }
.section-header .button { margin-top: 0; }

.button-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.vault-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.vault-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
}

.vault-row-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.vault-name { font-weight: 600; }
.vault-amount { font-weight: 700; }

.progress-thin { height: 4px; margin: .4rem 0; }

.category-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: 1.5rem;
}

.category-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem 1rem;
}

.category-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.category-name { font-weight: 600; flex-grow: 1; }
.category-row form { margin: 0; }

.link-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: 1.5rem;
}

.link-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
}

.link-row-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .3rem;
}

.link-nickname { font-weight: 600; }

.vault-transfer-link {
  display: inline-block;
  margin-top: .5rem;
  font-size: .85rem;
  color: var(--accent);
  text-decoration: none;
}
.vault-transfer-link:hover { text-decoration: underline; }

.vault-history { margin-top: .5rem; }
.vault-history > summary {
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  list-style: none;
}
.vault-history > summary::-webkit-details-marker { display: none; }
.vault-history > summary:hover { color: var(--accent); }
.vault-history-list {
  list-style: none;
  margin: .5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.vault-history-list li {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  font-size: .8rem;
}
.vault-history-date { color: var(--muted); flex-shrink: 0; }
.vault-history-note { color: var(--muted); flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Comprometido / disponible ─────────────────────────────────────────── */

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: .3rem;
}
.dot-green { background: var(--goal); }
.dot-red { background: var(--danger); }

.committed-toggle {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: .5rem 0 1rem;
  color: var(--muted);
  font-size: .9rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: .85rem;
  padding: 0;
  margin: 0;
  text-decoration: underline;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  margin: 1rem 0 .25rem;
  font-size: .85rem;
  color: var(--muted);
}
.checkbox-label input { width: auto; margin-top: .2rem; }

/* ── Estadísticas ──────────────────────────────────────────────────────── */

.patrimonio-bar {
  height: 10px;
  background: var(--danger);
  border-radius: 999px;
  overflow: hidden;
  margin: .75rem 0;
}
.patrimonio-bar-fill {
  height: 100%;
  background: var(--goal);
}

.stats-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: .9rem;
  color: var(--muted);
}
.stats-totals strong { color: var(--text); }

.stats-table {
  width: 100%;
  border-collapse: collapse;
}
.stats-table td {
  padding: .4rem .5rem .4rem 0;
  border-top: 1px solid var(--border);
}
.stats-table form { margin: 0; }
.stats-amount { text-align: right; font-variant-numeric: tabular-nums; }
.amount-in { color: var(--goal); }
.amount-out { color: var(--danger); }

.transactions-table-wrap {
  overflow-x: auto;
}
.transactions-table {
  font-size: .85rem;
}
.transactions-table td {
  padding: .25rem .5rem .25rem 0;
  line-height: 1.2;
}
.transactions-table select {
  padding: .25rem .4rem;
  font-size: .8rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin: 1rem 0 1.5rem;
}
.filter-row select {
  width: auto;
}

.chart {
  width: 100%;
  height: 160px;
  display: block;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: .85rem;
  color: var(--muted);
  margin: .5rem 0;
}
.line-swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: .3rem;
  vertical-align: middle;
}
.line-total { stroke: var(--accent); background: var(--accent); }
.line-green { stroke: var(--goal); background: var(--goal); }
.line-red { stroke: var(--danger); background: var(--danger); }

/* ── Infotip ───────────────────────────────────────────────────────────── */
/* <details>/<summary> nativo: se abre solo al tocar el ícono "i", sin JS. */

.infotip {
  display: inline-block;
  position: relative;
  margin-left: .4rem;
  vertical-align: middle;
}

.infotip > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: .7rem;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.infotip > summary::-webkit-details-marker { display: none; }
.infotip > summary:hover,
.infotip[open] > summary {
  border-color: var(--accent);
  color: var(--accent);
}

.infotip-body {
  position: absolute;
  top: 130%;
  left: 0;
  z-index: 30;
  width: max-content;
  max-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .75rem;
  font-size: .8rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--muted);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}
.infotip-body code { color: var(--text); }

/* Los modales son angostos (max-width: 380px, con padding) -- 280px de
   tooltip se salía del borde derecho y quedaba tapado. Adentro de un modal
   se achica para que entre completo. */
dialog.modal .infotip-body {
  max-width: 200px;
}

/* ── Paginador ─────────────────────────────────────────────────────────── */

.paginator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem 0;
}
.paginator .button-secondary {
  margin-top: 0;
}
.paginator .disabled {
  display: inline-block;
  padding: .6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  opacity: .5;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */

dialog.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: 90%;
  max-width: 380px;
  color: var(--text);
}
dialog.modal::backdrop {
  background: rgba(0, 0, 0, .6);
}
dialog.modal h2 { margin-top: 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.25rem;
}
.modal-actions button { margin-top: 0; }
