/* ============================================================
   RESPONSIVE & AUTO-WRAP — All breakpoints + zoom handling
   Covers browser zoom from 75% to 200% and screen widths
   ============================================================ */

/* ---- HAMBURGER BUTTON ---- */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: var(--bg-card-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-fast);
  padding: 0;
}

.hamburger-btn:hover {
  border-color: var(--brand-primary);
  background: var(--bg-hover);
}

.hamburger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: var(--transition-fast);
  transform-origin: center;
}

/* Animated X when open */
.hamburger-btn.is-active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.is-active span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger-btn.is-active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---- SIDEBAR OVERLAY BACKDROP ---- */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 299;
  backdrop-filter: blur(2px);
  transition: opacity 0.25s ease;
  opacity: 0;
}

#sidebar-overlay.sidebar-overlay-active {
  display: block;
  opacity: 1;
}

/* ============================================================
   BREAKPOINT: ≤ 1280px  (125–150% browser zoom on 1920px)
   Sidebar narrows, content wraps more aggressively
   ============================================================ */
@media (max-width: 1280px) {
  :root { --sidebar-width: 220px; }

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

  .doctor-stats-row { flex-wrap: wrap; }
  .doctor-stat      { flex: 1 1 calc(33.33% - 1px); min-width: 100px; }

  .filters-bar { flex-wrap: wrap; gap: var(--space-sm); }
  .filter-chip, .filter-select { flex-shrink: 0; }

  .page-header { flex-wrap: wrap; gap: var(--space-sm); }
  .page-header-left { min-width: 0; }
}

/* ============================================================
   BREAKPOINT: ≤ 1100px  (150–175% zoom / tablets)
   Sidebar collapses off-screen; hamburger appears
   ============================================================ */
@media (max-width: 1100px) {
  /* Show hamburger */
  .hamburger-btn { display: flex !important; }

  /* Sidebar slides off screen */
  #sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-width) - 10px);
    top: 0;
    height: 100vh;
    z-index: 300;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }

  #sidebar.sidebar-open {
    left: 0;
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
  }

  /* Main content takes full width */
  #main-content { margin-left: 0 !important; width: 100%; }

  /* KPIs → 2 columns */
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Tables scroll horizontally */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }

  /* Doctor profile header stacks */
  .doctor-profile-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: var(--space-md);
  }

  .doctor-stats-row { flex-wrap: wrap; }
  .doctor-stat { flex: 1 1 calc(50% - 1px); }

  /* Tabs scroll horizontally */
  .tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .tab  { white-space: nowrap; flex-shrink: 0; }
}

/* ============================================================
   BREAKPOINT: ≤ 900px  (175–200% zoom / small tablets)
   Full single-column layout
   ============================================================ */
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; }

  .page { padding: var(--space-md) !important; }

  .doctor-stats-row { flex-direction: column; }
  .doctor-stat { border-right: none !important; border-bottom: 1px solid var(--border-subtle); }
  .doctor-stat:last-child { border-bottom: none; }

  /* Search bar full width */
  .search-input-big { font-size: 14px; }
  .search-input-wrapper { flex-wrap: wrap; gap: var(--space-sm); }
  .search-input-wrapper .btn { width: 100%; }

  /* Filters wrap fully */
  .filters-bar { gap: var(--space-xs); }
  .filter-select { font-size: 12px; padding: 6px 8px; }

  /* Modal fits screen */
  .modal { max-width: calc(100vw - 32px) !important; margin: var(--space-md); }
  .modal-body { max-height: 60vh; overflow-y: auto; }
}

/* ============================================================
   BREAKPOINT: ≤ 640px  (phone / extreme zoom)
   Minimal single-column, hide non-essential table columns
   ============================================================ */
@media (max-width: 640px) {
  :root { --topbar-height: 56px; }

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

  .topbar-scope { display: none; }

  /* Activity table: hide less critical columns */
  #activity-table th:nth-child(4),
  #activity-table td:nth-child(4),
  #activity-table th:nth-child(5),
  #activity-table td:nth-child(5),
  #activity-table th:nth-child(7),
  #activity-table td:nth-child(7) { display: none; }

  /* Doctor directory table: hide city/zone detail */
  .doctor-stat { flex: 1 1 100%; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn { width: 100%; }

  .timeline-card { padding: var(--space-sm); }
  .timeline-month-label { position: static; }

  h1 { font-size: 20px !important; }
  h2 { font-size: 18px !important; }
}

/* ============================================================
   TABLE RESPONSIVE — Always allow horizontal scroll
   ============================================================ */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrapper::-webkit-scrollbar { height: 4px; }
.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

/* ============================================================
   FILTER BAR — Always wraps cleanly
   ============================================================ */
.filters-bar {
  flex-wrap: wrap;
  align-items: center;
}

/* ============================================================
   AUTOCOMPLETE — Never overflow viewport
   ============================================================ */
.autocomplete-dropdown {
  max-height: min(400px, 50vh);
  overflow-y: auto;
}

/* ============================================================
   DOCTOR PROFILE STATS — Always wrappable
   ============================================================ */
.doctor-stats-row { flex-wrap: wrap; }

/* ============================================================
   LIGHT MODE overrides for new elements
   ============================================================ */
[data-theme="light"] .hamburger-btn {
  background: #ffffff;
  border-color: rgba(121, 36, 194, 0.15);
}

[data-theme="light"] .hamburger-btn span {
  background: #1e1441;
}

[data-theme="light"] #sidebar-overlay {
  background: rgba(30, 20, 65, 0.4);
}
