/* ==========================================================
   Finanzas Hogar - estilos
   ========================================================== */

:root {
  --topbar-h: 56px;
  --sidebar-w: 244px;
  --brand-1: #0f172a;
  --brand-2: #1e293b;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #dc2626;
  --save: #0ea5e9;
}

[data-bs-theme="dark"] {
  --brand-1: #020617;
  --brand-2: #0b1220;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bs-body-bg);
  -webkit-tap-highlight-color: transparent;
}
[data-bs-theme="light"] body { background: #f1f5f9; }

/* ---------- Topbar ---------- */
.app-topbar {
  height: var(--topbar-h);
  background: linear-gradient(90deg, var(--brand-1), var(--brand-2));
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  z-index: 1030;
}
.app-topbar .navbar-brand { color: #fff; }
.app-topbar .navbar-brand:hover { color: #cbd5e1; }
.brand-badge {
  width: 32px; height: 32px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.14); font-size: 1.05rem;
}
.btn-icon {
  color: #e2e8f0; border: 0; background: rgba(255,255,255,.08);
  width: 34px; height: 34px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,.2); color: #fff; }
.btn-ledger {
  background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 9px;
  padding: .32rem .6rem; font-weight: 500;
}
.btn-ledger:hover { background: rgba(255,255,255,.24); color: #fff; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.app-sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--bs-body-bg);
  border-right: 1px solid var(--bs-border-color);
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; padding: .75rem .5rem;
  display: flex; flex-direction: column;
}
[data-bs-theme="light"] .app-sidebar { background: #fff; }
.app-main { flex: 1 1 auto; min-width: 0; }

.app-sidebar .nav-link, .app-offcanvas .nav-link {
  display: flex; align-items: center; gap: .65rem;
  border-radius: 9px; padding: .55rem .75rem; margin-bottom: 2px;
  color: var(--bs-body-color); font-size: .92rem; font-weight: 500;
}
.app-sidebar .nav-link i, .app-offcanvas .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .85; }
.app-sidebar .nav-link:hover, .app-offcanvas .nav-link:hover { background: var(--bs-secondary-bg); }
.app-sidebar .nav-link.active, .app-offcanvas .nav-link.active {
  background: var(--accent); color: #fff;
}
.app-sidebar .nav-link.active i { opacity: 1; }
.sidebar-foot { margin-top: auto; }
.app-offcanvas { width: 260px; }
.app-offcanvas .nav { padding: .5rem; }

/* ---------- Selector de periodo ---------- */
.period-picker { min-width: 240px; }
.month-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.month-grid .btn { font-size: .78rem; padding: .3rem 0; }

/* ---------- Tarjetas ---------- */
.card { border: 1px solid var(--bs-border-color); border-radius: 14px; }
[data-bs-theme="light"] .card { box-shadow: 0 1px 2px rgba(15,23,42,.06); }
.card-header {
  background: transparent; border-bottom: 1px solid var(--bs-border-color);
  font-weight: 600; padding: .7rem 1rem;
}

.kpi { position: relative; overflow: hidden; }
.kpi .kpi-icon {
  position: absolute; right: -6px; top: -8px; font-size: 3.6rem; opacity: .09;
}
.kpi .kpi-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; opacity: .7; }
.kpi .kpi-value { font-size: 1.45rem; font-weight: 700; line-height: 1.15; }
.kpi .kpi-foot  { font-size: .78rem; }
@media (max-width: 575.98px) { .kpi .kpi-value { font-size: 1.2rem; } }

.kpi-accent { border-left: 4px solid var(--bs-secondary); }
.kpi-in     { border-left-color: var(--save); }
.kpi-out    { border-left-color: var(--bad); }
.kpi-save   { border-left-color: var(--ok); }
.kpi-free   { border-left-color: var(--accent); }
.kpi-warn   { border-left-color: var(--warn); }

.stat-num { font-variant-numeric: tabular-nums; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-pos { color: var(--ok); }
.money-neg { color: var(--bad); }

/* ---------- Tablas ---------- */
.table > :not(caption) > * > * { padding: .55rem .6rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--bs-secondary-color); font-weight: 600; }
.table-hover tbody tr:hover { background: var(--bs-secondary-bg); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Tabla que se convierte en tarjetas en movil */
@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack tbody tr {
    display: block; border: 1px solid var(--bs-border-color);
    border-radius: 12px; margin-bottom: .6rem; padding: .5rem .65rem;
    background: var(--bs-body-bg);
  }
  .table-stack tbody td {
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; border: 0; padding: .3rem 0; text-align: right;
  }
  .table-stack tbody td::before {
    content: attr(data-label); font-size: .74rem; text-transform: uppercase;
    letter-spacing: .03em; color: var(--bs-secondary-color); font-weight: 600;
    text-align: left; flex: 0 0 auto;
  }
  .table-stack tbody td.td-full { display: block; text-align: left; }
  .table-stack tbody td.td-full::before { display: block; margin-bottom: .15rem; }
}

/* ---------- Graficos ---------- */
.chart-box { position: relative; width: 100%; height: 280px; }
.chart-box.sm { height: 220px; }
.chart-box.lg { height: 340px; }
@media (max-width: 575.98px) { .chart-box { height: 240px; } .chart-box.lg { height: 260px; } }

/* ---------- Alertas / recordatorios ---------- */
.alert-card { border-radius: 12px; border: 1px solid var(--bs-border-color); border-left-width: 4px; }
.alert-card.sev-critico { border-left-color: var(--bad); }
.alert-card.sev-aviso   { border-left-color: var(--warn); }
.alert-card.sev-info    { border-left-color: var(--save); }
.alert-card.sev-exito   { border-left-color: var(--ok); }
.alert-card .ic { font-size: 1.25rem; }

/* ---------- Misc ---------- */
.necessity-pill { font-size: .7rem; padding: .18rem .5rem; border-radius: 20px; font-weight: 600; }
.progress { background: var(--bs-secondary-bg); border-radius: 20px; }
.form-label { font-size: .82rem; font-weight: 600; margin-bottom: .25rem; }
.form-text { font-size: .76rem; }
.required::after { content: " *"; color: var(--bad); }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.6rem; opacity: .35; display: block; margin-bottom: .5rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bs-body-bg); padding-top: .5rem; }

