/* ── Tablet (≤900px) ───────────────────────────────────────────────– */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 200px;
  }

  .hdr-row2 {
    flex-wrap: wrap;
    overflow: visible;
  }

  .hdr-btn {
    flex-shrink: 0;
  }

  /* Icon-only row-1 buttons when space is tight (tooltips still available) */
  .user-badge .hdr-lbl {
    display: none;
  }
}

/* ── Mobile (≤640px) ───────────────────────────────────────────────– */
@media (max-width: 640px) {
  body {
    height: 100dvh;
  }

  #app {
    height: 100dvh;
  }

  /* Prevent iOS input auto-zoom (triggers when font-size < 16px) */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Auth card: fluid width */
  .auth-card {
    width: calc(100vw - 32px);
    padding: 26px 18px;
  }

  .auth-logo {
    font-size: 1.7rem;
  }

  /* Header row 1: scroll instead of clip when crowded */
  .hdr-row1 {
    height: 44px;
    padding: 0 8px;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .hdr-row1::-webkit-scrollbar {
    display: none;
  }

  #btn-toggle-sidebar {
    display: flex;
  }

  .logo {
    font-size: 0.9rem;
  }

  #user-email-lbl {
    display: none;
  }

  #month-label {
    min-width: 76px;
    font-size: 0.84rem;
  }

  .month-nav {
    padding: 3px 6px;
    gap: 3px;
  }

  .user-badge button {
    padding: 3px 8px;
    font-size: 0.75rem;
  }

  /* Header row 2: wrap into extra lines instead of horizontal scroll */
  .hdr-row2 {
    flex-wrap: wrap;
    overflow: visible;
    height: auto;
    min-height: 36px;
    padding: 3px 5px;
    gap: 3px;
  }

  /* Dropdowns: never wider than the viewport */
  .hdr-menu-list {
    max-width: calc(100vw - 20px);
  }

  .hdr-btn {
    font-size: 0.72rem;
    padding: 3px 7px;
    height: 25px;
    flex-shrink: 0;
  }

  .hdr-sep {
    height: 18px;
    flex-shrink: 0;
  }

  /* Sidebar: full-height slide-in drawer */
  aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 400;
    transform: translateX(-110%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    overflow-y: auto;
    display: flex !important;
  }

  aside.sidebar-open {
    transform: translateX(0);
  }

  .sidebar-mobile-hdr {
    display: flex;
  }

  /* Tabs */
  .tab {
    padding: 9px 12px;
    font-size: 0.82rem;
  }

  /* Modals: fit screen */
  .modal {
    max-width: calc(100vw - 20px) !important;
    padding: 18px 16px;
  }

  .modal-overlay {
    padding: 10px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .shift-row {
    gap: 4px;
    font-size: 0.78rem;
  }

  /* Summary */
  .summary-wrap {
    padding: 8px;
  }

  /* Keep Physician (first) column pinned while the 10-col table scrolls
     horizontally — parity with Schedule/Coverage td.sticky-col */
  table.summary th {
    z-index: 5;
  }

  table.summary th:first-child {
    position: sticky;
    left: 0;
    z-index: 7;
    background: var(--thead);
  }

  table.summary td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--surface);
  }

  table.summary tr:nth-child(even) td:first-child {
    background: var(--thead);
  }

  /* Status bar */
  .statusbar {
    font-size: 0.72rem;
    padding: 3px 10px;
  }

  /* Workspace switcher: cap width; badge is redundant with the select */
  #ws-select {
    max-width: 110px;
  }

  #ws-badge {
    display: none !important;
  }

  #btn-leave-ws {
    font-size: 0.68rem;
    padding: 3px 7px;
    height: 24px;
  }

  /* Touch devices have no hover — keep physician delete buttons visible */
  .doc-del {
    opacity: 1;
  }

  .doc-email-btn {
    opacity: 0.7;
  }

  /* Help: single column */
  #help-canvas dl.help-list {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  #help-canvas dl.help-list dd {
    margin: 0 0 8px;
  }

  /* Physician view: responsive */
  #physician-view .phys-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  #physician-view .phys-month {
    width: 100%;
  }

  #physician-view .phys-month select {
    width: 100%;
  }
}

/* Charts: single column on narrow screens. Kept top-level: nesting this inside
   the 640px block clamped it to 640px, while the shipped inline rule it
   replaces applied at 760px. */
@media (max-width: 760px) {
  #summary-charts {
    grid-template-columns: 1fr;
  }
}
