/* =============================================================
   Componentes — Cuaderno Financiero
   ============================================================= */

/* ---------- Icon containers (SVG) ---------- */
.ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  color: currentColor;
}
.ico svg { display: block; }

/* Brand mark — caja con el logo cuaderno */
.brand-mark {
  background: var(--ink);
  color: var(--canvas);
  border-radius: 9px;
  display: grid;
  place-items: center;
}
.sidebar-header .brand-mark { width: 30px; height: 30px; }
.auth-header .brand-mark   { width: 48px; height: 48px; border-radius: 12px; }

/* Iconos en items de lista (cuentas) — el SVG vive en swatch */
.item .swatch svg { stroke-width: 1.85; }

/* Icono dentro de nav-item: tinte sutil para no competir con el texto */
.nav-item .ico { color: var(--ink-muted); transition: color .12s ease; }
.nav-item.active .ico,
.nav-item:hover .ico { color: var(--ink); }
.nav-item.active .ico { color: var(--accent); }

/* Botones con icono + label: respeto del gap */
.btn .ico { margin-right: -2px; }
.btn--block .ico { margin-right: 0; }

/* Empty states con SVG centrado */
.empty .ico { display: inline-flex; opacity: 0.5; margin-bottom: 2px; }
.empty .ico svg { width: 26px; height: 26px; }

/* ---------- Header de vista ---------- */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--s-5);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--rule);
}
.view-header > div { min-width: 0; }

/* ---------- Formularios ---------- */
.field {
  display: flex; flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
}
.field > span {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

input, select, textarea, .control {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus, .control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
input::placeholder, textarea::placeholder { color: var(--ink-quiet); }
input[type="color"] {
  padding: 3px;
  width: 56px; height: 36px;
  cursor: pointer;
  background: var(--surface);
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

select.control, .control { width: auto; min-width: 168px; }
.control--search { min-width: 240px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-4);
}
.form-grid .full { grid-column: 1 / -1; }

/* Toggle compacto (checkbox + label) */
.toggle-card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  font-size: 13.5px;
  color: var(--ink);
}
.toggle__label { letter-spacing: -0.005em; }
.msi-grid {
  margin-top: var(--s-3);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-3);
  transition: opacity .15s ease;
}

/* ---------- Botones ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--ink);
  color: var(--canvas);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.005em;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .04s ease;
  white-space: nowrap;
  height: 36px;
}
.btn:hover  { background: var(--ink-soft); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-block, .btn--block { width: 100%; justify-content: center; }
.btn-sm, .btn--sm { padding: 6px 10px; font-size: 12px; height: 30px; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
/* En oscuro el accent es claro: el texto del botón pasa a tinta para legibilidad */
[data-theme="dark"] .btn--primary,
[data-theme="dark"] .btn-primary {
  color: var(--canvas);
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .btn--primary,
  [data-theme="auto"] .btn-primary {
    color: var(--canvas);
  }
}

.btn-secondary, .btn--secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--rule-strong);
}
.btn-secondary:hover, .btn--secondary:hover {
  background: var(--surface-2);
  border-color: var(--rule-emphasis);
}

.btn-danger, .btn--danger {
  background: var(--negative);
  color: #fff;
  border-color: transparent;
}
.btn-danger:hover, .btn--danger:hover { background: #843e33; }

.btn-ghost, .btn--ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--rule-strong);
}
.btn-ghost:hover, .btn--ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--rule-emphasis);
}

/* Compatibilidad con index.html que usa btn-primary */
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  width: 30px; height: 30px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1;
  display: inline-grid; place-items: center;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--rule);
}
.icon-btn--accent { color: var(--accent); }
.icon-btn--accent:hover { background: var(--accent-tint); border-color: var(--accent-tint); color: var(--accent); }
.icon-btn--ok { color: var(--positive); }
.icon-btn--ok:hover { background: var(--positive-tint); border-color: transparent; color: var(--positive); }

/* ---------- Cards / panel ---------- */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: var(--s-5) var(--s-5);
  box-shadow: var(--shadow-xs);
}

.card-header, .panel__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-4);
}
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card-header .actions { margin-left: auto; display: flex; gap: var(--s-2); }
.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.panel__head .filter-row { flex: 1; }
.panel__head .btn { margin-left: auto; }

/* ---------- KPIs ---------- */
.kpi-grid, .kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4);
}
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}
/* hairline de acento — la firma del ledger */
.kpi::before {
  content: "";
  position: absolute;
  top: 0; left: var(--s-5);
  width: 28px; height: 1.5px;
  background: var(--ink-quiet);
  border-radius: 2px;
}
.kpi--accent::before   { background: var(--accent); }
.kpi.positive::before  { background: var(--positive); }
.kpi.negative::before  { background: var(--negative); }
.kpi.primary::before   { background: var(--accent); }
.kpi.warning::before   { background: var(--warning); }

