/* ============================================================
   money-track — sistema de diseño fintech (light mode)
   ============================================================ */
:root {
  /* Lienzo y superficies */
  --bg: #f6f7fb;
  --bg-soft: #eef1f8;
  --card: #ffffff;
  --border: #e9ecf3;
  --border-strong: #dfe3ee;

  /* Tinta */
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;

  /* Acentos por dominio */
  --inv: #6366f1;      --inv-soft: #eef0fe;
  --gasto: #f59e0b;    --gasto-soft: #fef6e7;
  --credito: #14b8a6;  --credito-soft: #e5faf6;
  --home: #7c5cff;     --home-soft: #f0edff;

  /* Semántica */
  --pos: #16a34a;  --pos-soft: #e8f6ee;
  --neg: #dc2626;  --neg-soft: #fdeaea;

  /* Sombras y radios */
  --sh-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --sh: 0 4px 16px rgba(15, 23, 42, .07);
  --sh-lg: 0 12px 32px rgba(15, 23, 42, .10);
  --r: 18px;
  --r-sm: 12px;
  --r-lg: 24px;

  --sidebar-w: 250px;
  --maxw: 1760px;

  --font-display: "Sora", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { font-feature-settings: "cv05", "ss01"; }

h1, h2, h3, .num {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  margin: 0;
}

.num { font-variant-numeric: tabular-nums; }

a { color: inherit; text-decoration: none; }

/* ============================================================
   Layout con sidebar
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 10px 22px;
}
.brand .logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--home), var(--inv));
  display: grid; place-items: center;
  color: #fff; font-family: var(--font-display); font-weight: 700;
  box-shadow: var(--sh);
}
.brand b { font-family: var(--font-display); font-size: 1.12rem; letter-spacing: -.03em; }
.brand span { display: block; font-size: .72rem; color: var(--faint); font-weight: 500; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.ico { width: 20px; height: 20px; flex: none; }
.nav-item .ico { width: 20px; height: 20px; flex: none; opacity: .8; }
.nav-item:hover { background: var(--bg-soft); }
.nav-item.active { color: #fff; font-weight: 600; box-shadow: var(--sh); }
.nav-item.active .ico { opacity: 1; }
.nav-item.home.active   { background: linear-gradient(135deg, var(--home), var(--inv)); }
.nav-item.inv.active    { background: var(--inv); }
.nav-item.gasto.active  { background: var(--gasto); }
.nav-item.credito.active{ background: var(--credito); }
.nav-item.hist.active   { background: var(--home); }

.sidebar-foot { margin-top: auto; }
.logout {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: var(--r-sm);
  color: var(--muted); font-size: .9rem;
}
.logout:hover { background: var(--neg-soft); color: var(--neg); }

/* ============================================================
   Contenido
   ============================================================ */
.main { padding: 30px 38px 90px; max-width: var(--maxw); width: 100%; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 26px; flex-wrap: wrap;
}
.page-head .eyebrow {
  font-size: .74rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .12em; color: var(--faint); margin-bottom: 4px;
}
.page-head h1 { font-size: 1.9rem; }
.page-head .sub { color: var(--muted); font-size: .92rem; margin-top: 3px; }

/* ============================================================
   Tarjetas
   ============================================================ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 22px;
  box-shadow: var(--sh-sm);
}
.card.pad-lg { padding: 26px 28px; }
.card-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.card-title h3 { font-size: 1.05rem; }
.card-title .hint { font-size: .82rem; color: var(--faint); }

.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-4 { grid-template-columns: repeat(4, 1fr); }
.g-hero { grid-template-columns: 1.5fr 1fr; align-items: stretch; }

/* KPI tiles */
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  box-shadow: var(--sh-sm);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent, var(--inv));
}
.kpi .label {
  font-size: .78rem; color: var(--muted); font-weight: 500;
  display: flex; align-items: center; gap: 7px; margin-bottom: 9px;
}
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent, var(--inv)); }
.kpi .value { font-family: var(--font-display); font-size: 1.55rem; font-weight: 700; letter-spacing: -.03em; }
.kpi .delta { font-size: .82rem; font-weight: 600; margin-top: 4px; }
.delta.up { color: var(--pos); }
.delta.down { color: var(--neg); }

/* Hero patrimonio */
.hero {
  background: linear-gradient(135deg, #1e1b4b 0%, #4338ca 55%, #6366f1 100%);
  color: #fff;
  border-radius: var(--r-lg);
  padding: 30px 32px;
  box-shadow: var(--sh-lg);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px;
  width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%);
}
.hero .eyebrow { color: rgba(255,255,255,.7); font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; }
.hero .big { font-family: var(--font-display); font-size: 3rem; font-weight: 700; letter-spacing: -.04em; margin: 8px 0 2px; }
.hero .meta { display: flex; gap: 26px; margin-top: 20px; flex-wrap: wrap; }
.hero .meta div span { display: block; color: rgba(255,255,255,.65); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; }
.hero .meta div b { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; }

