/* ============================================================
   GYM MANAGEMENT SYSTEM — COMPLETE MOBILE-FIRST RESPONSIVE PWA SYSTEM (2026)
   Breakpoints:
     1. Small Mobile:   320px – 374px
     2. Standard Mobile: 375px – 430px
     3. Large Mobile:    431px – 767px
     4. Tablet:          768px – 1023px
     5. Laptop:          1024px – 1439px
     6. Large Desktop:   1440px and above
   ============================================================ */

/* ─── 1. SAFE AREA & ROOT ADAPTATIONS ───────────────────────── */
: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-nav-height: 60px;
}

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  box-sizing: border-box;
}

body {
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

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

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

/* ─── 2. UNIVERSAL TOUCH TARGETS & FORM ACCESSIBILITY ───────── */
button, 
.btn, 
.nav-item, 
.mobile-nav-link, 
.cat-chip, 
.dash-quick-btn,
.product-card,
select,
input[type="button"],
input[type="submit"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 38px;
}

/* Mobile inputs: 16px font-size prevents unwanted iOS auto-zoom */
@media (max-width: 768px) {
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  input[type="date"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Universal responsive form helper rows */
.form-row-2col {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.75rem;
}

.form-row-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .form-row-2col,
  .form-row-3col {
    grid-template-columns: 1fr !important;
  }
}

/* ─── 3. RESPONSIVE APP HEADER ───────────────────────────────── */
@media (max-width: 992px) {
  .header-clock-badge {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-header {
    height: auto !important;
    min-height: 56px !important;
    padding: 0 !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
  }

  .header-main-row {
    height: 56px !important;
  }

  .header-search-container.desktop-search {
    display: none !important;
  }

  .header-mobile-search-row {
    display: block !important;
  }

  .brand-logo-img {
    height: 30px !important;
  }

  .brand-gym-title, .brand-name {
    font-size: 0.95rem !important;
  }

  .brand-badge {
    display: none !important;
  }

  .header-mode-btn .mode-label {
    display: none !important;
  }

  .header-mode-btn {
    padding: 0 0.55rem !important;
    min-width: 38px;
    height: 38px;
    justify-content: center;
  }

  .user-info {
    display: none !important;
  }

  .header-logout-btn {
    display: none !important;
  }

  /* Dropdown menus responsive clamp */
  #headerNotifMenu,
  #systemStatusPanel,
  #headerUserMenu {
    position: fixed !important;
    top: 58px !important;
    right: 10px !important;
    left: 10px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: calc(100vw - 20px) !important;
    max-height: 75vh !important;
    border-radius: 14px !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25) !important;
    z-index: 9999 !important;
  }

  /* Content padding for bottom navigation bar */
  .app-main {
    padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 1.25rem) !important;
  }
}

/* ─── 4. MOBILE SIDEBAR DRAWER ───────────────────────────────── */
@media (max-width: 768px) {
  .app-sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: -290px !important;
    width: 280px !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: var(--bg-surface, #FFFFFF) !important;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.2) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    display: block !important;
  }

  .app-sidebar.open {
    transform: translateX(290px) !important;
  }

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

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9990;
    animation: fadeInBackdrop 0.2s ease;
  }

  .sidebar-backdrop.visible {
    display: block !important;
  }

  @keyframes fadeInBackdrop {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  .sidebar-nav .nav-item {
    min-height: 46px !important;
    font-size: 0.92rem !important;
    padding: 0.75rem 1rem !important;
  }
}

/* ─── 5. MOBILE BOTTOM NAVIGATION ────────────────────────────── */
@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: block !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9900 !important;
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-top: 1px solid var(--border-color, #E2E8F0) !important;
    padding-bottom: var(--safe-bottom) !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08) !important;
  }

  .mobile-nav-items {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    height: var(--mobile-nav-height) !important;
    align-items: center !important;
    justify-items: center !important;
  }

  .mobile-nav-link {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 44px !important;
    color: #64748B !important;
    text-decoration: none !important;
    font-size: 0.68rem !important;
    font-weight: 700 !important;
    transition: color 0.15s ease !important;
  }

  .mobile-nav-link.active {
    color: var(--primary, #2563EB) !important;
  }

  .mobile-nav-link .nav-svg-icon {
    width: 22px !important;
    height: 22px !important;
    margin-bottom: 2px !important;
  }
}

