/**
 * ATOQ Custom Styles v2 — Sidebar Layout
 * Extiende Bootstrap 5. Carga DESPUÉS de Bootstrap y at-branding.css.
 * NO modifica colores Bootstrap — solo forma, layout y tipografía.
 */

/* ============================================================
   1. RESET & BASE
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: #212529;
  background-color: #f4f5f7;
  margin: 0;
}

h1 { font-size: 22px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 18px; font-weight: 700; line-height: 1.2; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }
h5 { font-size: 13px; font-weight: 600; }
h6 { font-size: 12px; font-weight: 600; }

/* ============================================================
   2. LAYOUT — SIDEBAR + MAIN
   ============================================================ */

/* Wrapper que contiene todo */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 170px;
  min-height: 100vh;
  background-color: #0f0f0f;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.25s ease;
}

/* Scrollbar sidebar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* Logo / Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  text-decoration: none;
}

.sidebar-brand-logo {
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px 10px;
  align-items: center;
}

.sidebar-logo-img {
  width: 120px;
  height: auto;
  object-fit: contain;
}

.sidebar-logo-label {
  font-size: 9px;
  font-weight: 500;
  color: rgba(255,255,255,0.35);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-brand-icon {
  width: 34px;
  height: 34px;
  background: #e84317;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand-text {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.1;
}

.sidebar-brand-text small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: rgba(255,255,255,0.40);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Nav sections */
.sidebar-section {
  padding: 8px 10px 4px;
}

.sidebar-section-grow {
  flex: 1;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(255,255,255,0.30);
  padding: 0 6px;
  margin-bottom: 3px;
  display: block;
}

/* Nav item */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 7px;
  text-decoration: none;
  color: rgba(255,255,255,0.60);
  font-size: 11.5px;
  font-weight: 500;
  margin-bottom: 1px;
  transition: all 0.15s ease;
  position: relative;
  white-space: nowrap;
}

.sidebar-link i {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-link:hover {
  background-color: rgba(255,255,255,0.07);
  color: #fff;
}

.sidebar-link.active {
  background-color: rgba(232, 67, 23, 0.18);
  color: #e84317;
}

.sidebar-link.active i {
  color: #e84317;
}

/* ---- Nav colapsable ---- */

/* Botón padre (toggle) */
.sidebar-nav-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 7px;
  text-decoration: none;
  color: rgba(255,255,255,0.60);
  font-size: 11.5px;
  font-weight: 500;
  margin-bottom: 1px;
  transition: all 0.15s ease;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}

.sidebar-nav-toggle:hover {
  background-color: rgba(255,255,255,0.07);
  color: #fff;
}

.sidebar-nav-toggle.open {
  color: #fff;
  background-color: rgba(255,255,255,0.05);
}

/* Chevron que rota */
.sidebar-nav-toggle .sidebar-chevron {
  margin-left: auto;
  font-size: 11px;
  color: rgba(255,255,255,0.25);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.sidebar-nav-toggle.open .sidebar-chevron {
  transform: rotate(90deg);
  color: rgba(255,255,255,0.50);
}

/* Contador de alertas en el toggle padre */
.sidebar-nav-toggle .sidebar-badge {
  margin-left: auto;
  margin-right: 4px;
}

.sidebar-nav-toggle.open .sidebar-badge {
  margin-right: 4px;
}

/* Sub-ítems */
.sidebar-submenu {
  padding-left: 14px;
  margin-bottom: 2px;
}

.sidebar-sublink {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: rgba(255,255,255,0.50);
  font-size: 11px;
  font-weight: 400;
  margin-bottom: 1px;
  transition: all 0.12s ease;
  white-space: nowrap;
  border-left: 2px solid transparent;
}

.sidebar-sublink i {
  font-size: 13px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-sublink:hover {
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.05);
}

.sidebar-sublink.active {
  color: #e84317;
  border-left-color: #e84317;
  background: rgba(232,67,23,0.12);
  font-weight: 500;
}

/* Badge de alerta dentro del sidebar */
.sidebar-badge {
  margin-left: auto;
  background: #dc3545;
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* Divisor */
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 6px 10px;
}

/* Footer del sidebar — usuario */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e84317;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.sidebar-user-role {
  font-size: 10px;
  color: rgba(255,255,255,0.40);
  white-space: nowrap;
}

.sidebar-logout {
  color: rgba(255,255,255,0.35);
  font-size: 16px;
  text-decoration: none;
  transition: color 0.15s;
  flex-shrink: 0;
}

.sidebar-logout:hover {
  color: #dc3545;
}

/* ---- MAIN WRAPPER ---- */
.main-wrapper {
  margin-left: 170px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: calc(100vw - 170px);
  overflow-x: hidden;
}

/* ---- TOP HEADER ---- */
.top-header {
  height: 60px;
  background: #fff;
  border-bottom: 1px solid #eef0f3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.top-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-header-title {
  font-size: 16px;
  font-weight: 700;
  color: #212529;
  margin: 0;
}

.top-header-subtitle {
  font-size: 12px;
  color: #adb5bd;
  margin: 0;
  font-weight: 400;
}

.top-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.top-header-date {
  font-size: 12px;
  color: #6c757d;
  font-weight: 500;
}

/* Toggle sidebar en mobile */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: #6c757d;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}

/* ---- CONTENT AREA ---- */
.content-area {
  flex: 1;
  padding: 16px;
  overflow-x: hidden;
}

/* ============================================================
   3. CARDS
   ============================================================ */

.card {
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05), 0 2px 8px rgba(0,0,0,0.04);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid #f2f3f5;
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 12px 12px 0 0 !important;
}

