/**
 * Portal adaptive layer — phone and tablet.
 *
 * Loaded after catppuccin-latte.css. Named PDS bands live on :root there;
 * custom properties cannot be interpolated into @media, so the operative
 * pixels are repeated here: mobile is max-width 767px (--pds-bp-lg minus 1).
 *
 * Scope:
 *   - staff bottom nav + more sheet
 *   - table-to-card for labeled data tables (never queue/week-grid)
 *   - bottom sheets for mobile-menu and confirm/modals
 *   - 48px comfortable touch (--pds-touch-comfortable) on mobile chrome
 *
 * Queue `.cw-table` and schedule `.week-grid` keep horizontal scroll.
 */

/* ===== BOTTOM NAV (staff + patient) ===== */
.staff-bottom-nav {
  display: none;
}

.adaptive-sheet-backdrop {
  display: none;
}

.adaptive-sheet-handle {
  display: none;
}

.adaptive-sheet-close {
  display: none;
}

@media (max-width: 767px) {
  .staff-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    align-items: stretch;
    justify-content: space-around;
    gap: 0.25rem;
    min-height: var(--pds-touch-comfortable);
    padding: 0.25rem 0.25rem calc(0.25rem + env(safe-area-inset-bottom, 0px));
    background: var(--surface-primary);
    border-top: 1px solid var(--border-primary);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }

  .staff-bottom-nav__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-height: var(--pds-touch-comfortable);
    min-width: var(--pds-touch-comfortable);
    padding: 0.25rem 0.125rem;
    border: 0;
    background: transparent;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: 0.6875rem;
    font-weight: var(--weight-medium);
    text-decoration: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .staff-bottom-nav__item svg,
  .staff-bottom-nav__item i {
    width: 22px;
    height: 22px;
  }

  .staff-bottom-nav__item.active,
  .staff-bottom-nav__item[aria-current="page"] {
    color: var(--color-primary);
    background: var(--color-primary-light);
  }

  .staff-bottom-nav__item:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  body:has(.staff-bottom-nav) .mobile-menu-toggle {
    display: none;
  }

  body:has(.staff-bottom-nav) .main,
  body:has(.staff-bottom-nav) .footer {
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }

  /* Pages with a floating action bar (tasks detail, form fill) keep extra
     content padding so the raised bar never covers the last block. */
  body:has(.floating-actions) .main {
    padding-bottom: calc(8.5rem + env(safe-area-inset-bottom, 0px));
  }

  .patient-mobile-nav a {
    min-height: var(--pds-touch-comfortable);
    min-width: var(--pds-touch-comfortable);
  }

  .patient-main {
    padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* ===== BOTTOM SHEETS (mobile-menu + confirm + generic modals) ===== */
@media (max-width: 767px) {
  .mobile-menu {
    display: block;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transform: none;
    pointer-events: none;
  }

  .mobile-menu.active {
    pointer-events: auto;
  }

  .adaptive-sheet-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    border: 0;
    padding: 0;
    margin: 0;
    background: rgba(17, 17, 27, 0.45);
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-smooth);
  }

  .mobile-menu.active .adaptive-sheet-backdrop {
    opacity: 1;
  }

  .adaptive-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    overflow: auto;
    background: var(--surface-primary);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
    padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translateY(110%);
    transition: transform var(--duration-normal) var(--ease-smooth);
  }

  .mobile-menu.active .adaptive-sheet-panel {
    transform: translateY(0);
  }

  .adaptive-sheet-handle {
    display: block;
    width: 36px;
    height: 4px;
    margin: 0.5rem auto 0.75rem;
    border-radius: 999px;
    background: var(--border-secondary);
  }

  .adaptive-sheet-close {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--pds-touch-comfortable);
    min-width: var(--pds-touch-comfortable);
    margin-left: auto;
    margin-bottom: 0.5rem;
    padding: 0 0.75rem;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    background: var(--surface-secondary);
    color: var(--text-primary);
    font: inherit;
    cursor: pointer;
  }

  .mobile-menu .nav-link {
    min-height: var(--pds-touch-comfortable);
    display: flex;
    align-items: center;
  }

  .confirm-modal-overlay {
    align-items: flex-end !important;
  }

  .confirm-modal {
    width: 100% !important;
    max-width: none !important;
    border-radius: 16px 16px 0 0 !important;
  }

  .confirm-modal-btn {
    min-height: var(--pds-touch-comfortable);
    min-width: var(--pds-touch-comfortable);
  }

  .modal-overlay {
    align-items: flex-end;
  }

  .modal-overlay .modal-content,
  .modal-content {
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
  }
}

/* ===== TABLE CARDS ===== */
@media (max-width: 767px) {
  table.adaptive-cards {
    display: block;
    width: 100%;
    border: 0;
  }

  table.adaptive-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  table.adaptive-cards tbody,
  table.adaptive-cards tr {
    display: block;
    width: 100%;
  }

  table.adaptive-cards tr {
    background: var(--surface-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--shadow-xs, 0 1px 2px rgba(0, 0, 0, 0.04));
  }

  table.adaptive-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    min-height: var(--pds-touch-comfortable);
    padding: 0.375rem 0;
    border: 0;
    text-align: right;
  }

  table.adaptive-cards td::before {
    content: attr(data-label);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    text-align: left;
    flex: 0 1 42%;
  }

  table.adaptive-cards td:empty {
    display: none;
  }

  /* Queue and week-grid keep a real table + overflow-x: auto. */
  .cw-table-container,
  .week-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== 48px TOUCH FLOOR (mobile chrome, not dense desktop tables) ===== */
@media (max-width: 767px) {
  .btn,
  .btn-sm,
  .btn-primary,
  .btn-secondary,
  .filter-btn,
  .filter-chip,
  .documents-filter-chip,
  .mobile-menu-toggle,
  a.nav-link,
  button.nav-link,
  .task-notification,
  input[type="submit"],
  input[type="button"],
  input[type="reset"] {
    min-height: var(--pds-touch-comfortable);
    min-width: var(--pds-touch-comfortable);
  }

  .header {
    height: 64px;
  }

  .header-content {
    gap: 0.5rem;
    min-width: 0;
  }

  .header-brand {
    min-width: 0;
  }

  .header-brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(42vw, 12rem);
  }

  .login-container {
    width: 100%;
    max-width: 100%;
    margin: 1.5rem auto;
    padding: 0;
  }

  .login-card {
    max-width: 100%;
    padding: 1.25rem;
    box-sizing: border-box;
  }

  .login-card .form-input,
  .login-card .btn {
    max-width: 100%;
    box-sizing: border-box;
  }
}
