/**
 * Roscha Synergy - Hệ Thống Bố Cục Thích Ứng Đa Thiết Bị (Adaptive Layout System)
 * Phân vùng:
 * - Compact: < 640px (Mobile portrait & nhỏ)
 * - Medium:  640px - 1023px (Tablet & Mobile landscape)
 * - Wide:    >= 1024px (Laptop & Desktop màn rộng)
 */

:root {
  --shell-sidebar-width: 260px;
  --shell-header-height: 70px;
  --shell-bottom-nav-height: 60px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ==========================================================================
   1. RESET & AN TOÀN TRÀN NỘI DUNG (OVERFLOW & SAFE AREA)
   ========================================================================== */
html, body {
  min-height: 100%;
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* Giới hạn độ rộng tối đa cho màn hình cực lớn (Tránh kéo dãn vô tận trên 2K/4K) */
.content-area {
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* Khu vực quản trị Admin cho phép không gian rộng hơn */
#tab-admin.content-area,
.admin-workspace {
  max-width: 1800px;
}

/* ==========================================================================
   2. THANH ĐIỀU HƯỚNG ĐÁY DI ĐỘNG (MOBILE BOTTOM NAVIGATION)
   ========================================================================== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--shell-bottom-nav-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  background: rgba(10, 15, 29, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 1000;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 0;
  transition: all 0.2s ease;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item .mobile-nav-icon {
  font-size: 1.25rem;
  line-height: 1;
  margin-bottom: 3px;
  transition: transform 0.2s ease;
}

.mobile-nav-item .mobile-nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
  color: #00d2ff;
}

.mobile-nav-item.active .mobile-nav-icon {
  transform: scale(1.15);
}

/* Ẩn Bottom Nav ở chế độ khách chưa đăng nhập hoặc khi mở chế độ Admin */
body.auth-guest-mode .mobile-bottom-nav,
body.admin-mode-active .mobile-bottom-nav {
  display: none !important;
}

/* ==========================================================================
   3. BREAKPOINT: COMPACT (< 640PX - ĐIỆN THOẠI)
   ========================================================================== */
@media (max-width: 639px) {
  /* Hiển thị bottom navigation cho thành viên đã đăng nhập */
  body:not(.auth-guest-mode) .mobile-bottom-nav {
    display: grid;
  }

  /* Tạo khoảng trống ở đáy để thanh nav không che nội dung */
  body:not(.auth-guest-mode) .content-area {
    padding-bottom: calc(var(--shell-bottom-nav-height) + var(--safe-area-bottom) + 24px) !important;
  }

  /* Khắc phục lỗi Header Guest tràn ra ngoài màn hình 320px (UI-02) */
  .top-header {
    height: auto;
    min-height: 58px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-wrap: nowrap;
  }

  /* Thu gọn nút đăng nhập và đăng ký ở màn hình nhỏ */
  .btn-header-register {
    padding: 6px 10px !important;
    font-size: 0.72rem !important;
    height: 36px !important;
    white-space: nowrap;
  }

  #btn-header-login {
    padding: 6px 10px !important;
    font-size: 0.72rem !important;
    height: 36px !important;
  }

  .header-search {
    order: 3;
    width: 100%;
    margin: 4px 0 0 0 !important;
  }

  .header-search input {
    font-size: 0.8rem;
    height: 36px;
  }

  /* Đảm bảo sidebar mobile hiển thị mượt mà dạng drawer */
  .sidebar {
    width: min(85vw, 320px) !important;
  }

  /* Đảm bảo form và lưới nội dung co giãn tốt */
  .dash-card {
    padding: 16px 12px;
  }
}

/* ==========================================================================
   4. BREAKPOINT: MEDIUM (640PX - 1023PX - TABLET & LANDSCAPE)
   ========================================================================== */
@media (min-width: 640px) and (max-width: 1023px) {
  .mobile-bottom-nav {
    display: none;
  }

  .content-area {
    padding: 20px 16px;
  }

  .top-header {
    padding: 0 16px;
  }
}

/* ==========================================================================
   5. BREAKPOINT: WIDE (>= 1024PX - LAPTOP & DESKTOP)
   ========================================================================== */
@media (min-width: 1024px) {
  .mobile-bottom-nav {
    display: none !important;
  }

  .mobile-sidebar-toggle-btn {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--shell-sidebar-width);
    transform: translateX(0) !important;
    z-index: 100;
  }

  .main-wrapper {
    margin-left: var(--shell-sidebar-width);
    width: calc(100% - var(--shell-sidebar-width));
  }
}