/* ─── 6. MOBILE-FIRST POS & BILLING SYSTEM ───────────────────── */
@media (max-width: 1024px) {
  .pos-container {
    flex-direction: column !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .pos-main-zone {
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  .pos-search-bar {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    padding: 0.65rem 0.85rem !important;
  }

  .pos-member-search {
    flex: 1 1 100% !important;
    min-width: 100% !important;
  }

  .pos-catalog-filter-wrap {
    flex: 1 1 calc(50% - 0.25rem) !important;
    min-width: 140px !important;
  }

  .pos-btn-scan,
  .pos-btn-new-member {
    flex: 0 0 auto !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.82rem !important;
    height: 38px !important;
  }

  /* Horizontal scrolling categories chip bar */
  .pos-categories {
    overflow-x: auto !important;
    white-space: nowrap !important;
    padding: 0.5rem 0.85rem !important;
    -webkit-overflow-scrolling: touch;
    gap: 0.4rem !important;
    scrollbar-width: none;
  }

  .pos-categories::-webkit-scrollbar {
    display: none;
  }

  .cat-chip {
    padding: 0.45rem 0.85rem !important;
    font-size: 0.82rem !important;
    min-height: 36px !important;
  }

  /* Catalog Grid in responsive columns */
  .pos-product-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 0.65rem !important;
    padding: 0.75rem 0.85rem !important;
  }

  .product-card {
    min-height: 120px !important;
    padding: 0.75rem !important;
  }

  .product-name {
    font-size: 0.85rem !important;
  }

  .product-price {
    font-size: 0.95rem !important;
  }

  /* Mobile Cart Sidebar Transforms to Full-Width Section */
  .pos-cart-zone {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    border-left: none !important;
    border-top: 2px solid var(--border-color, #E2E8F0) !important;
    margin-top: 1rem !important;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05) !important;
  }

  .cart-summary-footer {
    padding: 0.85rem !important;
  }

  .deal-discount-card {
    margin-bottom: 0.65rem !important;
  }

  .pay-now-btn {
    height: 52px !important;
    font-size: 1.05rem !important;
  }

  /* Hide fixed desktop keyboard shortcuts on mobile touchscreens */
  .pos-keyboard-shortcuts {
    display: none !important;
  }

  /* Mobile Sticky Floating Cart Dock */
  .pos-mobile-cart-dock {
    position: fixed !important;
    bottom: calc(var(--mobile-nav-height, 60px) + var(--safe-bottom, 0px) + 8px) !important;
    left: 12px !important;
    right: 12px !important;
    max-width: 440px !important;
    margin: 0 auto !important;
    z-index: 9800 !important;
    background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%) !important;
    color: #FFFFFF !important;
    border: 1px solid rgba(245, 158, 11, 0.4) !important;
    border-radius: 14px !important;
    padding: 0.75rem 1rem !important;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35) !important;
    align-items: center !important;
    justify-content: space-between !important;
    cursor: pointer !important;
  }
}

/* ─── 7. SPECIFIC BREAKPOINT ENHANCEMENTS ────────────────────── */

/* A. Small Mobile (320px – 374px) */
@media (min-width: 320px) and (max-width: 374px) {
  body {
    font-size: 13.5px !important;
  }

  .page-content {
    padding: 0.65rem !important;
  }

  .pos-product-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.4rem !important;
    padding: 0.4rem !important;
  }

  .product-card {
    padding: 0.5rem !important;
    min-height: 110px !important;
  }

  .product-name {
    font-size: 0.78rem !important;
  }

  .product-price {
    font-size: 0.85rem !important;
  }

  .dash-quick-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.45rem !important;
  }

  .qk-title {
    font-size: 0.75rem !important;
  }

  .kpi-card {
    padding: 0.85rem !important;
  }

  .kpi-card-value {
    font-size: 1.35rem !important;
  }

  .payment-method-selector {
    grid-template-columns: 1fr 1fr !important;
  }

  .payment-status-selector {
    grid-template-columns: 1fr !important;
    gap: 0.4rem !important;
  }
}

/* B. Standard Mobile (375px – 430px) */
@media (min-width: 375px) and (max-width: 430px) {
  .page-content {
    padding: 0.75rem !important;
  }

  .pos-product-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .dash-quick-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }

  .payment-method-selector {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* C. Large Mobile (431px – 767px) */
@media (min-width: 431px) and (max-width: 767px) {
  .page-content {
    padding: 0.85rem !important;
  }

  .pos-product-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    gap: 0.65rem !important;
  }

  .dash-quick-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.65rem !important;
  }
}