.card-header.bg-primary {
  background: #0d6efd !important;
  border-bottom: none;
  color: #fff;
}

.card-body { padding: 20px; }

.card-footer {
  background: transparent;
  border-top: 1px solid #f2f3f5;
  padding: 14px 20px;
  border-radius: 0 0 12px 12px !important;
}

/* ---- Stat Cards (dashboard) ---- */
.stat-card {
  position: relative;
  overflow: hidden;
}

.stat-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-card-number {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  color: #1a1d21;
}

.stat-card-label {
  font-size: 12px;
  font-weight: 500;
  color: #6c757d;
  margin-top: 4px;
}

.stat-card-trend {
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 8px;
}

/* Cards de alerta operacional (grandes) */
.alert-card-number {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  margin: 8px 0 6px;
}

/* ============================================================
   4. BOTONES
   ============================================================ */

.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  padding: 8px 16px;
  letter-spacing: 0.1px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  border-width: 1px;
}

.btn-sm {
  border-radius: 6px;
  font-size: 12px;
  padding: 5px 12px;
}

.d-grid .btn {
  height: 42px;
  justify-content: center;
}

.btn-primary:hover   { box-shadow: 0 4px 14px rgba(13,110,253,0.30); transform: translateY(-1px); }
.btn-success:hover   { box-shadow: 0 4px 14px rgba(25,135,84,0.30);  transform: translateY(-1px); }
.btn-danger:hover    { box-shadow: 0 4px 14px rgba(220,53,69,0.30);  transform: translateY(-1px); }
.btn-warning:hover   { box-shadow: 0 4px 14px rgba(255,193,7,0.30);  transform: translateY(-1px); }
.btn-info:hover      { box-shadow: 0 4px 14px rgba(13,202,240,0.30); transform: translateY(-1px); }

.btn-primary:active,
.btn-success:active,
.btn-danger:active,
.btn-warning:active,
.btn-info:active { transform: translateY(0); }

.btn-outline-primary,
.btn-outline-success,
.btn-outline-danger,
.btn-outline-warning,
.btn-outline-info,
.btn-outline-secondary { border-width: 1.5px; }

/* ============================================================
   5. BADGES
   ============================================================ */

