:root {
  --bg: #0D1117;
  --surface: #161B22;
  --surface-alt: #10141A;
  --border: #232A34;
  --border-soft: #171C24;
  --text: #E6EDF3;
  --text-dim: #C4CDD7;
  --text-mute: #8B949E;
  --text-faint: #7F8B9B;
  --text-ghost: #7A8696;
  --accent: #3DDC97;
  --accent-light: #5EE8AC;
  --danger: #F87171;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
}

body {
  font-family: 'Manrope', system-ui, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

input::placeholder { color: var(--text-ghost); }
input, button, select, textarea { font-family: 'Manrope', system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }
button { cursor: pointer; }

.num { font-family: 'Space Grotesk', sans-serif; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

.bottom-nav {
  height: 68px;
  flex-shrink: 0;
  background: var(--surface-alt);
  border-top: 1px solid #1E242D;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  position: sticky;
  bottom: 0;
  z-index: 10;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-ghost);
  font-size: 10px;
  font-weight: 600;
  min-width: 44px;
  padding: 4px 0;
}
.nav-item.active { color: var(--accent); font-weight: 700; }
/* "Salir" solo en el menú lateral de PC; en celular se sale desde Perfil. */
.nav-logout { display: none; }
.nav-fab {
  width: 48px; height: 48px;
  border-radius: 999px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-top: -22px;
  box-shadow: 0 4px 14px rgba(61,220,151,0.4);
}

.card {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.btn-primary {
  height: 50px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
  width: 100%;
}
.btn-primary:disabled { opacity: 0.6; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-mute);
  font-size: 13px;
}

.input-field {
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  width: 100%;
  outline: none;
}
.input-field:focus { border-color: var(--accent); }

select.input-field {
  appearance: none;
  -webkit-appearance: none;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.error-banner {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.4);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  display: none;
}

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.spinner {
  font-size: 12.5px;
  color: var(--text-faint);
  padding: 24px 0;
  text-align: center;
}

/* Contenido del dashboard: oculto hasta que cargan los datos (clase .ready). */
#content { display: none; flex-direction: column; gap: 18px; }
#content.ready { display: flex; }

/* Elementos solo para el menú lateral de PC: ocultos en celular. */
.nav-brand, .nav-fab-label { display: none; }

/* Estado "pendiente de pago" en listas */
.badge-pending {
  font-size: 10.5px;
  font-weight: 700;
  color: #F2B84B;
  background: rgba(242,184,75,0.12);
  border: 1px solid rgba(242,184,75,0.35);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
}
.paid-toggle {
  width: 22px; height: 22px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1.5px solid var(--text-ghost);
  background: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--bg);
  padding: 0;
}
.paid-toggle.on { background: var(--accent); border-color: var(--accent); }

/* ---------- Diseño para PC (pantallas anchas) ---------- */
@media (min-width: 1024px) {
  /* El menú pasa a ser una barra lateral fija a la izquierda. */
  body.has-nav { padding-left: 230px; }

  .bottom-nav {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 230px;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    padding: 22px 14px;
    border-top: none;
    border-right: 1px solid #1E242D;
  }
  .nav-brand {
    display: block;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
    padding: 4px 14px 18px 14px;
  }
  .nav-item {
    flex-direction: row;
    gap: 12px;
    min-width: 0;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
  }
  .nav-item:hover { background: var(--surface); }
  .nav-item.active { background: rgba(61,220,151,0.1); }
  .nav-fab {
    order: -1;                 /* el botón "Nuevo movimiento" queda arriba del menú */
    width: auto; height: 44px;
    margin: 0 0 10px 0;
    border-radius: var(--radius-sm);
    gap: 10px;
    box-shadow: none;
  }
  .nav-fab-label { display: inline; color: #0D1117; font-size: 14px; font-weight: 700; }
  .nav-brand { order: -2; }
  .nav-logout {
    display: flex; align-items: center; gap: 12px;
    margin-top: auto;            /* lo empuja al pie del menú */
    padding: 11px 14px; border-radius: var(--radius-sm);
    background: none; border: none; color: var(--text-faint);
    font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .nav-logout:hover { background: var(--surface); color: var(--danger); }

  /* Contenido más ancho, centrado en el espacio libre. */
  .app-shell { max-width: 1040px; }

  /* Dashboard en dos columnas */
  #content.ready { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
  #content .span-all { grid-column: 1 / -1; }

  /* Formularios angostos y centrados */
  .narrow { max-width: 560px; width: 100%; margin-left: auto; margin-right: auto; }
}

/* ---------- Análisis ---------- */
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav button {
  width: 34px; height: 34px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-mute);
  font-size: 16px; line-height: 1; padding: 0;
}
.month-nav button:hover { color: var(--text); }
.month-nav .month-label { min-width: 138px; text-align: center; font-weight: 700; font-size: 15px; color: var(--text); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; color: var(--text-faint);
  font-size: 14px; font-weight: 700; padding: 10px 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; }
.stat .k { font-size: 11.5px; color: var(--text-faint); font-weight: 600; }
.stat .v { font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 700; margin-top: 2px; }

.blocks { display: grid; grid-template-columns: 1fr; gap: 14px; align-items: start; }
.block-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.block-title { font-size: 13.5px; font-weight: 700; color: var(--text); }
.block-total { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 16px; }
.block-items { max-height: 320px; overflow-y: auto; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border-soft); }
.item-main { flex-grow: 1; min-width: 0; }
.item-title { font-size: 13px; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 11px; color: var(--text-faint); }
.empty-note { font-size: 12.5px; color: var(--text-faint); padding: 8px 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 11.5px; color: var(--text-faint); font-weight: 700;
  padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 4px 6px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.data-table input, .data-table select {
  width: 100%; background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--text); font-size: 13px; padding: 7px 6px; min-width: 0;
}
.data-table input:hover, .data-table select:hover { border-color: var(--border); }
.data-table input:focus, .data-table select:focus { outline: none; border-color: var(--accent); background: var(--surface-alt); }
.data-table select option { background: var(--surface); }
.data-table input.amt { text-align: right; font-family: 'Space Grotesk', sans-serif; font-weight: 700; }
.data-table tr.flash td { background: rgba(61,220,151,0.10); }
.data-table tr.new-row td { background: var(--surface-alt); }
.data-table tfoot td { font-weight: 700; padding: 10px 8px; border-bottom: none; }

