/* ============================================================
   Contabilidad Básica — estilos (tema oscuro, menú lateral, responsive)
   ============================================================ */
:root {
  --bg1: #0f1b3d; --bg2: #16275c; --card: #1a2c5e; --border: #2c3f7a;
  --text: #eef1f8; --muted: #8b9ac7; --gold: #ffd166; --accent: #2d6a4f;
  --accent2: #1f6fb2; --rojo: #c05a5a; --verde: #4c9e6f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: linear-gradient(160deg, var(--bg1), var(--bg2)); min-height: 100vh; color: var(--text); }
.hidden { display: none !important; }
button { font-family: inherit; }
.btn { background: #262b42; color: #e8e8f0; border: 1px solid #3a4062; border-radius: 8px; padding: 9px 14px; font-size: .9rem; cursor: pointer; }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: #5a2525; border-color: #8f4a4a; }
.btn.small { padding: 5px 10px; font-size: .78rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea { width: 100%; padding: 9px; margin-bottom: 8px; border-radius: 8px; border: 1px solid var(--border); background: #0d1530; color: var(--text); font-size: .92rem; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--gold); }
label.lbl { display: block; font-size: .8rem; color: var(--muted); margin: 8px 0 4px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 1.02rem; margin-bottom: 10px; color: var(--gold); }
.card h3 { font-size: .92rem; margin: 12px 0 8px; color: var(--text); }
.hint { color: var(--muted); font-size: .82rem; margin-bottom: 8px; }
.status-line { font-size: .85rem; margin-top: 6px; min-height: 1.2em; color: var(--gold); }
.badge { padding: 2px 8px; border-radius: 12px; font-size: .72rem; background: #33457f; white-space: nowrap; }
.badge.admin { background: #7a5c1e; } .badge.auxiliar { background: #1f6fb2; }
.badge.definitivo { background: var(--accent); } .badge.anulado { background: #5a2525; }
.badge.vencido { background: #7a2d2d; } .badge.por_vencer { background: #7a5c1e; } .badge.pagado { background: var(--accent); }
.badge.caja { background: #1f6fb2; } .badge.banco { background: #2d6a4f; } .badge.otra { background: #33457f; }

/* ---------- Login ---------- */
#view-login { display: flex; justify-content: center; padding-top: 9vh; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 30px; width: 100%; max-width: 400px; text-align: center; }
.login-card h1 { font-size: 1.6rem; margin-bottom: 4px; }
.tagline { color: var(--muted); font-size: .9rem; margin-bottom: 16px; }

/* ---------- Layout: menú lateral ---------- */
#view-app { display: flex; min-height: 100vh; }
#sidebar { width: 220px; min-width: 220px; background: #0c1733; border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { font-size: 1.15rem; font-weight: 700; padding: 4px 8px 14px; }
.logo span { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { text-align: left; background: transparent; border: none; color: var(--muted); border-radius: 8px; padding: 10px 12px; font-size: .9rem; cursor: pointer; }
.nav-item:hover { background: #16275c; color: var(--text); }
.nav-item.active { background: var(--gold); color: #1a1a1a; font-weight: 700; }
.side-foot { font-size: .72rem; color: var(--muted); padding: 8px; }
#main { flex: 1; padding: 16px 20px; max-width: 1280px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.25rem; flex: 1; }
.topbar .who { color: var(--muted); font-size: .82rem; }
.empresa-switch { width: auto; max-width: 260px; margin: 0; padding: 6px 10px; font-size: .85rem; }

/* ---------- Componentes ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 1000px) { .grid3, .grid4 { grid-template-columns: 1fr 1fr; } }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.kpi .k-titulo { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi .k-valor { font-size: 1.35rem; font-weight: 700; margin-top: 4px; }
.kpi .k-sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.kpi.positivo .k-valor { color: #7fd4a5; } .kpi.negativo .k-valor { color: #ff9b8a; } .kpi.dorado .k-valor { color: var(--gold); }

.tabla-wrap { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tabla th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); padding: 8px 8px; white-space: nowrap; }
.tabla td { padding: 7px 8px; border-bottom: 1px solid #1b2a55; vertical-align: middle; }
.tabla tr:hover td { background: #16275c; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabla .tot { font-weight: 700; border-top: 2px solid var(--border); background: #16275c; }
.mono { font-family: Consolas, monospace; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { background: #1a2c5e; border: 1px solid var(--border); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-size: .85rem; }
.tab.active { background: var(--gold); color: #1a1a1a; font-weight: 700; border-color: var(--gold); }

.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filtros input, .filtros select { width: auto; margin: 0; padding: 7px 10px; }
.filtros .lbl { margin: 0 0 3px; }

.list-item { background: #16214a; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: .88rem; }
.list-item .meta { color: var(--muted); font-size: .78rem; }
.acciones { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5, 10, 25, .72); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 24px 12px; overflow-y: auto; }
#modal-puc { z-index: 60; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; width: 100%; max-width: 760px; }
.modal h2 { color: var(--gold); font-size: 1.05rem; margin-bottom: 12px; }
.modal-acciones { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }

/* ---------- Líneas de comprobante ---------- */
.linea-comp { display: grid; grid-template-columns: 215px 1fr 120px 120px 36px; gap: 6px; margin-bottom: 6px; align-items: center; }
.linea-comp input, .linea-comp .combo { margin: 0; }
.combo { position: relative; }
.combo-fila { display: flex; gap: 4px; }
.combo-fila input { flex: 1; min-width: 0; }
.combo-fila .btn { margin: 0; padding: 5px 9px; }
.combo .sugerencias { position: absolute; top: 100%; left: 0; right: 0; background: #0d1530; border: 1px solid var(--border); border-radius: 0 0 8px 8px; z-index: 20; max-height: 220px; overflow-y: auto; }
.combo .sugerencias div { padding: 7px 10px; font-size: .8rem; cursor: pointer; border-bottom: 1px solid #1b2a55; }
.combo .sugerencias div:hover { background: #1f6fb2; }
.combo .sugerencias .cod { color: var(--gold); font-weight: 700; margin-right: 6px; font-family: Consolas, monospace; }
.totales-linea { display: flex; gap: 18px; margin-top: 10px; font-size: .9rem; }
.totales-linea .dif { font-weight: 700; }
.totales-linea .dif.ok { color: var(--verde); } .totales-linea .dif.mal { color: #ff9b8a; }

/* ---------- Gráfico ---------- */
.grafico { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding: 8px 4px 0; }
.grafico .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.grafico .barra { width: 60%; border-radius: 4px 4px 0 0; }
.grafico .barra.ing { background: var(--verde); } .grafico .barra.gas { background: var(--rojo); }
.grafico .ley { font-size: .68rem; color: var(--muted); }
.leyenda { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin-top: 8px; }
.leyenda span b { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* ---------- Navegador PUC (modal) ---------- */
.pb-lista { max-height: 52vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; background: #0d1530; font-size: .85rem; }
.pb-lista .cod { color: var(--gold); font-weight: 700; margin-right: 6px; font-family: Consolas, monospace; }
.pb-lista .pb-ruta { color: var(--muted); font-size: .72rem; margin-right: 6px; }
.puc-fila { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.puc-fila:hover { background: #16275c; }
.pb-flecha { background: none; border: none; color: var(--muted); cursor: pointer; width: 22px; font-size: .8rem; flex-shrink: 0; }
.pb-flecha:hover { color: var(--gold); }
.pb-vacio { display: inline-block; }
.puc-fila .puc-item { flex: 1; padding: 5px 4px; }
.puc-fila .puc-item:hover { background: transparent; color: var(--gold); }
.pb-usar { margin: 2px 4px; padding: 3px 8px; font-size: .72rem; flex-shrink: 0; }
.puc-item { padding: 6px 4px; cursor: pointer; border-radius: 6px; }
.puc-item:hover { background: #1f6fb2; }
.puc-item .badge { margin-left: 6px; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #0c1733; border: 1px solid var(--gold); color: var(--text); padding: 10px 18px; border-radius: 10px; z-index: 100; font-size: .88rem; box-shadow: 0 4px 18px rgba(0,0,0,.5); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  #sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; height: 100vh; }
  #sidebar.abierto { transform: translateX(0); }
  #main { padding: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .linea-comp { grid-template-columns: 1fr 1fr; }
  .topbar h1 { font-size: 1.05rem; }
}