/* Barra de composición (elemento firma) */
.compo { margin-top: 22px; }
.compo-bar {
  display: flex; height: 16px; border-radius: 999px; overflow: hidden;
  background: rgba(255,255,255,.15);
}
.compo-bar span { height: 100%; transition: filter .15s; }
.compo-bar span:hover { filter: brightness(1.12); }
.compo-legend {
  display: flex; flex-wrap: wrap; gap: 12px 20px; margin-top: 14px;
}
.compo-legend .item { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: rgba(255,255,255,.85); }
.compo-legend .swatch { width: 11px; height: 11px; border-radius: 3px; }

/* ============================================================
   Chips, badges, tablas
   ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px;
  font-size: .8rem; font-weight: 600;
  background: var(--bg-soft); color: var(--ink-2);
}
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.badge.pos { background: var(--pos-soft); color: var(--pos); }
.badge.neg { background: var(--neg-soft); color: var(--neg); }
.badge.warn { background: var(--gasto-soft); color: #b45309; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: .9rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--bg-soft); }
.row-tag { width: 4px; border-radius: 4px; }

/* ============================================================
   Botones y formularios
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--r-sm);
  font-family: var(--font-body); font-weight: 600; font-size: .9rem;
  border: 1px solid transparent; cursor: pointer; transition: transform .1s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--inv); color: #fff; box-shadow: var(--sh-sm); }
.btn-primary:hover { box-shadow: var(--sh); }
.btn-gasto { background: var(--gasto); color: #fff; }
.btn-credito { background: var(--credito); color: #fff; }
.btn-ghost { background: var(--card); color: var(--ink-2); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-sm { padding: 7px 13px; font-size: .82rem; }
.btn-danger { background: var(--neg-soft); color: var(--neg); }
.btn-block { width: 100%; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
input, select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); background: #fff; color: var(--ink);
  font-family: var(--font-body); font-size: .92rem;
}
input:focus, select:focus { outline: 2px solid var(--inv); outline-offset: 1px; border-color: var(--inv); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; align-items: end; }

/* Progreso */
.progress { height: 12px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--credito), #0d9488); border-radius: 999px; transition: width .4s; }

/* ============================================================
   Flash
   ============================================================ */
.flashes { position: fixed; top: 18px; right: 18px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.flash {
  padding: 13px 18px; border-radius: var(--r-sm); background: var(--card);
  box-shadow: var(--sh-lg); font-size: .88rem; font-weight: 500;
  border-left: 4px solid var(--inv); animation: slidein .3s ease;
}
.flash.success { border-color: var(--pos); }
.flash.error { border-color: var(--neg); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Modal
   ============================================================ */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--card); border-radius: var(--r-lg); padding: 26px;
  width: 100%; max-width: 460px; box-shadow: var(--sh-lg);
  animation: pop .2s ease;
}
.modal h3 { font-size: 1.2rem; margin-bottom: 18px; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* ============================================================
   Login
   ============================================================ */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--home-soft), transparent),
              radial-gradient(1000px 500px at 110% 110%, var(--inv-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { justify-content: center; padding-bottom: 26px; }

/* ============================================================
   Mobile
   ============================================================ */
.mobile-nav { display: none; }
.month-picker { display: flex; align-items: center; gap: 8px; }

/* Ícono de editar (lápiz) dentro de botones */
.ico-edit { width: 15px; height: 15px; display: block; }

/* Ícono por tipo de cuenta / tarjeta */
.acct-ico {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; flex: none;
}
.acct-ico .ico { width: 20px; height: 20px; }
.acct-head { display: flex; align-items: center; gap: 12px; }
.acct-head .name { font-family: var(--font-display); font-size: 1.05rem; letter-spacing: -.02em; }

/* Tarjeta de cuenta con banda de color superior */
.acct-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.acct-body { display: flex; flex-direction: column; flex: 1; }
.acct-actions { margin-top: auto; }
.acct-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 18px; color: #fff;
  background: var(--acct, var(--inv));
}
.acct-banner .acct-ico { background: rgba(255, 255, 255, .22); color: #fff; }
.acct-banner .name { color: #fff; font-family: var(--font-display); font-size: 1.1rem;
  font-weight: 600; letter-spacing: -.02em; }
.acct-banner .type {
  margin-left: auto; font-size: .74rem; font-weight: 600; text-transform: capitalize;
  padding: 4px 11px; border-radius: 999px;
  background: rgba(255, 255, 255, .22); color: #fff;
}
.acct-body { padding: 18px 20px 20px; }

.acct-body .acct-value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700;
  letter-spacing: -.03em; line-height: 1.1; }
.acct-body .lbl { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--faint); font-weight: 600; }
.banner-edit { margin-left: 8px; background: rgba(255,255,255,.22); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer; display: grid; place-items: center; }
.banner-edit:hover { background: rgba(255,255,255,.35); }
.banner-edit svg { width: 16px; height: 16px; }