.badge {
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* Versiones suaves */
.badge-soft-warning  { background: #fff3cd; color: #856404; }
.badge-soft-info     { background: #cff4fc; color: #055160; }
.badge-soft-success  { background: #d1e7dd; color: #0a3622; }
.badge-soft-danger   { background: #f8d7da; color: #842029; }
.badge-soft-secondary{ background: #e2e3e5; color: #41464b; }
.badge-soft-dark     { background: #d3d3d4; color: #141619; }
.badge-soft-primary  { background: #cfe2ff; color: #084298; }

/* En tablas, convertir badges sólidos a suaves */
.table .badge.bg-warning   { background: #fff3cd !important; color: #856404 !important; }
.table .badge.bg-info      { background: #cff4fc !important; color: #055160 !important; }
.table .badge.bg-success   { background: #d1e7dd !important; color: #0a3622 !important; }
.table .badge.bg-danger    { background: #f8d7da !important; color: #842029 !important; }
.table .badge.bg-secondary { background: #e2e3e5 !important; color: #41464b !important; }
.table .badge.bg-primary   { background: #cfe2ff !important; color: #084298 !important; }
.table .badge.bg-dark      { background: #d3d3d4 !important; color: #141619 !important; }

/* ============================================================
   6. TABLAS
   ============================================================ */

.table { margin-bottom: 0; }

.table thead th {
  background: #f8f9fa;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6c757d;
  border-bottom: 2px solid #eef0f3;
  border-top: none;
  padding: 11px 16px;
  white-space: nowrap;
}

.table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid #f4f5f7;
  font-size: 13px;
  vertical-align: middle;
  color: #374151;
}

.table tbody tr:hover td { background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: none; }

/* Tasa de éxito */
.rate-high   { color: #198754; font-weight: 700; }
.rate-medium { color: #fd7e14; font-weight: 700; }
.rate-low    { color: #dc3545; font-weight: 700; }

/* ============================================================
   7. FORMULARIOS
   ============================================================ */

.form-control,
.form-select {
  border-radius: 8px;
  border: 1.5px solid #e2e5e9;
  padding: 8px 13px;
  font-size: 13px;
  background: #fff;
  color: #212529;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.form-select:focus {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13,110,253,0.12);
  outline: none;
}

.form-control.is-invalid { border-color: #dc3545; box-shadow: 0 0 0 3px rgba(220,53,69,0.12); }

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: #6c757d;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  display: block;
}

.form-text { font-size: 11px; color: #6c757d; margin-top: 4px; }

.input-group .form-control { border-right: none; }
.input-group .btn { border-radius: 0 8px 8px 0; }
.input-group-text {
  border: 1.5px solid #e2e5e9;
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: #f8f9fa;
  color: #6c757d;
  font-size: 14px;
}

/* ============================================================
   8. ALERTAS
   ============================================================ */

.alert {
  border-radius: 10px;
  border: none;
  padding: 14px 18px;
  font-size: 13px;
  border-left: 4px solid transparent;
}

.alert-info    { background: #eff6ff; color: #1e40af; border-left-color: #0dcaf0; }
.alert-success { background: #f0fdf4; color: #166534; border-left-color: #198754; }
.alert-warning { background: #fffbeb; color: #92400e; border-left-color: #ffc107; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-left-color: #dc3545; }

/* ============================================================
   9. PAGINACIÓN
   ============================================================ */

.pagination { gap: 4px; }

.page-link {
  border-radius: 8px !important;
  border: 1.5px solid #e2e5e9;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  color: #495057;
  transition: all 0.12s;
}

.page-link:hover  { background: #e9ecef; border-color: #dee2e6; color: #212529; }
.page-item.active .page-link { background: #0d6efd; border-color: #0d6efd; color: #fff; }
.page-item.disabled .page-link { opacity: 0.4; }

/* ============================================================
   10. OFFCANVAS
   ============================================================ */

.offcanvas { border-left: none; box-shadow: -8px 0 40px rgba(0,0,0,0.12); }
.offcanvas-header { padding: 18px 24px; border-bottom: 1px solid #f2f3f5; font-weight: 600; }
.offcanvas-body { padding: 0; }

/* ============================================================
   11. MENSAJES
   ============================================================ */

.messages-container {
  padding: 12px 16px 0;
}

/* ============================================================
   12. FOOTER
   ============================================================ */

.site-footer {
  background: transparent;
  padding: 16px 28px;
  font-size: 11px;
  color: #adb5bd;
  border-top: 1px solid #eef0f3;
  margin-top: auto;
  text-align: right;
}

/* ============================================================
   13. UTILIDADES
   ============================================================ */

code {
  background: #eff6ff;
  color: #0d6efd;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
}

.label-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9ca3af;
}

.form-check-input {
  border-radius: 4px;
  border: 1.5px solid #ced4da;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.form-check-input:checked { background-color: #0d6efd; border-color: #0d6efd; }

/* Mini stats en portal */
.stats-mini-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  border-left: 3px solid;
  transition: transform 0.15s;
}

.stats-mini-card:hover { transform: translateX(3px); }

/* Progress bar semanal */
.week-progress-track {
  height: 8px;
  border-radius: 8px;
  background: #e9ecef;
  overflow: hidden;
}

.week-progress-bar {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, #198754, #20c997);
  transition: width 0.8s ease;
}

/* ============================================================
   14. LOGIN MODE (sin sidebar)
   ============================================================ */

.main-wrapper.login-mode {
  margin-left: 0;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f4f5f7;
  width: 100%;
}

.main-wrapper.login-mode .content-area {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 16px;
  width: 100%;
}

/* ============================================================
   15. RESPONSIVE — SIDEBAR COLLAPSIBLE
   ============================================================ */

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-170px);
  }

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

  .main-wrapper {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: block;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1039;
  }

  .sidebar-overlay.active {
    display: block;
  }
}

@media (max-width: 575px) {
  .content-area { padding: 16px; }
  .top-header   { padding: 0 16px; }
  .stat-card-number { font-size: 24px; }
  .alert-card-number { font-size: 36px; }
}
