/**
 * Responsive Navigation & Layout Patterns (Desktop, Tablet Rail & Mobile PWA)
 * Conforms to planning/05-GUIA-DISENO-UI-UX.md
 */

/* ─── Desktop Large (≥ 1440px): Centered with max-width ceiling ─── */
@media (min-width: 1440px) {
  .main-wrapper {
    max-width: var(--content-max-width);
    margin: 0 auto;
  }
}

/* ─── Desktop Standard (1025px – 1439px): Full Sidebar ─── */
@media (min-width: 1025px) {
  .app-sidebar {
    width: 260px;
    display: flex !important;
  }
  .mobile-top-header,
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* ─── Tablet (641px – 1024px): Rail Mode (68px, icon-only) ─── */
@media (min-width: 641px) and (max-width: 1024px) {
  .app-sidebar {
    width: 68px !important;
    display: flex !important;
  }
  
  .app-sidebar .brand-text,
  .app-sidebar .nav-label,
  .app-sidebar .nav-badge,
  .app-sidebar .user-meta-info,
  .app-sidebar .theme-label,
  .app-sidebar .status-text {
    display: none !important;
  }

  .sidebar-header {
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 12px 6px !important;
  }

  .sidebar-brand {
    justify-content: center !important;
  }

  .sidebar-nav {
    padding: 10px 6px !important;
    align-items: center !important;
  }

  .nav-item {
    justify-content: center !important;
    padding: 10px !important;
  }

  .mobile-top-header,
  .mobile-bottom-nav {
    display: none !important;
  }

  .desktop-grid-dashboard {
    grid-template-columns: 1fr !important;
  }

  .dashboard-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }
}

/* ─── Mobile (≤ 640px): Fixed Top Header + Bottom 5-Slot Bar ─── */
@media (max-width: 640px) {
  .app-sidebar {
    display: none !important;
  }

  .mobile-top-header {
    display: flex !important;
  }

  .mobile-bottom-nav {
    display: flex !important;
  }

  /* Native app feel for root viewport and navigation bars */
  html, body, .app-layout, .mobile-bottom-nav, .mobile-top-header {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  html::-webkit-scrollbar,
  body::-webkit-scrollbar,
  .mobile-bottom-nav::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  .main-wrapper {
    margin-left: 0 !important;
    padding-top: 56px !important;
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 20px)) !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    box-sizing: border-box !important;
  }

  .tab-content {
    padding: 12px 10px 48px !important;
    box-sizing: border-box !important;
  }

  .tab-container {
    gap: 12px !important;
    padding-bottom: 32px !important;
  }

  .dashboard-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .dashboard-kpi-grid .card-panel {
    padding: 12px 10px !important;
  }

  .dash-productivity-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .dash-metric-stat-box {
    padding: 12px 8px !important;
  }

  /* Modal notification */
  .notif-dropdown-panel {
    position: fixed !important;
    top: 56px !important;
    right: 8px !important;
    left: 8px !important;
    bottom: auto !important;
    width: auto !important;
    max-width: 440px !important;
    margin: 0 auto !important;
    max-height: 65vh !important;
  }

  #toastContainer {
    top: 56px !important;
    right: 10px !important;
    left: auto !important;
    bottom: auto !important;
    max-width: calc(100vw - 20px) !important;
  }
}

/* ─────────────────────────────────────────────────────────
   MOBILE TOP HEADER
   ───────────────────────────────────────────────────────── */
.mobile-top-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 990;
  height: 52px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 12px;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-sizing: border-box;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-brand-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-sidebar);
  letter-spacing: -0.02em;
}

.mobile-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-header-btn {
  position: relative;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--radius-xs);
  background: var(--bg-sidebar-item);
  border: 1px solid var(--border-sidebar-item);
  color: var(--text-sidebar);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
  padding: 0;
  box-sizing: border-box;
}

.mobile-header-btn svg {
  stroke: var(--text-sidebar);
  stroke-width: 2;
  width: 18px;
  height: 18px;
}

