/* ============================================================================
   MOBILE NATIVE — the student mobile app's OWN design layer.

   WHY THIS FILE EXISTS
   The student phone app (iOS/Android via Capacitor) and the clinician/admin
   WEB app share style.css. That shared file is why restyling the phone app
   historically kept disturbing the web app. This file breaks that coupling:

     1. It is linked ONLY on the student app pages, and AFTER style.css — so it
        is the last word in the cascade and can override anything for mobile
        WITHOUT specificity gymnastics.
     2. Every rule is scoped under `html.is-capacitor` — the class main.js adds
        only inside the native runtime (main.js:2). The desktop/web app never
        has that class, so nothing in this file can EVER reach the web app.

   Double isolation: web-first pages don't even load it, and if a student opens
   an app page in a plain browser these rules stay inert (no is-capacitor).

   THE RULE (please keep it):
   • All mobile-app-only design lives HERE, scoped under `html.is-capacitor`.
   • Do NOT add mobile-only tweaks inside the shared style.css anymore.
   • Overriding an existing mobile style? Just write it here — loaded last, it
     wins. `html.is-capacitor .foo { … }` beats an unscoped style.css `.foo`,
     and ties (won by source order) with style.css's own `html.is-capacitor`
     rules.

   The presence of the marker var below is what the isolation test asserts.
   ============================================================================ */

