/* ═══════════════════════════════════════════
   Variables y Reset
═══════════════════════════════════════════ */
:root {
  --sidebar-bg:     #1a2332;
  --sidebar-hover:  #243040;
  --sidebar-active: #22883f;
  --accent:         #22883f;
  --accent-hover:   #1a6b30;
  --bg:             #f5f6fa;
  --card:           #ffffff;
  --text:           #1e293b;
  --muted:          #64748b;
  --border:         #e2e8f0;
  --danger:         #dc2626;
  --warning:        #d97706;
  --success:        #16a34a;
  --info:           #0284c7;
  --radius:         10px;
  --shadow:         0 1px 4px rgba(0,0,0,.08);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════
   Layout
═══════════════════════════════════════════ */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform .25s ease;
}
.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand .empresa {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7fb3e0;
  font-weight: 600;
}
.sidebar-brand .titulo {
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 2px;
}
.sidebar nav { padding: 0.75rem 0; flex: 1; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1.25rem;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.sidebar-link.activo {
  background: rgba(34,136,63,.15);
  color: #fff;
  border-left-color: var(--accent);
}
.sidebar-link .icon { font-size: 1rem; width: 18px; text-align: center; }
.sidebar-footer {
  padding: 1rem 1.25rem;
  font-size: 0.7rem;
  color: rgba(255,255,255,.25);
  border-top: 1px solid rgba(255,255,255,.07);
}

/* Main */
.main { margin-left: 240px; flex: 1; min-width: 0; }  /* min-width:0 = el flex item se encoge y deja scrollear tablas (no estira la página) */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-titulo { font-weight: 600; font-size: 1rem; }
.topbar-fecha  { color: var(--muted); font-size: 0.82rem; }
.content { padding: 1.75rem 2rem; }

/* Botón hamburguesa (☰) — solo visible en celular */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text, #0f172a);
  padding: 0.1rem 0.6rem 0.1rem 0;
  margin-right: 0.2rem;
}
/* Fondo oscuro detrás del menú deslizante — solo en celular */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 90;
}