.mobile-header-btn:hover,
.mobile-header-btn:active {
  background: var(--bg-sidebar-item-hover);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.mobile-header-btn:hover svg,
.mobile-header-btn:active svg {
  stroke: var(--accent-gold);
}

.mobile-header-btn.active {
  background: rgba(201, 162, 39, 0.15) !important;
  border-color: var(--accent-gold) !important;
  color: var(--accent-gold) !important;
}

.mobile-header-btn.active svg {
  stroke: var(--accent-gold) !important;
}

.mobile-user-btn {
  padding: 0;
  overflow: visible;
  position: relative;
  background: transparent;
  border: none;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mobile-user-avatar-badge {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, var(--accent-gold-light) 0%, rgba(0, 0, 0, 0.4) 100%);
  color: var(--accent-gold);
  border: 1px solid var(--accent-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 13px;
  font-family: var(--font-sans);
  box-sizing: border-box;
}

.mobile-online-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: var(--status-emerald);
  border: 1.5px solid var(--bg-sidebar);
  border-radius: 50%;
}

.mobile-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 15px;
  height: 15px;
  background: var(--status-crimson);
  color: #ffffff;
  font-size: 8.5px;
  font-weight: 800;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  font-family: var(--font-mono);
}

/* ─────────────────────────────────────────────────────────
   MOBILE BOTTOM NAVIGATION BAR (5 Slots)
   ───────────────────────────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 990;
  height: 58px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  align-items: center;
  justify-content: space-around;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-sizing: border-box;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 2px;
  border-radius: var(--radius-xs);
  color: var(--text-sidebar-muted);
  transition: var(--transition-fast);
  position: relative;
  min-height: 44px;
}

.bottom-nav-item:active {
  background: var(--bg-sidebar-hover);
}

.bottom-nav-item.active {
  color: var(--accent-gold);
}

.bottom-nav-item.active .bottom-nav-icon svg {
  stroke: var(--accent-gold);
  filter: drop-shadow(0 0 4px rgba(201, 162, 39, 0.4));
}

.bottom-nav-item[data-tab="admin"] .bottom-nav-icon svg {
  stroke: var(--accent-gold);
}

.bottom-nav-item[data-tab="admin"].active {
  color: var(--accent-gold);
}

.bottom-nav-icon {
  position: relative;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: var(--transition-fast);
}

.bottom-nav-label {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
}

.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 2px;
  background: var(--accent-gold);
}

/* ─────────────────────────────────────────────────────────
   NOTIFICATION DROPDOWN PANEL
   ───────────────────────────────────────────────────────── */
.notif-dropdown-panel {
  position: fixed;
  left: 16px;
  top: 64px;
  bottom: auto;
  width: 330px;
  max-height: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: var(--transition-fast);
  transform-origin: top left;
  box-sizing: border-box;
}

.notif-dropdown-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.notif-dropdown-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

.notif-dropdown-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.notif-dropdown-title svg {
  stroke: var(--accent-gold);
}

.notif-dropdown-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.notif-dropdown-close:hover {
  color: var(--status-crimson);
}

.btn-notif-action {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

.btn-notif-action:hover {
  color: var(--accent-gold);
  border-color: var(--accent-gold);
  background: var(--bg-sidebar-hover);
}

.btn-notif-action.btn-notif-clear:hover {
  color: var(--status-crimson);
  border-color: var(--status-crimson);
  background: rgba(244, 63, 94, 0.1);
}

.notif-dropdown-list {
  padding: 6px 12px;
  overflow-y: auto;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.notif-item:last-child {
  border-bottom: none;
}

.notif-item-msg {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  word-break: break-word;
}

.notif-item-time {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.notif-dropdown-footer {
  padding: 6px 12px 8px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

/* Extra small mobile (≤ 375px) */
@media (max-width: 375px) {
  .mobile-brand-title {
    font-size: 13.5px;
  }
  .dashboard-kpi-grid .card-panel div[id^="dash"] {
    font-size: 16px !important;
  }
}

/* Ultra-narrow mobile (≤ 340px, e.g. Galaxy Z Fold outer screen ~280px) */
@media (max-width: 340px) {
  .mobile-top-header {
    padding: 0 6px !important;
    height: 48px !important;
  }

  .mobile-brand-title {
    font-size: 12px !important;
    letter-spacing: -0.02em !important;
  }

  .mobile-header-btn,
  .mobile-user-btn,
  .mobile-user-avatar-badge {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
  }

  .mobile-header-actions {
    gap: 4px !important;
  }

  .bottom-nav-label {
    font-size: 8.5px !important;
    letter-spacing: -0.02em !important;
  }

  .bottom-nav-icon svg {
    width: 16px !important;
    height: 16px !important;
  }

  .bottom-nav-item {
    padding: 3px 1px !important;
    min-height: 40px !important;
  }

  .tab-content {
    padding: 8px 6px 40px !important;
  }
}

