/* ── Variables ───────────────────────────────────────────────── */
:root {
  --sidebar-width: 260px;
  --sidebar-bg: #0f172a;
  --topbar-h: 56px;
}

/* ── Reset ───────────────────────────────────────────────────── */
* { box-sizing: border-box; }
body { font-family: 'Segoe UI', sans-serif; background: #f4f6f9; margin: 0; }

/* ── Layout desktop ──────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--sidebar-bg);
  color: #fff;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  z-index: 1040;
}

.main-content { flex: 1; padding: 1.5rem; overflow-x: hidden; min-width: 0; }

/* ── Sidebar links ───────────────────────────────────────────── */
#sidebar .nav-link { border-radius: 8px; font-size: .9rem; padding: .45rem .75rem; color: #cbd5e1; }
#sidebar .nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
#sidebar .nav-link.active { background: #0d6efd; color: #fff; }
#sidebar hr { border-color: #334155; }

/* ── Topbar mobile ───────────────────────────────────────────── */
#topbar-mobile {
  display: none;
  position: sticky;
  top: 0;
  z-index: 1050;
  background: var(--sidebar-bg);
  color: #fff;
  padding: .75rem 1rem;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

#topbar-mobile .brand { font-weight: 700; font-size: 1.1rem; color: #38bdf8; }

#btn-menu-mobile {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

/* Overlay oscuro al abrir sidebar en mobile */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1039;
}

#sidebar-overlay.visible { display: block; }

/* ── Cards KPI ───────────────────────────────────────────────── */
.kpi-card { border: none; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.07); }
.kpi-card .kpi-valor { font-size: 2rem; font-weight: 700; }
.kpi-card .kpi-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: #6c757d; }

/* ── Tablas ──────────────────────────────────────────────────── */
.table-hover tbody tr:hover { background: #f0f4ff; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: #6c757d; border-top: none; }

/* ── Score colors ────────────────────────────────────────────── */
.score-alto  { color: #198754; font-weight: 700; }
.score-medio { color: #fd7e14; font-weight: 700; }
.score-bajo  { color: #dc3545; font-weight: 700; }

/* ── Badges estado ───────────────────────────────────────────── */
.badge-borrador  { background: #6c757d; }
.badge-enviada   { background: #0d6efd; }
.badge-revisada  { background: #fd7e14; }
.badge-publicada { background: #198754; }

/* ── Login ───────────────────────────────────────────────────── */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0f172a; padding: 1rem; }
.login-card { width: 100%; max-width: 420px; border-radius: 16px; border: 1px solid #1e293b; background: #1e293b; }
.login-card .form-control { background: #0f172a; border-color: #334155; color: #f1f5f9; }
.login-card .form-control:focus { border-color: #0d6efd; box-shadow: none; color: #f1f5f9; background: #0f172a; }
.login-card label { color: #94a3b8; }

/* ── Toast ───────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }

/* ── RESPONSIVE MOBILE ───────────────────────────────────────── */
@media (max-width: 768px) {

  /* Mostrar topbar mobile */
  #topbar-mobile { display: flex; }

  /* Sidebar se convierte en drawer lateral */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: 4px 0 16px rgba(0,0,0,.3);
  }

  #sidebar.open { transform: translateX(0); }

  /* Main content ocupa todo el ancho */
  .app-wrapper { flex-direction: column; }
  .main-content { padding: 1rem; padding-top: calc(var(--topbar-h) + .75rem); }

  /* Tablas scrolleables */
  .table-responsive { -webkit-overflow-scrolling: touch; }

  /* Cards en columna */
  .kpi-card .kpi-valor { font-size: 1.5rem; }

  /* Toast en parte inferior centrado */
  #toast-container { left: 1rem; right: 1rem; bottom: 1rem; }

  /* Formulario auditor más cómodo en touch */
  .escala-btn { min-width: 40px; height: 40px; font-size: .9rem; }
  .star-btn { font-size: 2rem; }
  .pregunta-item { padding: .85rem; }

  /* Modal fullscreen en mobile */
  .modal-dialog { margin: 0; max-width: 100%; }
  .modal-content { border-radius: 0; min-height: 100vh; }
  .modal-dialog-scrollable .modal-content { max-height: 100vh; }
}

@media (max-width: 480px) {
  .main-content { padding: .75rem; padding-top: calc(var(--topbar-h) + .5rem); }
  h4.fw-bold { font-size: 1.1rem; }
}

/* ── Impresión ───────────────────────────────────────────────── */
@media print {
  /* Ocultar elementos de navegación */
  #sidebar, #topbar-mobile, #sidebar-overlay,
  .barra-acciones, .filtros-bar, .dash-tabs,
  .btn, .btn-group, #toast-container,
  .modal-backdrop, nav, footer,
  .dash-panel:not(.active),
  .no-print { display: none !important; }

  /* Main ocupa todo el ancho */
  .app-wrapper { display: block !important; }
  .main-content { padding: 0 !important; margin: 0 !important; width: 100% !important; }

  /* Modal expande a pantalla completa al imprimir */
  .modal { display: block !important; position: fixed !important;
    top: 0 !important; left: 0 !important; width: 100% !important;
    height: auto !important; overflow: visible !important; z-index: 9999 !important; }
  .modal-dialog { max-width: 100% !important; margin: 0 !important; width: 100% !important; }
  .modal-content { border: none !important; box-shadow: none !important;
    min-height: auto !important; border-radius: 0 !important; }
  .modal-header .btn-close { display: none !important; }
  .modal-footer .btn-outline-secondary { display: none !important; }
  .modal-body { overflow: visible !important; max-height: none !important; }

  /* Cuando hay modal abierto, ocultar el fondo */
  body.modal-open .app-wrapper { display: none !important; }
  body.modal-open .modal-backdrop { display: none !important; }

  /* Evitar cortes en cards */
  .card, .metric-card, .tienda-card {
    break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #dee2e6 !important;
  }

  /* Colores visibles en impresión */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  body { overflow: visible !important; }
  @page { margin: 1.5cm; size: A4; }
}
