/* Mobile app shell: final responsive layer, loaded after all theme files. */
@media (max-width: 850px) {
  body { min-height: 100dvh; overscroll-behavior-y: none; }
  .main-content { padding: 0 16px calc(100px + env(safe-area-inset-bottom)); }
  .topbar { position: sticky; z-index: 25; top: 0; min-height: calc(68px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); gap: 8px; background: inherit; }
  .menu-toggle { order: 1; flex: none; }
  .experience-switcher { order: 2; flex: 1; min-width: 0; margin: 0; }
  .experience-switcher button { min-width: 0; padding: 0 8px; white-space: nowrap; }
  .experience-switcher .admin-toggle { display: none; }
  .topbar-actions, .dentist-topbar-actions { order: 3; margin: 0; }
  .topbar-actions :is(.location-pill,.appearance-toolbar-button,.icon-button), .dentist-topbar-actions :is(.workspace-status,.appearance-toolbar-button) { display: none; }
  .topbar-actions .avatar-button, .dentist-topbar-actions .avatar-button { display: inline-grid; width: 40px; height: 40px; }

  .mobile-nav { right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); left: max(10px, env(safe-area-inset-left)); display: none; min-height: 66px; padding: 5px; grid-template-columns: repeat(5, minmax(0, 1fr)) !important; border: 1px solid rgba(255,255,255,.85); border-radius: 22px; background: #fffdfd; box-shadow: 0 14px 34px rgba(60,16,22,.18), inset 0 1px 0 #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
  body[data-experience="public"] .public-mobile-nav, body[data-experience="dentist"] .dentist-mobile-nav, body[data-experience="admin"] .admin-mobile-nav { display: grid; }
  .mobile-nav .nav-item { min-width: 0; min-height: 54px; padding: 4px 2px; gap: 3px; border-radius: 16px; justify-content: center; }
  .mobile-nav .nav-item > span { width: auto; font-size: 18px; }
  .mobile-nav small { overflow: hidden; max-width: 100%; font-size: 9px; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-nav .nav-item.active { background: linear-gradient(135deg, rgba(224,0,0,.14), rgba(251,237,237,.92)); }

  .modal-backdrop { background: rgba(34,20,24,.38); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .modal-sheet { top: auto; right: 0; bottom: 0; width: 100%; height: auto; max-height: min(86dvh, 760px); padding: 62px 18px calc(22px + env(safe-area-inset-bottom)); border: 1px solid rgba(165,0,22,.13); border-bottom: 0; border-radius: 28px 28px 0 0; box-shadow: 0 -18px 46px rgba(48,14,20,.2); transform: translateY(110%); }
  .modal-sheet::before { position: absolute; top: 13px; left: calc(50% - 22px); width: 44px; height: 4px; border-radius: 99px; background: rgba(99,68,73,.25); content: ""; }
  .modal-sheet.open { transform: translateY(0); }
  .sheet-close { top: 18px; right: 18px; }
  .modal-actions { position: sticky; bottom: calc(-22px - env(safe-area-inset-bottom)); padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); background: inherit; }
  .modal-actions button { min-height: 47px; }

  body[data-theme="liquid"] .topbar { background: #343337; }
  body[data-theme="liquid"] .mobile-nav { border-color: rgba(255,255,255,.18); background: linear-gradient(160deg, #515057, #2b2a30 85%) !important; box-shadow: 0 14px 30px rgba(0,0,0,.34), inset 0 1px 0 rgba(255,255,255,.24) !important; }
  body[data-theme="liquid"] .mobile-nav .nav-item { color: #e7e1e7 !important; background: transparent !important; box-shadow: none !important; }
  body[data-theme="liquid"] .mobile-nav .nav-item.active { color: #fff !important; background: linear-gradient(135deg, #bb4a54, #5b545b) !important; box-shadow: inset 0 1px 0 rgba(255,255,255,.24), 0 5px 14px rgba(0,0,0,.22) !important; }
  body[data-theme="liquid"] .modal-sheet { border-color: rgba(255,255,255,.18); background: linear-gradient(145deg, #4f4e55, #29282e 80%) !important; }
  body[data-theme="liquid"] .modal-sheet::before { background: rgba(255,255,255,.35); }
}

@media (max-width: 390px) {
  .experience-switcher button { padding: 0 6px; font-size: 9px; }
  .main-content { padding-right: 13px; padding-left: 13px; }
  .mobile-nav { right: 8px; left: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .modal-sheet, .mobile-nav, .topbar { transition: none !important; }
}

/* Tablet app shell — keeps iPad and tablet layouts app-like without the phone
   bottom bar or expensive live blur effects. This layer intentionally comes
   after the phone styles so an iPad in portrait is treated as a tablet. */
@media (min-width: 700px) and (max-width: 1199px) {
  .app-shell {
    display: grid !important;
    grid-template-columns: 168px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    display: flex !important;
    width: auto;
    height: 100dvh;
    min-height: 100vh;
    padding: calc(20px + env(safe-area-inset-top)) 12px 18px;
    gap: 18px;
  }

  .brand-lockup { padding: 0 8px; }
  .brand-lockup img { width: 100%; max-width: 128px; }
  .side-nav { gap: 6px; }
  .side-nav .nav-item { min-height: 48px; padding: 9px 10px; gap: 9px; font-size: 11px; }
  .side-nav .nav-item > span { width: 19px; font-size: 18px; }

  /* The public, dentist and admin navigation trees are all present in the
     markup so roles can change instantly. At tablet sizes, never let a
     browser's intermediate layout show more than the active tree. */
  body[data-experience="public"] .public-side-nav,
  body[data-experience="dentist"] .dentist-side-nav,
  body[data-experience="admin"] .admin-side-nav { display: grid !important; }
  body[data-experience="public"] :is(.dentist-side-nav, .admin-side-nav),
  body[data-experience="dentist"] :is(.public-side-nav, .admin-side-nav),
  body[data-experience="admin"] :is(.public-side-nav, .dentist-side-nav) { display: none !important; }

  .sidebar-support { padding: 13px; }
  .sidebar-support strong { font-size: 13px; }
  .sidebar-footer { margin: 0 4px; font-size: 9px; }

  .main-content {
    min-width: 0;
    padding: 0 28px calc(42px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    z-index: 25;
    top: 0;
    min-height: calc(76px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    gap: 12px;
    background: inherit;
  }

  .menu-toggle { display: none !important; }
  .experience-switcher { order: initial; flex: none; margin: 0; }
  .experience-switcher button { min-width: 0; padding: 0 12px; }
  .experience-switcher .admin-toggle { display: inline-flex; }
  .topbar-actions, .dentist-topbar-actions { order: initial; display: flex; margin-left: auto; }
  .topbar-actions :is(.location-pill,.appearance-toolbar-button,.icon-button), .dentist-topbar-actions :is(.workspace-status,.appearance-toolbar-button) { display: inline-flex; }
  .topbar-actions .avatar-button, .dentist-topbar-actions .avatar-button { width: 40px; height: 40px; }
  .mobile-nav,
  body[data-experience="public"] .public-mobile-nav,
  body[data-experience="dentist"] .dentist-mobile-nav,
  body[data-experience="admin"] .admin-mobile-nav { display: none !important; }

  /* On a tablet, overlays become a reachable side sheet rather than a tall
     phone sheet. It leaves the current screen visible for orientation. */
  .modal-backdrop { background: rgba(34,20,24,.28); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .modal-sheet {
    top: 0;
    right: 0;
    bottom: auto;
    width: min(510px, 62vw);
    height: 100dvh;
    max-height: none;
    padding: calc(72px + env(safe-area-inset-top)) 28px calc(28px + env(safe-area-inset-bottom));
    border: 0;
    border-left: 1px solid rgba(165,0,22,.13);
    border-radius: 0;
    box-shadow: -18px 0 46px rgba(48,14,20,.18);
    transform: translateX(108%);
  }
  .modal-sheet::before { display: none; }
  .modal-sheet.open { transform: translateX(0); }
  .sheet-close { top: calc(18px + env(safe-area-inset-top)); right: 22px; }
  .modal-actions { bottom: calc(-28px - env(safe-area-inset-bottom)); padding: 15px 0 calc(15px + env(safe-area-inset-bottom)); }

  .quick-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .article-grid, .appointment-grid, .opportunity-grid, .admin-article-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .directory-row { grid-template-columns: 58px minmax(0, 1fr) auto; }
  .directory-meta { display: none; }
  .member-stat-grid, .admin-metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Liquid Glass remains painted and static on touch tablets. This prevents
     Safari/iPadOS compositor stalls while preserving the visual treatment. */
  body[data-theme="liquid"] .sidebar { border-right-color: rgba(255,255,255,.19); background: linear-gradient(165deg, #535258, #2b2a30 88%) !important; }
  body[data-theme="liquid"] .topbar { background: #343337; }
  body[data-theme="liquid"] .modal-sheet { border-left-color: rgba(255,255,255,.17); background: linear-gradient(145deg, #4f4e55, #29282e 80%) !important; }
}

/* Portrait iPads and compact tablets: preserve comfortable reading width,
   then stack heavier two-column content before it becomes cramped. */
@media (min-width: 700px) and (max-width: 899px) {
  .sidebar { padding-right: 10px; padding-left: 10px; }
  .main-content { padding-right: 22px; padding-left: 22px; }
  .topbar-actions .location-pill { display: none; }
  .hero-grid, .home-bottom-grid, .profile-layout, .care-layout, .portal-grid, .admin-layout, .student-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-card.featured { grid-column: span 2; }
  .quick-card { min-height: 128px; }
  .hero-card { min-height: 390px; }
  .modal-sheet { width: min(500px, 72vw); }
}

@media (min-width: 900px) and (max-width: 1199px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr) 220px; }
  .home-bottom-grid, .profile-layout, .care-layout, .portal-grid, .admin-layout, .student-grid { grid-template-columns: minmax(0, 1.1fr) minmax(250px, .9fr); }
}

/* Spacious phone presentation
   A deliberately calm, editorial mobile layer: fewer cramped rows, more
   breathing room, and one unmistakable primary action per important card. */
@media (max-width: 699px) {
  body {
    min-width: 320px;
    background: linear-gradient(180deg, #fffefe 0, #fffafa 48%, #fff 100%);
    -webkit-tap-highlight-color: transparent;
  }

  .main-content {
    padding-right: clamp(18px, 5vw, 26px);
    padding-bottom: calc(116px + env(safe-area-inset-bottom));
    padding-left: clamp(18px, 5vw, 26px);
  }

  .topbar {
    min-height: calc(82px + env(safe-area-inset-top));
    gap: 10px;
  }
  .menu-toggle {
    width: 44px;
    height: 44px;
    border-radius: 15px;
  }
  .experience-switcher {
    min-height: 46px;
    padding: 3px;
    border-radius: 17px;
    box-shadow: 0 8px 22px rgba(82,20,27,.06);
  }
  .experience-switcher button {
    min-height: 40px;
    padding: 0 10px;
    border-radius: 13px;
    font-size: 10px;
  }
  .topbar-actions .avatar-button,
  .dentist-topbar-actions .avatar-button {
    width: 44px;
    height: 44px;
    box-shadow: 0 8px 18px rgba(165,0,22,.17);
  }

  h1 { letter-spacing: -.055em; }
  h2 { letter-spacing: -.045em; }
  .eyebrow { margin-bottom: 11px; font-size: 10px; letter-spacing: .15em; }
  .section-block { margin-top: 64px; }
  .section-heading { margin-bottom: 18px; gap: 14px; }
  .section-heading h2 { font-size: clamp(24px, 6.5vw, 29px); }
  .section-heading.compact { margin-top: 56px; }

  .hero-grid { gap: 16px; }
  .hero-card {
    min-height: 554px;
    border-radius: 28px;
    background: radial-gradient(circle at 82% 12%, rgba(224,0,0,.26), transparent 29%), linear-gradient(150deg, #fff7f7, #fff 55%, #fde9eb);
    box-shadow: 0 22px 46px rgba(87,18,27,.12);
  }
  .hero-card::before { top: auto; right: -74px; bottom: -84px; width: 330px; height: 330px; opacity: .8; }
  .hero-card::after { right: -8%; bottom: -138px; width: 92%; opacity: .7; }
  .hero-copy {
    width: 100%;
    padding: 32px clamp(20px, 6vw, 28px);
    justify-content: flex-start;
  }
  .hero-copy h1 {
    max-width: 300px;
    margin-bottom: 15px;
    font-size: clamp(35px, 10vw, 44px);
    line-height: 1.04;
  }
  .hero-description {
    max-width: min(260px, 73%);
    margin-bottom: 24px;
    font-size: 13px;
    line-height: 1.55;
  }
  .hero-actions {
    position: relative;
    z-index: 4;
    display: grid;
    width: min(218px, 72%);
    gap: 10px;
  }
  .hero-actions :is(.primary-button, .secondary-button) {
    width: 100%;
    min-height: 52px;
    padding: 0 16px;
    border-radius: 16px;
    font-size: 12px;
  }
  .hero-actions .primary-button { box-shadow: 0 12px 23px rgba(224,0,0,.26); }
  .hero-person { right: -12px; bottom: -10px; width: 47%; }
  .person-halo { top: auto; bottom: 44px; width: 154px; height: 176px; }
  .person-portrait { width: 142px; height: 205px; margin-top: auto; border-radius: 70px 70px 17px 17px; font-size: 82px; }
  .trusted-tag { right: 14px; bottom: 17px; padding: 8px 10px 8px 7px; transform: scale(.86); transform-origin: right bottom; }
  .hero-watermark { bottom: 12px; left: 19px; font-size: 70px; }
  .emergency-card {
    display: grid;
    min-height: 138px;
    padding: 21px;
    grid-template-columns: 44px minmax(0,1fr) 42px;
    align-items: center;
    gap: 13px;
    border-radius: 23px;
  }
  .emergency-card p { margin: 0 0 3px; font-size: 11px; }
  .emergency-card h2 { font-size: 21px; }
  .round-arrow { width: 42px; height: 42px; margin: 0; }

  .quick-grid { gap: 14px; }
  .quick-card {
    min-height: 152px;
    padding: 18px;
    border-radius: 21px;
    box-shadow: 0 11px 25px rgba(78,22,25,.055);
  }
  .quick-card.featured { min-height: 166px; }
  .quick-icon { width: 40px; height: 40px; border-radius: 13px; font-size: 20px; }
  .quick-card b { margin-top: 15px; font-size: 14px; }
  .quick-card small { margin-top: 5px; font-size: 10px; line-height: 1.45; }
  .quick-card i { right: 17px; bottom: 15px; font-size: 20px; }

  .dentist-scroll {
    grid-auto-columns: minmax(274px, 82vw);
    gap: 15px;
    margin-right: calc(-1 * clamp(18px, 5vw, 26px));
    padding: 3px clamp(2px, 1vw, 6px) 14px 2px;
    scroll-padding-left: 2px;
    scroll-snap-type: x mandatory;
  }
  .dentist-scroll > * { scroll-snap-align: start; }
  .dentist-card, .article-card, .event-row, .directory-row {
    border-radius: 21px;
    box-shadow: 0 11px 25px rgba(78,22,25,.045);
  }
  .dentist-card { min-height: 270px; padding: 18px; }
  .article-grid { gap: 15px; }
  .article-card { overflow: hidden; }
  .article-image { height: 150px; }
  .article-body { padding: 17px; }

  .directory-toolbar, .care-notice, .form-panel, .notice-panel, .verification-panel,
  .portal-panel, .student-panel, .content-studio, .admin-queue, .admin-published,
  .admin-directory-management { border-radius: 22px; }
  .directory-row { padding: 15px; gap: 12px; }
  .directory-row .dentist-photo { width: 54px; height: 54px; }
  .directory-main h3 { font-size: 14px; }
  .directory-actions .primary-button { min-height: 42px; border-radius: 13px; }
  .event-row { padding: 16px; }
  .event-date { height: 58px; border-radius: 15px; }
  .profile-hero { padding: 30px 2px 21px; }
  .profile-summary { gap: 10px; }
  .profile-stat { padding: 16px 12px; border-radius: 18px; }
  .profile-menu { padding: 9px; border-radius: 21px; }

  :is(.primary-button,.secondary-button,.outline-button,.filter-button,.location-action,.save-button) { min-height: 48px; border-radius: 14px; }
  :is(.primary-button,.secondary-button,.outline-button,.filter-button,.location-action,.save-button):active { transform: scale(.98); }
  .mobile-nav {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    left: max(16px, env(safe-area-inset-left));
    min-height: 76px;
    padding: 6px;
    border-radius: 25px;
    box-shadow: 0 18px 38px rgba(60,16,22,.19), inset 0 1px 0 #fff;
  }
  .mobile-nav .nav-item { min-height: 62px; border-radius: 19px; gap: 4px; }
  .mobile-nav .nav-item > span { font-size: 20px; }
  .mobile-nav small { font-size: 10px; }
  .mobile-nav .nav-item.active { color: #fff; background: linear-gradient(135deg, var(--red), var(--maroon)); box-shadow: 0 7px 14px rgba(165,0,22,.22); }

  /* Theme-safe variants for the brighter, more spacious surfaces above. */
  body[data-theme="dark"] { background: #170d0f; }
  body[data-theme="liquid"] { background: #343337; }
  body[data-theme="liquid"] .hero-card { box-shadow: 0 18px 36px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.20) !important; }
  body[data-theme="liquid"] .mobile-nav .nav-item.active { background: linear-gradient(135deg, #bb4a54, #5b545b) !important; }
}

@media (max-width: 370px) {
  .hero-card { min-height: 530px; }
  .hero-copy h1 { max-width: 270px; font-size: 34px; }
  .hero-description { max-width: 245px; }
  .hero-person { width: 45%; }
  .person-portrait { width: 128px; height: 185px; font-size: 74px; }
  .trusted-tag { display: none; }
  .experience-switcher button { padding: 0 7px; font-size: 9px; }
}