/* ═══════════════════════════════════════════
   Flash Messages
═══════════════════════════════════════════ */
.flash-container { padding: 0 2rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.flash.exito  { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash.error  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash.info   { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* ═══════════════════════════════════════════
   KPI Cards
═══════════════════════════════════════════ */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.kpi-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.kpi-icon.verde   { background: #dcfce7; color: #16a34a; }
.kpi-icon.azul    { background: #dbeafe; color: #1d4ed8; }
.kpi-icon.amarillo{ background: #fef3c7; color: #d97706; }
.kpi-icon.rojo    { background: #fee2e2; color: #dc2626; }
.kpi-label { font-size: 0.75rem; color: var(--muted); }
.kpi-valor { font-size: 1.35rem; font-weight: 700; margin-top: 1px; }
.kpi-sub   { font-size: 0.75rem; color: var(--muted); }

/* ═══════════════════════════════════════════
   Cards y Tablas
═══════════════════════════════════════════ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.card-header h2 { font-size: 0.95rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.card-footer {
  padding: 0.6rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 0.6rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.tabla-scroll { overflow-x: auto; }

/* ═══════════════════════════════════════════
   Badges y Estado
═══════════════════════════════════════════ */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-activo    { background: #dcfce7; color: #166534; }
.badge-liquidado { background: #dbeafe; color: #1e40af; }
.badge-cancelado { background: #f3f4f6; color: #6b7280; }
.badge-pagado    { background: #dcfce7; color: #166534; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-vencido   { background: #fee2e2; color: #991b1b; }

/* ═══════════════════════════════════════════
   Botones
═══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 7px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f1f5f9; }
.btn-danger   { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 0.95rem; }

/* ═══════════════════════════════════════════
   Formularios
═══════════════════════════════════════════ */
.form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.form-grid.tres { grid-template-columns: 1fr 1fr 1fr; }
.form-full  { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
label { font-size: 0.82rem; font-weight: 500; color: var(--text); }
label .req { color: var(--danger); }
input, select, textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.88rem;
  background: #fff;
  color: var(--text);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34,136,63,.1);
}
input[readonly] { background: #f8fafc; color: var(--muted); }
.form-hint { font-size: 0.75rem; color: var(--muted); }

/* Buscador */
.search-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.search-box input { min-width: 200px; }

/* ═══════════════════════════════════════════
   Preview / Info box
═══════════════════════════════════════════ */
.preview-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1.25rem;
}
.preview-box h3 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #166534;
  margin-bottom: 0.75rem;
}
.preview-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(0,0,0,.05);
  font-size: 0.88rem;
}
.preview-row:last-child { border-bottom: none; }
.preview-row .label { color: var(--muted); }
.preview-row .valor { font-weight: 600; }
.preview-row .valor.grande { font-size: 1.1rem; color: var(--accent); }

/* Cuota box */
.cuota-box {
  background: linear-gradient(135deg, #1a2332 0%, #243040 100%);
  border-radius: var(--radius);
  padding: 1.5rem;
  color: #fff;
  margin-bottom: 1.5rem;
}
.cuota-box .mes-label {
  font-size: 0.8rem;
  opacity: .7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cuota-box .cuota-items { display: flex; gap: 2rem; margin: 1rem 0; }
.cuota-box .ci-label { font-size: 0.75rem; opacity: .6; }
.cuota-box .ci-val   { font-size: 1rem; font-weight: 600; }
.cuota-box .ci-total { font-size: 1.35rem; font-weight: 700; color: #4ade80; }
.cuota-box .cuota-btns { display: flex; gap: 0.75rem; margin-top: 1rem; }
.btn-blanco { background: #fff; color: var(--sidebar-bg); font-weight: 600; }
.btn-blanco:hover { background: #e2e8f0; }
.btn-verde-outline {
  background: transparent;
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
}
.btn-verde-outline:hover { background: rgba(255,255,255,.1); }

/* Barra de progreso */
.progress-wrap { background: #e2e8f0; border-radius: 20px; height: 8px; overflow: hidden; }
.progress-bar  {
  height: 100%;
  background: var(--accent);
  border-radius: 20px;
  transition: width .4s;
}

/* ═══════════════════════════════════════════
   Autocomplete cliente
═══════════════════════════════════════════ */
.autocomplete-wrapper { position: relative; }
.autocomplete-results {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0 0 7px 7px;
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}
.autocomplete-item {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: #f0fdf4; }
.autocomplete-item .nombre { font-weight: 600; }
.autocomplete-item .nit    { color: var(--muted); font-size: 0.8rem; }

/* ═══════════════════════════════════════════
   Historial de pagos — color en fila
═══════════════════════════════════════════ */
tr.fila-pagada td { background: #f0fdf4; }
tr.fila-actual td { background: #fffbeb; font-weight: 600; }

/* ═══════════════════════════════════════════
   Utilidades
═══════════════════════════════════════════ */
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.font-mono { font-family: 'SF Mono', 'Consolas', monospace; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Filtros tabs */
.filtros { display: flex; gap: 0.35rem; }
.filtro-btn {
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  text-decoration: none;
  transition: all .15s;
}
.filtro-btn.activo, .filtro-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Sidebar user block ─────────────────────────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
  margin-top: auto;
}
.sidebar-user-icon { font-size: 1.4rem; }
.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.sidebar-user-logout {
  font-size: 0.7rem;
  color: rgba(255,255,255,.4);
  text-decoration: none;
}
.sidebar-user-logout:hover { color: rgba(255,255,255,.8); }

/* ── Modal overlay ─────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.abierto { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  margin: 1rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: .2rem .4rem;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 1.25rem 1.5rem 1.5rem; }

/* ── Mora / estado rows ────────────────────────────────────── */
.fila-vencida td    { background: #fff5f5 !important; }
.fila-por-vencer td { background: #fffbeb !important; }
.fila-anulada td    { background: #f9fafb !important; opacity: .7; }
.fila-anulada td, .fila-anulada .fw-bold { color: var(--muted) !important; }

/* ── Badge anulado ─────────────────────────────────────────── */
.badge-anulado {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}

/* ── Btn sm ─────────────────────────────────────────────────── */
.btn-sm { padding: .3rem .65rem; font-size: 0.8rem; }

/* Responsive */
@media (max-width: 900px) {
  /* Menú lateral como cajón deslizante: oculto por defecto, entra al abrir */
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-overlay { display: block; }
  .menu-toggle { display: inline-flex; align-items: center; }
  .main { margin-left: 0; }

  /* Márgenes y barra superior más compactos */
  .content { padding: 1rem 0.85rem; }
  .topbar { padding: 0.7rem 0.85rem; }
  .topbar-fecha { display: none; }  /* ahorra espacio en pantallas chicas */

  /* Formularios y KPIs apilados */
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.tres { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }

  /* Filas de botones / filtros / búsqueda: que se acomoden en varias líneas */
  .top-actions, .search-box, .filtros { flex-wrap: wrap; }
  .search-box input { min-width: 0; flex: 1; }
  /* Filas con display:flex inline (ej. botones de acción) también hacen wrap */
  [style*="display:flex"], [style*="display: flex"] { flex-wrap: wrap; }

  /* Tarjetas de KPI: el item de grid se encoge y el número largo no desborda */
  .kpi-card { min-width: 0; }
  .kpi-valor { font-size: 1.05rem; overflow-wrap: anywhere; }

  /* Tablas anchas: scroll horizontal automático (sin tocar cada plantilla) */
  .tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  th, td { white-space: nowrap; }
}

/* En celulares angostos los KPIs van en una sola columna: cada número con
   ancho completo, sin partirse a media cifra. En tablet/landscape (481-900) van en 2. */
@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi-valor { font-size: 1.25rem; }  /* con ancho completo el número cabe entero */
}