.list-tight .list-group-item { padding: .55rem .75rem; }
.text-xs { font-size: .75rem; }
.cursor-pointer { cursor: pointer; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.nav-link:hover, .dropdown-item:hover { text-decoration: none; }

/* ---------- Selects con buscador (Tom Select) ---------- */
/* El tema bootstrap5 de Tom Select copia las clases del <select> al wrapper,
   asi que el borde y el fondo los pinta el wrapper y quedan iguales a los
   inputs nativos. Aqui solo afinamos alto, foco y modo oscuro. */
.ts-wrapper { min-width: 0; }
.ts-wrapper.form-select, .ts-wrapper.form-control { min-height: calc(1.5em + .75rem + 2px); }
.ts-wrapper.form-select-sm, .ts-wrapper.form-control-sm { min-height: calc(1.5em + .5rem + 2px); }
.ts-wrapper.form-select-sm .ts-control, .form-select-sm + .ts-dropdown { font-size: .875rem; }
.ts-control { color: var(--bs-body-color); }
.ts-wrapper.focus.form-select, .ts-wrapper.focus.form-control {
  border-color: #86b7fe;
  box-shadow: 0 0 0 .25rem rgba(13,110,253,.25);
}
.ts-dropdown {
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  box-shadow: 0 8px 24px rgba(15,23,42,.18);
  z-index: 1060;               /* por sobre los modales */
}
.ts-dropdown .option { padding: .45rem .75rem; }
.ts-dropdown .active { background: var(--bs-primary); color: #fff; }
.ts-dropdown .no-results { padding: .55rem .75rem; color: var(--bs-secondary-color); }
.ts-control input::placeholder { color: var(--bs-secondary-color); opacity: 1; }

/* El buscador va DENTRO del desplegable (plugin dropdown_input), al estilo
   Select2: el campo sigue mostrando lo elegido y la caja de busqueda aparece
   limpia arriba de la lista, con el cursor al inicio. */
.ts-dropdown .dropdown-input-wrap { padding: .5rem; border-bottom: 1px solid var(--bs-border-color); }
.ts-dropdown .dropdown-input {
  width: 100%;
  padding: .35rem .6rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius-sm);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  box-shadow: none;
  outline: none;
}
.ts-dropdown .dropdown-input:focus {
  border-color: #86b7fe;
  box-shadow: 0 0 0 .2rem rgba(13,110,253,.2);
}
.ts-dropdown .dropdown-input::placeholder { color: var(--bs-secondary-color); opacity: 1; }
/* El campo cerrado se comporta como un select normal */
.ts-wrapper.single .ts-control, .ts-wrapper.single .ts-control input { cursor: pointer; }

[data-bs-theme="dark"] .ts-dropdown { background: var(--bs-body-bg); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
[data-bs-theme="dark"] .ts-dropdown .option:hover { background: var(--bs-secondary-bg); }

/* Dentro de modales el desplegable no debe quedar cortado */
.modal .ts-dropdown { position: absolute; }

/* Login */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.25rem; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #0ea5e9 130%);
}
.auth-card { width: 100%; max-width: 420px; border-radius: 18px; box-shadow: 0 18px 45px rgba(2,6,23,.35); }
.auth-logo {
  width: 54px; height: 54px; border-radius: 15px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.6rem; margin: 0 auto .75rem;
}

/* Impresion */
@media print {
  .app-sidebar, .app-topbar, .period-nav, .btn, .offcanvas { display: none !important; }
  .app-main { width: 100%; }
  .card { break-inside: avoid; }
}
