/* ==========================================================================
   SMR ADMIN — PIXEL-ACCURATE RESPONSIVE MOBILE & iOS PWA STYLESHEET
   Sửa triệt để lỗi hiển thị góc nhỏ trên mobile và bảo vệ 100% giao diện desktop.
   Hỗ trợ hoàn hảo: 320px, 360px, 375px, 390px, 402px, 430px, 768px, 1024px, 1440px.
   ========================================================================== */

/* Universal Mobile Resets & Safeguards */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
  width: 100% !important;
  -webkit-text-size-adjust: 100%;
}

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

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* Safe area insets for iPhone (Notch & Dynamic Island & Home Bar) */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Mobile Hamburger Toggle Button (Hidden on Desktop) */
.mobile-menu-toggle {
  display: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.mobile-menu-toggle:active {
  transform: scale(0.95);
  background: rgba(6, 182, 212, 0.2);
}

/* Mobile Drawer Close Button (Inside Sidebar, Hidden on Desktop) */
.sidebar-close-btn {
  display: none;
}

/* Backdrop for Sidebar Drawer */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* Bottom Navigation Bar on Mobile */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(17, 24, 39, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  z-index: 900;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.6);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  gap: 3px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 10px;
  transition: all 0.2s ease;
  min-width: 55px;
}
.bottom-nav-item i {
  font-size: 1.15rem;
  transition: transform 0.2s ease;
}
.bottom-nav-item.active {
  color: var(--accent);
}
.bottom-nav-item.active i {
  transform: translateY(-2px);
}
.bottom-nav-item:active {
  transform: scale(0.92);
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT: MOBILE & TABLET PORTRAIT (<= 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  .mobile-menu-toggle {
    display: inline-flex;
  }

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

  .sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1.1rem;
    cursor: pointer;
    margin-left: auto;
    transition: all 0.2s ease;
  }
  .sidebar-close-btn:active {
    background: rgba(239, 68, 68, 0.25);
    color: #ef4444;
  }

  /* Sidebar chuyển thành Drawer trượt */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: none !important;
    z-index: 1000 !important;
    width: 290px !important;
    max-width: 85vw !important;
    padding-top: max(16px, var(--safe-top)) !important;
    padding-bottom: max(16px, var(--safe-bottom)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 10px 0 40px rgba(0, 0, 0, 0.85) !important;
  }

  /* Wrapper toàn bộ app chiếm 100% màn hình, không bị trừ 260px */
  #admin-app-wrapper {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-x: hidden !important;
  }

  /* Main Viewport co giãn 100% tự nhiên - KHẮC PHỤC TRIỆT ĐỂ LỖI 130px GÓC NHỎ */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    flex: 1 1 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    padding-bottom: calc(75px + var(--safe-bottom)) !important;
    padding-left: max(12px, var(--safe-left)) !important;
    padding-right: max(12px, var(--safe-right)) !important;
  }

  .content-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 12px 0 !important;
    box-sizing: border-box !important;
  }

  .tab-section {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  /* Topbar header thích ứng mobile */
  .topbar {
    padding-top: max(10px, var(--safe-top)) !important;
    padding-bottom: 10px !important;
    padding-left: max(12px, var(--safe-left)) !important;
    padding-right: max(12px, var(--safe-right)) !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
    min-height: auto !important;
  }

  .topbar-header-row {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .topbar-header-row .page-title {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .topbar-header-row .page-title h1 {
    font-size: 1.15rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .topbar-header-row .page-title p {
    font-size: 0.72rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .topbar-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
    min-width: 0 !important;
    justify-content: flex-start !important;
  }

  .topbar-actions .btn {
    font-size: 0.74rem !important;
    padding: 6px 10px !important;
  }

  /* Bảng chỉ cuộn ngang trong vùng bảng khi cần */
  .table-responsive {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border-radius: 10px;
    margin-bottom: 16px;
  }

  .admin-table, .data-table {
    width: 100% !important;
    min-width: 600px;
  }

  .admin-table th, .admin-table td {
    white-space: nowrap;
    padding: 10px 12px;
  }

  /* Modals mobile */
  .modal-box,
  div[id^="modal-"] > div {
    width: 95% !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    padding: 18px 14px !important;
    box-sizing: border-box !important;
  }

  div[id^="modal-"],
  .modal-overlay {
    padding: 12px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  #admin-login-overlay {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 14px !important;
  }

  #admin-login-overlay > div {
    width: 100% !important;
    max-width: 440px !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    padding: 24px 18px !important;
  }

  .btn {
    min-height: 40px;
  }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT: SMARTPHONES & MOBILE PHONES (<= 768px)
   ========================================================================== */
@media (max-width: 768px) {
  /* Tự động chuyển cột các Card & Grid */
  div[style*="grid-template-columns: repeat(auto-fit, minmax(340px"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(320px"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(280px"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(260px"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(240px"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(220px"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: 110px 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Announcement studio layout */
  .announcement-studio-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .mockup-outer {
    position: static !important;
    max-width: 100% !important;
    margin-top: 14px !important;
  }

  /* Audio player cards stack */
  .audio-item-grid {
    grid-template-columns: 1fr !important;
  }

  /* Search & Toolbar rows wrap naturally */
  .tab-section > div[style*="display: flex"],
  .panel-card > div[style*="display: flex"],
  div[style*="display: flex; gap:"] {
    flex-wrap: wrap !important;
  }

  #inp-search-users,
  #inp-search-audit,
  #inp-search-schools,
  #inp-search-email,
  #inp-search-rides {
    min-width: 0 !important;
    flex: 1 1 100% !important;
    max-width: 100% !important;
  }

  /* Button flex wrap in topbar */
  .topbar-actions .btn {
    flex: 1 1 calc(50% - 6px) !important;
    justify-content: center !important;
    text-align: center !important;
    min-height: 38px !important;
    font-size: 0.72rem !important;
  }

  .status-badge {
    width: 100% !important;
    justify-content: center !important;
    font-size: 0.75rem !important;
  }

  /* Chống iOS Safari tự phóng to khi tap ô nhập liệu */
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT: COMPACT PHONES (<= 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .topbar-actions .btn {
    flex: 1 1 calc(50% - 6px) !important;
    font-size: 0.70rem !important;
    padding: 6px 6px !important;
  }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT: ULTRA-COMPACT (<= 360px - e.g. iPhone SE 1st gen)
   ========================================================================== */
@media (max-width: 360px) {
  .topbar-actions .btn {
    flex: 1 1 100% !important;
  }

  .mobile-bottom-nav .bottom-nav-item span {
    font-size: 0.60rem;
  }

  .mobile-bottom-nav .bottom-nav-item i {
    font-size: 1rem;
  }

  .page-title h1 {
    font-size: 1.02rem !important;
  }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT: TABLET SCREEN (768px - 1024px)
   ========================================================================== */
@media (min-width: 768px) and (max-width: 1024px) {
  .main-content {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
  .topbar-actions {
    width: auto !important;
  }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT: DESKTOP (>= 1025px) - BẢO VỆ 100% GIAO DIỆN GỐC
   ========================================================================== */
@media (min-width: 1025px) {
  .mobile-menu-toggle {
    display: none !important;
  }

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

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

  .sidebar-backdrop {
    display: none !important;
  }

  .sidebar {
    transform: none !important;
    position: fixed !important;
    width: 260px !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    z-index: 100 !important;
    box-shadow: none !important;
  }

  #admin-app-wrapper {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    min-height: 100vh !important;
  }

  .main-content {
    margin-left: 260px !important;
    width: calc(100% - 260px) !important;
    max-width: calc(100vw - 260px) !important;
    padding-bottom: 40px !important;
  }

  .topbar-header-row {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
  }
}