html.is-capacitor {
  /* Proof-of-load marker (read by the isolation test; harmless on device). */
  --pp-mobile-native: 1;

  /* One canonical place to reach the notch / home-indicator insets from any
     rule in this file, so mobile chrome can sit flush without magic numbers. */
  --pp-safe-top: env(safe-area-inset-top, 0px);
  --pp-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- one consistent native chrome -----------------------------------------
   The desktop top-bar (.navbar-app) is the biggest "website in a WebView" tell
   on the phone: it's redundant with each screen's own header + the bottom tab
   bar, it leaked raw onto Messages (which has no mobile header), and it sat
   BEHIND the in-document shell views as a second header. Kill it across the
   native app. Nothing goes headerless — every screen already owns a header:
   Today's .tm-whisper, the .student-shell-view-head, the pp-mobhead pages, and
   each in-app section's own <h2> (Notices, Roadmaps, Conditions, Tips). */
@media (max-width: 768px) {
  html.is-capacitor body.app-dashboard .navbar-app {
    display: none !important;
  }
  /* The navbar used to carry the top safe-area inset; with it gone each screen's
     own header sits at the very top, so pad the scroll container under the notch.
     Today (.tm-whisper), the pp-mobhead pages, the section trio, the shell views
     (.student-shell-view-head) and the placement-details drill-down (its own
     .pd-back header, see site-info.css) already inset themselves — exclude them
     so they don't get a double gap. */
  html.is-capacitor body.app-dashboard:not(.today-mobile-mock):not(.pp-has-mobhead):not(.has-external-shell-view):not(:has(#pp-section-head.is-on)):not(:has(#section-placement-details.is-active)) .app-content {
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* Teaching owns its masthead instead of a safe-area-aware shared header.
     Beat the unified shell's important padding reset with exactly one inset. */
  html.is-capacitor body.app-dashboard.teaching-v12-active .app-content {
    padding-top: var(--pp-safe-top) !important;
  }
  /* The document scrolls beneath the status bar; keep that reserved region
     opaque without adding another inset or changing Teaching's scroll owner. */
  html.is-capacitor body.app-dashboard.teaching-v12-active::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--pp-safe-top);
    background: #fff;
    z-index: 1100;
    pointer-events: none;
  }

  /* Student frame v1 moves the page heading before Today's Meridian content
     and the Placement details header. On an actual iPhone their headings were
     at y=0 / y=16 inside the 62px status area. The frame now owns one device
     inset whenever no compact masthead owns it. Teaching retains its existing
     inset on .app-content. Use the frame gutter and measured safe-area token,
     never a device-specific correction. */
  html.is-capacitor body.app-dashboard.pf-frame-v1:not(.pp-has-mobhead):not(.teaching-v12-active):not(:has(#pp-section-head.is-on)) .pf-page {
    padding-top: calc(var(--pp-safe-top) + var(--pf-page-top)) !important;
  }
  html.is-capacitor body.app-dashboard.pf-frame-v1.today-mobile-mock .tm-shell {
    padding-top: 8px !important;
  }
  html.is-capacitor body.app-dashboard.pf-frame-v1:has(#section-placement-details.is-active) #pd-mobile {
    padding-top: 8px !important;
  }

  /* A platform announcement is the first item in .app-content. Reserve the
     notch in normal flow before it, then remove that same inset from whichever
     route header follows. The page therefore owns exactly one safe-top inset,
     with no transformed/overlapping hit boxes and no device pixel constant. */
  html.is-capacitor body.app-dashboard .app-content:has(> .pf-platform-banners),
  /* Match student-shell.css's existing ID-level specificity ladder on the two
     route families whose zero-top reset is deliberately pinned !important. */
  html.is-capacitor body.app-dashboard.pp-has-mobhead:not(:has(#pf-navstd-a)):not(:has(#pf-navstd-b)) .app-content:has(> .pf-platform-banners),
  html.is-capacitor body.app-dashboard:has(#pp-section-head.is-on):not(:has(#pf-navstd-a)) .app-content:has(> .pf-platform-banners) {
    padding-top: var(--pp-safe-top) !important;
  }
  html.is-capacitor body.app-dashboard.today-mobile-mock .app-content:has(> .pf-platform-banners) .tm-shell,
  html.is-capacitor body.app-dashboard.pp-has-mobhead .app-content:has(> .pf-platform-banners) .pp-mobhead,
  html.is-capacitor body.app-dashboard.has-external-shell-view .app-content:has(> .pf-platform-banners) .student-shell-view-head,
  html.is-capacitor body.app-dashboard .app-content:has(> .pf-platform-banners) > #pp-section-head.is-on,
  html.is-capacitor body.app-dashboard:has(#section-placement-details.is-active) .app-content:has(> .pf-platform-banners) #pd-mobile {
    padding-top: 8px !important;
  }
}

/* ---- native touch feel ----------------------------------------------------
   A quick, subtle press-scale on the primary tappables makes the app feel
   native rather than "a website in a WebView". Additive (only :active), and
   silenced under reduced-motion. Add new tappables here as the app grows. */
@media (prefers-reduced-motion: no-preference) {
  html.is-capacitor .student-mobile-nav .student-mobile-nav-item:active,
  html.is-capacitor .tm-hero-cta:active,
  html.is-capacitor .tm-btn-primary:active,
  html.is-capacitor .tm-btn-ghost:active,
  html.is-capacitor .tm-g-tile:active,
  html.is-capacitor .tm-hero-pill:active,
  html.is-capacitor .tm-avatar:active,
  html.is-capacitor .tm-search-btn:active,
  html.is-capacitor .student-mobile-more-link:active,
  html.is-capacitor .native-session-attachment-card:active,
  html.is-capacitor .native-session-pdf-preview-open:active,
  html.is-capacitor .sor-row-act .sor-btn-ghost:active,
  html.is-capacitor .pf-th-seat:active,
  html.is-capacitor .pf-th-av:active {
    transform: scale(0.97);
    transition: transform 90ms ease;
  }
}

/* The iOS/Android status bar owns the time — the in-page clock pill ~20px
   beneath it is pure duplication on native. (Kept on mobile web, where no
   system clock is guaranteed on screen.) */
html.is-capacitor .tm-whisper .tm-clock {
  display: none;
}

/* In-document swaps: kill the hard cut (the last "webview tell"). The
   incoming section / shell view body fades in over ~160ms. Opacity only —
   a transform here would create a containing block and break any fixed
   descendants mid-animation. Synchronous CSS (no View Transitions API) so
   setActiveSection's callers keep their ordering guarantees. */
html.is-capacitor body.app-dashboard [data-page-section].is-active {
  animation: pp-section-enter 160ms ease-out;
}
html.is-capacitor .student-shell-view-body.pp-body-in {
  animation: pp-section-enter 160ms ease-out;
}
@keyframes pp-section-enter {
  from { opacity: 0.35; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html.is-capacitor body.app-dashboard [data-page-section].is-active,
  html.is-capacitor .student-shell-view-body.pp-body-in {
    animation: none;
  }
}

/* ---- timetable session resources -----------------------------------------
   Native detail sheets keep one scroll owner (.schedule-detail-body). Rich
   attachments and PDF first-page images therefore size to their content and
   never introduce a nested document/PDF scroller. */
@media (max-width: 768px) {
  html.is-capacitor body.student-schedule-page .native-session-takeaways {
    margin: 0 0 20px !important;
    padding: 14px 15px !important;
    border: 1px solid #d4e6fb !important;
    border-radius: 14px !important;
    background: var(--pf-brand-tint, #eaf2fd) !important;
  }

  html.is-capacitor body.student-schedule-page
    .native-session-takeaways
    > .schedule-detail-section-title {
    margin-bottom: 10px !important;
    color: var(--pf-brand-2, #1559b0) !important;
  }

  html.is-capacitor body.student-schedule-page .native-session-takeaway-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  html.is-capacitor body.student-schedule-page .native-session-takeaway-list li {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    gap: 9px;
    align-items: start;
    margin: 0;
  }

  html.is-capacitor body.student-schedule-page .native-session-takeaway-check {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    border-radius: 50%;
    color: #fff;
    background: var(--pf-brand, #1f6fd6);
    font-size: 10px;
    font-weight: 600;
  }

  html.is-capacitor body.student-schedule-page .native-session-takeaway-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
    color: var(--pf-ink-2, #5d6b84);
    font-size: 12.5px;
    line-height: 1.45;
  }

  html.is-capacitor body.student-schedule-page .native-session-takeaway-copy strong {
    color: var(--pf-ink, #1b2740);
    font-size: 13px;
  }

  html.is-capacitor body.student-schedule-page
    .schedule-session-resources.native-session-resources {
    margin: 20px 0 0 !important;
    padding: 18px 0 0 !important;
    border-top: 1px solid var(--pf-line, #e6ebf3) !important;
  }

  html.is-capacitor body.student-schedule-page .native-session-resources-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 11px;
  }

  html.is-capacitor body.student-schedule-page .native-session-resources-head h3 {
    margin: 0;
    color: var(--pf-ink, #1b2740);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
  }

  html.is-capacitor body.student-schedule-page .native-session-resources-head > span {
    flex: none;
    color: var(--pf-ink-3, #8a97ad);
    font-size: 10.5px;
    font-weight: 600;
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-list {
    gap: 10px;
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-card {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    min-height: 68px;
    padding: 11px 12px;
    border: 1px solid var(--pf-line, #e6ebf3);
    border-radius: 14px;
    color: var(--pf-ink, #1b2740);
    background: var(--pf-surface, #fff);
    box-shadow: 0 4px 14px rgba(20, 33, 64, 0.055);
    -webkit-tap-highlight-color: transparent;
  }

  html.is-capacitor body.student-schedule-page
    .native-session-attachment-card::after,
  html.is-capacitor body.student-schedule-page
    .native-session-pdf-preview-open::after {
    content: none;
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 11px;
    color: #8b2c2c;
    background: #fcecec;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
  }

  html.is-capacitor body.student-schedule-page
    .native-session-attachment-icon--slides {
    color: #9a4b18;
    background: #fff0e5;
  }

  html.is-capacitor body.student-schedule-page
    .native-session-attachment-icon--recording {
    color: var(--pf-brand-2, #1559b0);
    background: var(--pf-brand-tint, #eaf2fd);
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-copy {
    display: grid;
    gap: 5px;
    min-width: 0;
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-title {
    display: -webkit-box;
    overflow: hidden;
    color: var(--pf-ink, #1b2740);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-width: 0;
    color: var(--pf-ink-3, #8a97ad);
    font-size: 10px;
    font-weight: 500;
    line-height: 1.25;
  }

  html.is-capacitor body.student-schedule-page
    .native-session-attachment-meta
    span
    + span::before {
    content: "·";
    margin-right: 4px;
  }

  html.is-capacitor body.student-schedule-page .native-session-attachment-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 30px;
    padding: 5px 8px;
    border-radius: 999px;
    color: var(--pf-brand-2, #1559b0);
    background: var(--pf-brand-tint, #eaf2fd);
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
  }

  html.is-capacitor body.student-schedule-page .native-session-pdf-preview {
    overflow: hidden;
    margin: 13px 0 0;
    border: 1px solid var(--pf-line, #e6ebf3);
    border-radius: 14px;
    background: #f4f6fa;
  }

  html.is-capacitor body.student-schedule-page .native-session-pdf-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    color: var(--pf-ink-2, #5d6b84);
    background: var(--pf-surface, #fff);
    border-bottom: 1px solid var(--pf-line, #e6ebf3);
    font-size: 10.5px;
    font-weight: 600;
  }

  html.is-capacitor body.student-schedule-page .native-session-pdf-preview-stage {
    display: grid;
    place-items: center;
    min-height: 180px;
    max-height: 230px;
    padding: 12px;
    overflow: hidden;
    background: #e9edf4;
  }

  html.is-capacitor body.student-schedule-page .native-session-pdf-preview-stage img {
    display: block;
    width: 100%;
    height: 206px;
    object-fit: contain;
    object-position: center top;
    filter: drop-shadow(0 5px 9px rgba(20, 33, 64, 0.16));
  }

  html.is-capacitor body.student-schedule-page
    .native-session-pdf-preview-unavailable {
    display: grid;
    justify-items: center;
    gap: 9px;
    color: var(--pf-ink-2, #5d6b84);
    font-size: 12px;
    text-align: center;
  }

  html.is-capacitor body.student-schedule-page
    .native-session-pdf-preview-unavailable
    > span {
    display: grid;
    place-items: center;
    width: 58px;
    height: 74px;
    border-radius: 5px;
    color: #a12d2d;
    background: #fff;
    box-shadow: 0 5px 12px rgba(20, 33, 64, 0.12);
    font-size: 11px;
    font-weight: 600;
  }

  html.is-capacitor body.student-schedule-page .native-session-pdf-preview-caption {
    display: grid;
    gap: 10px;
    padding: 11px 12px 12px;
    color: var(--pf-ink-3, #8a97ad);
    background: var(--pf-surface, #fff);
    font-size: 10.5px;
    line-height: 1.4;
  }

  html.is-capacitor body.student-schedule-page .native-session-pdf-preview-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: stretch;
    gap: 6px;
    min-height: 44px;
    padding: 9px 12px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--pf-brand, #1f6fd6);
    font-size: 12px;
    font-weight: 600;
  }

  /* Universal Year 6 sessions have no QR footer. Do not leave an empty sticky
     bar covering the final attachment action. */
  html.is-capacitor body.student-schedule-page .schedule-detail-actions:empty {
    display: none !important;
  }
}