/* D. Tablet (768px – 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .page-content {
    padding: 1.25rem !important;
  }

  .pos-product-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
    gap: 0.85rem !important;
  }

  .dash-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .dash-quick-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* E. Laptop (1024px – 1439px) */
@media (min-width: 1024px) and (max-width: 1439px) {
  .pos-container {
    display: flex !important;
    height: calc(100vh - 60px) !important;
  }

  .pos-main-zone {
    flex: 1 !important;
    overflow-y: auto !important;
  }

  .pos-cart-zone {
    width: 380px !important;
    flex-shrink: 0 !important;
    height: 100% !important;
    overflow-y: auto !important;
  }

  .dash-kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* F. Large Desktop (1440px and above) */
@media (min-width: 1440px) {
  .pos-container {
    display: flex !important;
    height: calc(100vh - 60px) !important;
  }

  .pos-cart-zone {
    width: 420px !important;
    flex-shrink: 0 !important;
  }

  .dash-kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* ─── 8. UNIVERSAL RESPONSIVE TABLES & CONTAINERS ─────────────── */
.table-responsive,
.table-wrapper {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg, 14px);
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .table-responsive table,
  .table-wrapper table {
    min-width: 620px; /* guarantees readable tabular presentation with horizontal scroll */
  }

  .member-filter-group,
  #memberFilterGroup {
    overflow-x: auto !important;
    white-space: nowrap !important;
    width: 100% !important;
    padding-bottom: 0.4rem;
    -webkit-overflow-scrolling: touch;
  }

  .member-filter-chip {
    padding: 0.4rem 0.75rem !important;
    font-size: 0.78rem !important;
    min-height: 34px !important;
  }
}

/* ─── 9. RESPONSIVE MODAL SYSTEM ─────────────────────────────── */
@media (max-width: 768px) {
  .modal {
    padding: 0.5rem !important;
    align-items: flex-end !important; /* Slide-up bottom sheet feel on touch */
  }

  .modal .card,
  .modal-dialog,
  .payment-modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-top-left-radius: 20px !important;
    border-top-right-radius: 20px !important;
    margin: 0 !important;
    padding: 1.25rem 1rem !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .payment-modes-grid,
  .payment-method-selector {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .pay-mode-btn,
  .pm-chip {
    padding: 0.65rem 0.5rem !important;
    min-height: 48px !important;
  }

  .due-calc-grid {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }
}

/* ─── 10. CHARTS AND REPORTS CONTAINER RESPONSIVENESS ────────── */
.chart-container-responsive {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-height: 240px;
}

@media (max-width: 640px) {
  .chart-container-responsive {
    min-height: 200px;
  }
}

/* ─── 11. PWA INSTALL BANNER & OFFLINE TOAST ─────────────────── */
.pwa-install-banner {
  display: none;
  position: fixed;
  bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 12px);
  left: 12px;
  right: 12px;
  max-width: 440px;
  margin: 0 auto;
  z-index: 9998;
  background: #1E293B;
  color: #F8FAFC;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 0.85rem 1.15rem;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  animation: slideUpPwa 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 769px) {
  .pwa-install-banner {
    bottom: 24px;
    right: 24px;
    left: auto;
    width: 360px;
  }
}

.pwa-install-banner.visible {
  display: flex !important;
}

@keyframes slideUpPwa {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pwa-banner-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #2563EB;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.pwa-banner-content {
  flex: 1;
}

.pwa-banner-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: #FFFFFF;
}

.pwa-banner-desc {
  font-size: 0.72rem;
  color: #94A3B8;
  margin-top: 1px;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pwa-install-btn {
  background: #2563EB;
  color: #FFFFFF;
  border: none;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease;
}

.pwa-install-btn:active {
  background: #1D4ED8;
}

.pwa-dismiss-btn {
  background: transparent;
  color: #94A3B8;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.35rem;
  line-height: 1;
}

/* Offline Status Bar sticky enhancement */
#offlineStatusBar {
  position: sticky;
  top: 0;
  z-index: 9995;
  background: #DC2626;
  color: #FFFFFF;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 2px 10px rgba(220, 38, 38, 0.3);
}

#offlineStatusBar.visible {
  display: flex !important;
}

/* Online restored toast */
#onlineRestoredToast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #059669;
  color: #FFFFFF;
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  z-index: 9999;
  display: none;
  box-shadow: 0 4px 16px rgba(5, 150, 105, 0.4);
}