.matrix th, .matrix td { white-space: nowrap; }
.matrix td.num-cell { text-align: right; font-family: 'Space Grotesk', sans-serif; padding: 8px 10px; }
.matrix td.pending { color: #F2B84B; }
.matrix td.paid { color: var(--accent); }
.matrix .sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 170px; padding: 8px 10px; }
.matrix tfoot td { padding: 10px; }
.matrix small { display: block; font-size: 10px; color: var(--text-faint); font-family: 'Manrope', sans-serif; }

.charts { display: flex; flex-direction: column; gap: 14px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-mute); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

@media (min-width: 1024px) {
  .stat-row { grid-template-columns: repeat(5, 1fr); }
  .blocks { grid-template-columns: 1fr 1fr; }
  .charts { display: grid; grid-template-columns: 1fr 1.3fr; gap: 14px; align-items: start; }
}


/* ---------- Accesibilidad y detalles (revisión UI) ---------- */
/* Foco visible para quien navega con teclado. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.data-table input:focus-visible, .data-table select:focus-visible { outline-offset: 0; }

/* Montos y fechas con cifras de ancho fijo: las columnas quedan alineadas. */
.num, .stat .v, .block-total, .data-table input.amt, .data-table td.num-cell, .data-table td.num {
  font-variant-numeric: tabular-nums;
}

/* Estado "pendiente" con texto además del color. */
.badge-pending::before { content: "◷ "; }

/* Esqueletos de carga */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, #1E252F 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty-state { text-align: center; padding: 22px 12px; color: var(--text-faint); font-size: 13px; line-height: 1.5; }
.empty-state a { font-weight: 700; }

/* Barra de acciones en lote */
.bulk-bar {
  display: none; align-items: center; gap: 10px; flex-wrap: wrap;
  background: rgba(61,220,151,0.08); border: 1px solid rgba(61,220,151,0.3);
  border-radius: var(--radius-md); padding: 8px 12px; font-size: 13px;
}
.bulk-bar.show { display: flex; }
.bulk-bar button { height: 34px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.bulk-bar button.danger { color: var(--danger); border-color: rgba(248,113,113,0.4); }

/* Gráficos: detalle en tabla como alternativa accesible */
.chart-table summary { cursor: pointer; font-size: 12px; color: var(--text-mute); margin-top: 10px; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.chart-table th { text-align: left; color: var(--text-faint); font-weight: 600; padding: 4px 6px; }
.chart-table td { padding: 4px 6px; border-top: 1px solid var(--border-soft); }
.chart-table td.r, .chart-table th.r { text-align: right; font-variant-numeric: tabular-nums; }

/* Día a día: en celular cada fila pasa a ser una tarjeta (sin scroll horizontal). */
@media (max-width: 640px) {
  #daily { min-width: 0 !important; }
  #daily thead { display: none; }
  #daily, #daily tbody, #daily tfoot { display: block; }
  #daily tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px;
    padding: 12px; border-bottom: 1px solid var(--border);
  }
  #daily tr.new-row { background: var(--surface-alt); }
  #daily td { display: block; width: auto !important; padding: 0 !important; border: none; text-align: left !important; }
  #daily td[data-label]::before {
    content: attr(data-label); display: block; font-size: 10.5px; font-weight: 700;
    color: var(--text-faint); margin-bottom: 2px;
  }
  #daily td.span2 { grid-column: 1 / -1; }
  #daily td.sel-cell, #daily td.paid-cell, #daily td.del-cell { display: flex; align-items: center; gap: 8px; }
  #daily td.sel-cell::before, #daily td.paid-cell::before { margin: 0; }
  #daily tfoot tr { display: block; }
  #daily tfoot td { display: block; }
  #daily tfoot td[colspan="3"] { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (max-width: 640px) { #daily td:empty { display: none; } }
