/* ============================================================
   TEMAX WATCH CONTROL — MOBILE & TABLET RESPONSIVE SYSTEM
   Professional Responsive UI for Smart Watch Admin Dashboard
   Dual RTL/LTR Support, Touch Drawer & Mobile Components
   ============================================================ */

/* ── 1. SIDEBAR BACKDROP OVERLAY ── */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 16, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 990;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

body.sidebar-open .sidebar-backdrop,
.sidebar-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── 2. DESKTOP COLLAPSE BEHAVIOR (>= 992px) ── */
@media (min-width: 992px) {
  body.sidebar-collapsed [dir="rtl"] .main-content {
    margin-right: var(--sidebar-collapsed-w);
  }
  body.sidebar-collapsed [dir="ltr"] .main-content {
    margin-left: var(--sidebar-collapsed-w);
  }
}

/* ── 3. TABLET & MOBILE VIEW (<= 991px) ── */
@media (max-width: 991px) {
  /* Prevent horizontal page overflow */
  html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    position: relative;
  }

  /* Reset main content margins completely so content fills screen */
  [dir="rtl"] .main-content,
  [dir="ltr"] .main-content {
    margin-right: 0 !important;
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
  }

  /* SIDEBAR: Off-canvas slide-out drawer */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 300px !important;
    max-width: 86vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 1050 !important;
    background: rgba(8, 12, 23, 0.98) !important;
    backdrop-filter: blur(32px) !important;
    -webkit-backdrop-filter: blur(32px) !important;
    box-shadow: 0 0 65px rgba(0, 0, 0, 0.9) !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* RTL drawer: slides in from right */
  [dir="rtl"] .sidebar {
    right: 0 !important;
    left: auto !important;
    transform: translateX(105%) !important;
    border-left: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-right: none !important;
  }

  /* LTR drawer: slides in from left */
  [dir="ltr"] .sidebar {
    left: 0 !important;
    right: auto !important;
    transform: translateX(-105%) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-left: none !important;
  }

  /* Opened drawer state */
  body.sidebar-open .sidebar,
  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  /* Always show all labels, badges, sections, and profile in mobile drawer */
  .sidebar .nav-label {
    display: inline-block !important;
    font-size: 0.92rem !important;
  }
  .sidebar .nav-badge {
    display: inline-block !important;
  }
  .sidebar .nav-section-label {
    display: block !important;
    padding: 0.75rem 1.25rem 0.35rem !important;
    font-size: 0.72rem !important;
  }
  .sidebar .sidebar-logo-text {
    display: flex !important;
    flex-direction: column !important;
  }
  .sidebar .user-info {
    display: block !important;
  }
  .sidebar .nav-item {
    justify-content: flex-start !important;
    padding: 0.75rem 1.1rem !important;
    margin: 0.2rem 0.7rem !important;
    gap: 0.85rem !important;
  }
  .sidebar .nav-icon {
    margin: 0 !important;
    font-size: 1.2rem !important;
  }

  /* Close button inside mobile drawer */
  .sidebar-collapse-btn {
    width: 34px !important;
    height: 34px !important;
    border-radius: 9px !important;
    font-size: 1.25rem !important;
    background: rgba(255, 255, 255, 0.08) !important;
    color: #cbd5e1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
  }

  /* ── 4. TOPBAR ON MOBILE ── */
  .topbar {
    padding: 0 1rem !important;
    height: 60px !important;
    max-width: 100vw !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
  }
  .topbar-right,
  .topbar-left {
    gap: 0.6rem !important;
  }
  .topbar .btn-icon {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    font-size: 1.35rem !important;
    border-radius: 10px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    color: #fff !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    cursor: pointer !important;
  }
  .topbar .btn-icon:hover,
  .topbar .btn-icon:active {
    background: rgba(99, 102, 241, 0.25) !important;
    border-color: rgba(99, 102, 241, 0.5) !important;
  }
  .breadcrumb {
    font-size: 0.82rem !important;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .lang-toggle {
    padding: 3px !important;
    gap: 2px !important;
  }
  .lang-btn {
    padding: 0.3rem 0.55rem !important;
    font-size: 0.74rem !important;
    font-weight: 700 !important;
  }
  .topbar-clock {
    font-size: 0.85rem !important;
    font-weight: 700 !important;
  }

  /* ── 5. PAGES CONTAINER & HEADERS ── */
  .pages-container {
    padding: 1.15rem 0.95rem !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.95rem !important;
    margin-bottom: 1.25rem !important;
  }
  .page-title {
    font-size: 1.45rem !important;
  }
  .page-subtitle {
    font-size: 0.84rem !important;
    margin-top: 0.15rem !important;
  }
  .page-actions {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.55rem !important;
  }
  .page-actions > button,
  .page-actions > a {
    flex: 1 1 calc(50% - 0.55rem) !important;
    min-width: 130px !important;
    padding: 0.7rem 0.9rem !important;
    font-size: 0.86rem !important;
    justify-content: center !important;
  }

  /* ── 6. KPI GRIDS ── */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.85rem !important;
    margin-bottom: 1.25rem !important;
  }
  .kpi-card {
    padding: 1.05rem 0.95rem !important;
    gap: 0.85rem !important;
    border-radius: var(--radius-sm) !important;
  }
  .kpi-icon {
    width: 48px !important;
    height: 48px !important;
    font-size: 1.4rem !important;
    border-radius: 12px !important;
  }
  .kpi-value {
    font-size: 1.6rem !important;
  }
  .kpi-label {
    font-size: 0.8rem !important;
  }

  /* ── 7. CHARTS & DASHBOARD BOTTOM ── */
  .charts-row,
  .dashboard-bottom {
    grid-template-columns: 1fr !important;
    gap: 1.15rem !important;
  }
  .chart-card {
    padding: 1.15rem 1rem !important;
    overflow: hidden !important;
    border-radius: var(--radius-sm) !important;
  }
  .chart-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.5rem !important;
  }
  .chart-legend {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }

  /* ── 8. DATA TABLES ── */
  .table-card {
    border-radius: var(--radius-sm) !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }
  .table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: block !important;
  }
  .table-responsive table {
    min-width: 580px !important;
  }
  .card-header {
    padding: 0.95rem 1.1rem !important;
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }
  .table-footer {
    flex-direction: column !important;
    gap: 0.75rem !important;
    align-items: center !important;
    padding: 0.85rem 1.1rem !important;
  }

  /* ── 9. FILTERS & SEARCH ── */
  .filter-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.65rem !important;
    padding: 0.85rem !important;
  }
  .search-wrapper {
    width: 100% !important;
    min-width: 0 !important;
  }
  .filter-select {
    width: 100% !important;
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
  }

  /* ── 10. DEVICE MODELS, GALLERY & PLANS ── */
  .device-model-cards {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  .health-kpi-grid,
  .activity-kpis {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.85rem !important;
  }
  .watchface-gallery {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)) !important;
    gap: 0.85rem !important;
  }
  .fp-card {
    width: 100% !important;
    max-width: 100% !important;
  }
  .settings-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── 11. MODALS ON MOBILE (Sheet Style) ── */
  .modal-overlay {
    padding: 0.65rem !important;
    align-items: flex-end !important;
  }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh !important;
    border-radius: 20px 20px 10px 10px !important;
  }
  .modal-header {
    padding: 1.1rem 1.25rem !important;
  }
  .modal-body {
    padding: 1.1rem 1.25rem !important;
  }
  .modal-footer {
    padding: 0.95rem 1.25rem !important;
    flex-wrap: wrap !important;
  }
  .modal-footer button {
    flex: 1 !important;
    min-width: 120px !important;
  }

  /* ── 12. TOAST NOTIFICATIONS ── */
  .toast-container {
    left: 0.75rem !important;
    right: 0.75rem !important;
    top: 0.75rem !important;
  }
  .toast {
    min-width: 0 !important;
    width: 100% !important;
  }
}