.kpi h4, .kpi__label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.10em;
}
.kpi .value, .kpi__value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
  line-height: 1.1;
}
.kpi .meta, .kpi__meta {
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: -0.005em;
}
.kpi.positive .value, .kpi--positive .kpi__value { color: var(--positive); }
.kpi.negative .value, .kpi--negative .kpi__value { color: var(--negative); }
.kpi.primary  .value, .kpi--accent   .kpi__value { color: var(--accent); }

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
}
.panel .table-wrap {
  border: 0;
  border-top: 1px solid var(--rule);
  border-radius: 0;
  margin: var(--s-4) calc(-1 * var(--s-5)) calc(-1 * var(--s-5));
  background: transparent;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th,
table.data td {
  padding: 12px var(--s-4);
  text-align: left;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  background: transparent;
  font-weight: 600;
  color: var(--ink-muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  padding-top: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-strong);
}
table.data td.num,
table.data th.num     { text-align: right; }
table.data td.actions,
table.data th.actions { text-align: right; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr {
  transition: background .1s ease;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data .row--off td { color: var(--ink-quiet); }
table.data .row--off .cell-main__title { text-decoration: line-through; text-decoration-color: var(--ink-quiet); }

.amount-in  { color: var(--positive); font-weight: 600; }
.amount-out { color: var(--negative); font-weight: 600; }

/* Variant: ledger (más respiro y reglas más finas) */
.data--ledger th { font-size: 10px; letter-spacing: 0.12em; }
.data--ledger td { padding: 14px var(--s-4); }

/* Celda principal con título + sub */
.cell-main { min-width: 220px; max-width: 360px; white-space: normal; }
.cell-main__title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  letter-spacing: -0.005em;
  line-height: 1.35;
}
.cell-main__sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* Cuenta inline */
.acct {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
  letter-spacing: -0.005em;
}
.acct__dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--ink-muted);
  display: inline-block;
}

/* ---------- Chips / badges ---------- */
.chip, .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  white-space: nowrap;
}
.chip--accent, .badge.info {
  background: var(--accent-tint);
  color: var(--accent);
  border-color: transparent;
}
.badge.success { background: var(--positive-tint); color: var(--positive); border-color: transparent; }
.badge.danger  { background: var(--negative-tint); color: var(--negative); border-color: transparent; }
.badge.warning { background: var(--warning-tint); color: var(--warning); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink-quiet); }

/* state-mark: marca de estado en cell-main, más sutil */
.state-mark {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--rule);
  background: transparent;
  text-transform: lowercase;
}
.state-mark--credit { color: var(--accent); border-color: var(--accent-tint); background: var(--accent-tint); }
.state-mark--gasto  { color: var(--negative); border-color: var(--negative-tint); background: var(--negative-tint); }
.state-mark--off    { color: var(--ink-muted); }

/* ---------- Toolbar / filtros ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: center;
  justify-content: space-between;
}
.toolbar .filters,
.filter-row {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  align-items: center;
}
.toolbar .filters select,
.toolbar .filters input,
.filter-row select,
.filter-row input {
  min-width: 160px;
}

/* ---------- Modal ---------- */
.modal-root {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 50;
  padding: var(--s-5);
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(6px);
}
.modal {
  position: relative;
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--rule-strong);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 760px);
  overflow: hidden;
}
.modal-header {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--rule);
  display: flex; align-items: center;
}
.modal-header h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.modal-header .icon-btn { margin-left: auto; }
.modal-body { padding: var(--s-5); overflow: auto; }
.modal-footer {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--rule);
  display: flex; justify-content: flex-end; gap: var(--s-2);
  background: var(--surface-2);
}
.modal-footer__inner {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  width: 100%;
}

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed; bottom: var(--s-5); right: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-2);
  z-index: 70; pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  padding: 10px 14px 10px 12px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 240px; max-width: 360px;
  animation: toast-in .18s cubic-bezier(0.2, 0.7, 0.3, 1);
  display: flex; gap: var(--s-2); align-items: center;
  font-size: 13px;
  color: var(--ink);
}
.toast.success { border-left: 2px solid var(--positive); }
.toast.error   { border-left: 2px solid var(--negative); }
.toast.info    { border-left: 2px solid var(--accent); }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0 }
  to   { transform: none; opacity: 1 }
}

/* ---------- Spinner ---------- */
.loader {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 60;
  background: rgba(20, 26, 32, 0.10);
}
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--rule-emphasis);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Empty states ---------- */
.empty {
  padding: 36px var(--s-4);
  text-align: center;
  color: var(--ink-muted);
}
.empty .ico { font-size: 28px; margin-bottom: 4px; opacity: 0.5; }

.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  padding: var(--s-7) var(--s-4);
}
.empty-state__title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.empty-state__hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-muted);
}

/* ---------- Chart cards ---------- */
.chart-card {
  min-height: 340px;
  display: flex;
  flex-direction: column;
}
.chart-card .card-header {
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--rule);
}
.chart-card .card-header h3 {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.chart-card canvas {
  max-height: 340px;
  flex: 1;
}

/* ---------- Helpers de grilla ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }

/* ---------- Listas (cuentas / categorías) ---------- */
.item-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--s-3);
}
.item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  transition: border-color .12s ease, background .12s ease;
}
.item:hover { border-color: var(--rule-strong); background: var(--surface-2); }
.item .swatch { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.item .meta { flex: 1; min-width: 0; }
.item .name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  letter-spacing: -0.005em;
  overflow: hidden; text-overflow: ellipsis;
}
.item .sub {
  font-size: 12px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.item .actions { display: flex; gap: 2px; }

/* ---------- Progress (créditos) ---------- */
.progress {
  width: 100%;
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width .3s ease;
}

/* progress dedicado a la vista tarjeta (con meta tipográfica al lado) */
.ledger-progress { min-width: 140px; }
.ledger-progress__bar {
  width: 100%;
  height: 3px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.ledger-progress__bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width .3s ease;
}
.ledger-progress__meta {
  margin-top: 4px;
  display: flex; gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- Cuotas card (modal de tarjeta) ---------- */
.cuotas-card {
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--s-4);
}
.cuotas-card__row {
  display: flex; justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
}
.cuotas-card__row:last-of-type { border-bottom: 0; }
.cuotas-card .display-sm { margin-bottom: var(--s-3); }