/* Grilla que llena el ancho disponible (mejor uso del desktop) */
.g-auto { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* Chips de filtro */
.chips-filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 2px; }
.fchip { padding: 8px 15px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--card); color: var(--ink-2); font-weight: 600; font-size: .86rem;
  cursor: pointer; transition: all .15s; }
.fchip:hover { background: var(--bg-soft); }
.fchip.active { background: var(--inv); color: #fff; border-color: var(--inv); }

/* Aportaciones (desglose) */
.aport-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px;
  align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.aport-row:last-of-type { border-bottom: none; }
details.aportaciones summary { cursor: pointer; font-size: .85rem; font-weight: 600;
  color: var(--inv); list-style: none; padding: 6px 0; }
details.aportaciones summary::-webkit-details-marker { display: none; }
details.aportaciones summary::before { content: "▸ "; }
details.aportaciones[open] summary::before { content: "▾ "; }

/* Tablet / desktop angosto: 2 columnas antes de colapsar a móvil */
@media (max-width: 1120px) {
  .main { padding: 26px 26px 90px; }
  .g-4, .g-3 { grid-template-columns: repeat(2, 1fr); }
  .g-hero { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 22px 18px 96px; }
  .g-2, .g-3, .g-4, .g-hero { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 1.5rem; }
  .hero .big { font-size: 2.3rem; }

  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--card); border-top: 1px solid var(--border);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around; box-shadow: 0 -4px 20px rgba(15,23,42,.06);
  }
  .mobile-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: .66rem; color: var(--muted); font-weight: 600; padding: 4px 10px; border-radius: 10px;
  }
  .mobile-nav a .ico { width: 22px; height: 22px; }
  .mobile-nav a.active.home { color: var(--home); }
  .mobile-nav a.active.inv { color: var(--inv); }
  .mobile-nav a.active.gasto { color: var(--gasto); }
  .mobile-nav a.active.credito { color: var(--credito); }
  .mobile-nav a.active.hist { color: var(--home); }
  .mobile-nav a { padding: 4px 7px; }
}

/* Tablas apiladas en celular: cada fila = una tarjeta etiqueta → valor */
@media (max-width: 860px) {
  table.stack, table.stack tbody, table.stack tfoot, table.stack tr, table.stack td {
    display: block; width: 100%;
  }
  table.stack thead { display: none; }
  table.stack tr {
    border: 1px solid var(--border); border-radius: var(--r-sm);
    background: var(--card); box-shadow: var(--sh-sm);
    padding: 4px 14px; margin-bottom: 12px;
  }
  table.stack tr:last-child { margin-bottom: 0; }
  table.stack td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 10px 0 !important; border-bottom: 1px solid var(--border);
    text-align: right; font-size: .92rem;
  }
  table.stack td:last-child { border-bottom: none; }
  table.stack td::before {
    content: attr(data-label);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--faint); font-weight: 600; text-align: left; flex: none;
  }
  /* Celdas sin etiqueta: barra de color y acciones */
  table.stack td.cell-tag { display: none; }
  /* Detalle fino oculto en celular (visible en desktop y al tocar el pago) */
  table.stack td.cell-detail { display: none; }
  table.stack td.cell-actions { justify-content: flex-end; padding-top: 12px !important; }
  table.stack td.cell-actions::before { content: none; }
  table.stack td.cell-actions .flex { justify-content: flex-end !important; width: 100%; }
  /* La primera celda con etiqueta encabeza la tarjeta */
  table.stack tbody tr td:nth-child(2),
  table.stack tfoot tr td:first-child { font-weight: 700; }

  /* Gastos: concepto como título destacado + acento de color por categoría */
  #tblGastos tbody tr {
    display: flex; flex-direction: column;
    border-left: 5px solid var(--rowcolor, var(--border));
  }
  #tblGastos td.cell-title {
    order: -1; border-bottom: none; padding: 4px 0 2px !important;
    font-family: var(--font-display); font-size: 1.25rem; font-weight: 700;
    color: var(--ink); letter-spacing: -.02em; justify-content: flex-start;
  }
  #tblGastos td.cell-title::before { content: none; }
  #tblGastos td[data-label="Monto"] { font-size: 1.05rem; }
  #tblGastos td[data-label="Monto"] > * , #tblGastos td[data-label="Monto"] { font-weight: 700; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Utilidades */
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 18px; }
.mt-sm { margin-top: 10px; }
.flex { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.empty { text-align: center; padding: 40px 20px; color: var(--faint); }
.empty .big-ico { font-size: 2.4rem; margin-bottom: 8px; opacity: .5; }
