* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-ancho: 230px;
  --sidebar-cerrado: 56px;
  --azul: #1e3a5f;
  --azul-claro: #2c5282;
  --gris-fondo: #f4f6f8;
  --borde: #d9dee4;
  --rojo: #c0392b;
  --verde: #1e7e34;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: #1a202c;
  background: var(--gris-fondo);
}

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-ancho);
  background: var(--azul);
  color: #fff;
  flex-shrink: 0;
  transition: width 0.2s ease;
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-cerrado .sidebar { width: var(--sidebar-cerrado); }

.sidebar-header {
  padding: 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  white-space: nowrap;
}
.logo { font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  color: #cbd5e0;
  text-decoration: none;
  white-space: nowrap;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--azul-claro); color: #fff; }
.nav-item.activo {
  background: var(--azul-claro);
  color: #fff;
  border-left-color: #63b3ed;
}
.nav-icon { width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-cerrado .nav-label { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border-bottom: 1px solid var(--borde);
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.btn-toggle {
  border: 1px solid var(--borde);
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 15px;
  cursor: pointer;
}
.btn-toggle:hover { background: var(--gris-fondo); }
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-fecha { margin-left: auto; color: #718096; }

.contenido { padding: 18px; overflow-x: auto; }

.contenido h1 { font-size: 19px; margin-bottom: 4px; }
.contenido h2 { font-size: 15px; margin: 16px 0 10px; }
.subtitulo { color: #718096; margin-bottom: 16px; }

/* ---------- Tablas ---------- */
.tabla-wrap {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
}

table { border-collapse: collapse; width: 100%; font-size: 12px; }
th {
  background: #edf2f7;
  text-align: left;
  padding: 7px 8px;
  font-weight: 600;
  border-bottom: 2px solid var(--borde);
  white-space: nowrap;
}
td { padding: 6px 8px; border-bottom: 1px solid #eef1f4; white-space: nowrap; }
tbody tr:hover td { background: #f7fafc; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.neg { color: var(--rojo); }
.pos { color: var(--verde); }

/* Reportes agrupados por agencia */
.fila-agencia td {
  background: #e2e8f0;
  font-weight: 700;
  border-top: 2px solid var(--borde);
}
.fila-totales td { font-weight: 700; background: #f7fafc; border-top: 1px solid var(--borde); }

/* ---------- Cards / dashboard ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: #fff; border: 1px solid var(--borde); border-radius: 8px; padding: 14px 16px; }
.card .card-label { color: #718096; font-size: 12px; margin-bottom: 6px; }
.card .card-valor { font-size: 21px; font-weight: 700; }

/* ---------- Controles / formularios ---------- */
.barra-acciones { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
input, select, textarea {
  padding: 7px 10px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  font-family: inherit;
}
input[type="checkbox"] { width: auto; }

.btn {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: var(--azul);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: var(--azul-claro); }
.btn-sec { background: #fff; color: var(--azul); border: 1px solid var(--borde); }
.btn-sec:hover { background: var(--gris-fondo); }
.btn-mini { padding: 3px 8px; font-size: 11px; }
.btn-rojo { background: var(--rojo); }

.form-card {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.form-card h3 { font-size: 13px; margin-bottom: 10px; color: #4a5568; }
.form-grid { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #718096; }
.form-grid input, .form-grid select { min-width: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge-verde { background: #d4edda; color: #1e7e34; }
.badge-amarillo { background: #fff3cd; color: #856404; }
.badge-rojo { background: #f8d7da; color: #c0392b; }
.badge-gris { background: #e2e8f0; color: #4a5568; }

@media print {
  .sidebar, .topbar, .barra-acciones, .form-card, .no-print { display: none !important; }
  .contenido { padding: 0; }
  .tabla-wrap { border: none; }
}

/* ---------- Overlay de espera (formularios con data-espera) ---------- */
.overlay-carga {
  position: fixed;
  inset: 0;
  background: rgba(30, 58, 95, 0.55);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1000;
}
.overlay-carga.visible { display: flex; }
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: girar 0.8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
.overlay-carga p {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Renglón cuyo ticket ya existe en Ventas (posible duplicado) */
.fila-dup td { background: #fff3cd; }