/* ── 13. SMALL PHONES (<= 540px) ── */
@media (max-width: 540px) {
  .topbar {
    padding: 0 0.75rem !important;
    height: 56px !important;
  }
  .breadcrumb {
    display: none !important;
  }
  .topbar-clock {
    display: none !important;
  }
  .pages-container {
    padding: 0.85rem 0.65rem !important;
  }
  .page-title {
    font-size: 1.3rem !important;
  }
  .page-actions > button,
  .page-actions > a {
    flex: 1 1 100% !important;
    width: 100% !important;
  }

  .kpi-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
  .health-kpi-grid,
  .activity-kpis {
    grid-template-columns: 1fr !important;
  }
  .chart-stats {
    flex-direction: column !important;
    width: 100% !important;
  }
  .chart-stats .stat-pill {
    width: 100% !important;
    text-align: center !important;
  }
  .wf-model-tabs,
  .notif-type-tabs,
  .log-filter-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
    padding-bottom: 4px !important;
  }
  .detail-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 14. PUSH NOTIFICATIONS PAGE RESPONSIVENESS ── */
@media (max-width: 900px) {
  .notif-page {
    padding: 1rem 0.85rem 2rem !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  .notif-hero {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
    padding: 1.15rem 1rem !important;
  }
  .notif-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
  }
  .notif-grid {
    grid-template-columns: 1fr !important;
    gap: 1.15rem !important;
  }
  .notif-card {
    padding: 1.1rem !important;
  }
  .notif-target-cards {
    grid-template-columns: 1fr !important;
  }
  .notif-filter-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 4px !important;
  }
}

@media (max-width: 480px) {
  .notif-stats {
    grid-template-columns: 1fr !important;
  }
}
