/* =========================================================================
   Mobile app-style layout — a native-feeling phone view that replaces the
   desktop sidebar/topbar shell below 640px, on every logged-in page (bottom
   tab bar) plus bespoke Home and Login screens matching the provided
   reference mockups. Above 640px nothing here applies; the existing desktop/
   tablet responsive behavior in layout.css and login.css is untouched.
   ========================================================================= */

/* ---------- Bottom tab bar (global, all logged-in pages) ---------- */

@media (max-width: 640px) {
  /* Reserve space for the fixed bottom tab bar. It's a `position:fixed`
     overlay, so it never takes up document flow space on its own — anything
     that fills the viewport with min-height:100vh (a "cinematic" full-bleed
     screen, or a normal .page) has to explicitly leave this much room at
     the bottom itself, or its own bottom content/buttons render underneath
     the bar and end up hidden (confirmed on a real Poco X8 — the fixed bar's
     rendered height plus the phone's own gesture-nav safe-area easily
     exceeds a device-agnostic guess, so this is intentionally generous). */
  :root { --mtabbar-h: 84px; }

  /* Safety net: several pages nest a flex/grid row (e.g. .tabs) inside a
     CSS Grid column (.detail-grid, .player-layout, .dashboard-grid — see the
     "> * { min-width: 0 }" rules added next to each in pages.css/components.css
     for the real fix). This is a second line of defense so a stray unshrinkable
     element can never force the whole page to scroll sideways. */
  html, body { overflow-x: hidden; }

  /* NOTE: the sidebar, its hamburger toggle, and the dim scrim behind it are
     intentionally left alone here — they already become a slide-out drawer
     at the 900px breakpoint in layout.css (position:fixed + translateX, a
     working show/hide toggle), and that keeps working fine all the way down
     to phone widths. It's still needed on mobile: the bottom tab bar only
     covers 5 primary destinations, so the drawer is how the rest of the nav
     (Learning Journey, Practical Logbook, Internship, Career, Industry
     Portal, etc.) stays reachable. Force-hiding it here previously also
     left `.topbar__actions` as the ONLY visible child of a
     `justify-content: space-between` topbar, which collapses a lone flex
     item to the start — that's what was throwing the chat/notification
     dropdowns to the left edge of the screen instead of under their icons. */
  .page { padding-bottom: var(--mtabbar-h); max-width: 100%; }

  /* "Cinematic" full-bleed screens (the 360°/3D room simulation, the episode
     player) size themselves to fill the viewport below the topbar, but don't
     know about the tab bar sitting on top of them — so their own bottom
     content (e.g. an intro screen's CTA button) can end up hidden behind it. */
  /* Everything here is `box-sizing: border-box` (base.css), so min-height
     already includes padding — it must NOT also subtract the tab-bar
     clearance, or the box shrinks twice: once from the smaller min-height,
     again from the padding eating into that already-smaller box. That left
     a ~22px unstyled gap between the stage and the tab bar. min-height only
     needs to fill down to the viewport edge; padding-bottom alone reserves
     the tab-bar clearance inside that box, so the dark background still
     reaches the true bottom. */
  .r360-stage, .ep-stage {
    min-height: calc(100vh - var(--header-height));
    padding-bottom: calc(var(--mtabbar-h) + env(safe-area-inset-bottom, 0px));
  }

  /* Pages with a bespoke mobile screen (their own header baked into the
     markup, e.g. .mobile-home on Dashboard) hide the shared desktop topbar
     entirely instead of just trimming it — every other page keeps the
     topbar so search/notifications/profile stay reachable on mobile. */
  body:has(.mobile-home) .topbar { display: none; }

  /* .dropdown-menu's default `right: 0` anchors it to its own trigger
     button's right edge — fine on desktop where there's room to spare, but
     on a narrow phone the chat/notification buttons aren't the rightmost
     thing in the topbar (the profile button is), so their menus' min-width
     (260-280px) pushed them off the LEFT edge of the screen entirely.
     Anchoring to the viewport instead of the trigger sidesteps that. */
  .dropdown-menu {
    position: fixed; top: calc(var(--header-height) + 8px); left: 12px; right: 12px; width: auto; max-width: none;
  }

  /* The sidebar drawer (z-index:40) and its dim scrim (z-index:39) predate
     the bottom tab bar (z-index:60) — bump both above it here so opening
     the drawer on mobile covers the tab bar too, instead of the tab bar
     staying stranded on top of a supposedly full-screen overlay. */
  .sidebar { z-index: 70; }
  .sidebar-scrim { z-index: 65; }

  /* The tab bar itself is styled in coursera.css (UAT fixes layer): it shows
     at <=900px so navigation exists whenever the header tabs hide. */

  /* Course detail hero: the 21:7 banner + title/description/meta overlay is
     tuned for wide desktop images and is too short on a phone, forcing the
     overlay text up into the lighter part of the scrim (hard to read, looks
     like it "overlaps" the photo). Give it more height and drop the
     description here — it's already repeated in the Overview tab below. */
  .course-hero img { aspect-ratio: 4/3; }
  .course-hero__overlay { background: linear-gradient(0deg, rgba(15,18,22,0.92) 30%, rgba(15,18,22,0.15) 85%); padding: 16px; }
  .course-hero__content h1 { font-size: 19px; }
  .course-hero__content p { display: none; }
  .course-hero__meta { gap: 10px 14px; margin-top: 8px; }

  /* A couple of pages (e.g. the internship stat row in career.js) force
     .stat-grid to a fixed 3 columns via an inline style, which — being an
     inline style — outranks the class-based 1-column breakpoint already
     defined in components.css and squeezes labels like "Performance" until
     they overflow their card. !important is the only thing that can win
     against an inline style, so it's used deliberately here. */
  .stat-grid { grid-template-columns: 1fr !important; }
}

/* ---------- Mobile Home (dashboard.html) ---------- */
.mobile-home { display: none; }

@media (max-width: 640px) {
  .dashboard-desktop-view { display: none; }
  .mobile-home { display: block; padding: 16px 16px 0; max-width: 480px; margin: 0 auto; }

  .mh-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
  .mh-header__brand { display: flex; align-items: center; gap: 8px; }
  .mh-header__brand img { height: 26px; }
  .mh-header__brand-text { display: flex; flex-direction: column; line-height: 1.15; }
  .mh-header__brand-text strong { font-size: 13.5px; color: var(--ink-900); }
  .mh-header__brand-text span { font-size: 13px; color: var(--text-secondary); }
  .mh-header__actions { display: flex; align-items: center; gap: 6px; }
  .mh-icon-btn { position: relative; width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--ink-50); display: flex; align-items: center; justify-content: center; color: var(--ink-700); }
  .mh-icon-btn__dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--coral-500); border: 2px solid #fff; }
  .mh-avatar-wrap { position: relative; margin-left: 2px; }
  .mh-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
  .mh-avatar__dot { position: absolute; bottom: 0; right: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--green-500); border: 2px solid #fff; }

  .mh-hero { position: relative; overflow: hidden; border-radius: var(--radius-xl); padding: 20px 18px; margin-bottom: 16px; background: linear-gradient(150deg, var(--blue-50) 0%, #fff 65%); }
  .mh-hero__petals { position: absolute; top: -30px; right: -40px; width: 170px; height: 170px; opacity: 0.9; }
  .mh-hero__petals::before, .mh-hero__petals::after {
    content: ""; position: absolute; border-radius: 50%; background: var(--blue-100);
  }
  .mh-hero__petals::before { width: 170px; height: 170px; top: 0; right: 0; }
  .mh-hero__petals::after { width: 110px; height: 110px; top: 40px; right: 60px; background: var(--blue-400); opacity: 0.35; }
  .mh-hero__text { position: relative; z-index: 1; max-width: 68%; }
  .mh-hero__greeting { font-size: 13px; color: var(--text-secondary); margin-bottom: 2px; }
  .mh-hero__text h1 { font-size: 21px; font-weight: 800; color: var(--ink-900); margin-bottom: 8px; }
  .mh-hero__sub { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
  .mh-hero__card {
    position: relative; z-index: 1; margin-top: 16px; background: #fff; border-radius: 12px; padding: 12px 14px;
    box-shadow: var(--shadow-card); max-width: 210px;
  }
  .mh-hero__card p { font-size: 13px; font-weight: 600; color: var(--ink-900); line-height: 1.4; margin-bottom: 8px; }
  .mh-hero__card .progress-track { height: 5px; }

  .mh-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
  .mh-stat { display: flex; flex-direction: column; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--border-default); border-radius: 12px; padding: 12px 4px; text-align: center; }
  .mh-stat__icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
  .mh-stat strong { font-size: 15px; font-weight: 800; color: var(--ink-900); }
  .mh-stat span { font-size: 13px; color: var(--text-secondary); line-height: 1.2; }

  .mh-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 8px; margin-bottom: 22px; }
  .mh-action { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--ink-900); font-size: 13px; font-weight: 600; line-height: 1.25; }
  .mh-action__icon { width: 50px; height: 50px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }

  .mh-section { margin-bottom: 22px; }
  .mh-section__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
  .mh-section__header h3 { font-size: 16px; font-weight: 800; color: var(--ink-900); }
  .mh-section__header a { font-size: 13px; font-weight: 600; color: var(--blue-600); }

  .mh-continue-card { display: block; background: #fff; border: 1px solid var(--border-default); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-card); }
  .mh-continue-card__thumb { position: relative; aspect-ratio: 16/8; }
  .mh-continue-card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .mh-continue-card__play { position: absolute; inset: 0; margin: auto; width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,0.92); display: flex; align-items: center; justify-content: center; color: var(--blue-600); }
  .mh-continue-card__body { padding: 14px 16px 16px; }
  .mh-continue-card__cat { font-size: 13px; font-weight: 700; color: var(--blue-600); text-transform: uppercase; letter-spacing: 0.02em; }
  .mh-continue-card__body strong { display: block; font-size: 14.5px; color: var(--ink-900); margin: 3px 0 10px; }
  .mh-continue-card__row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
  .mh-continue-card__row > span:first-child { font-size: 13px; color: var(--text-secondary); }

  .mh-hscroll { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .mh-rec-card { flex: 0 0 auto; width: 220px; background: #fff; border: 1px solid var(--border-default); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-card); }
  .mh-rec-card__thumb { position: relative; aspect-ratio: 16/10; }
  .mh-rec-card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .mh-rec-card__badge { position: absolute; top: 10px; left: 10px; }
  .mh-rec-card__bookmark { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,0.92); display: flex; align-items: center; justify-content: center; color: var(--ink-700); }
  .mh-rec-card__body { padding: 12px 14px 14px; }
  .mh-rec-card__body strong { display: block; font-size: 13.5px; color: var(--ink-900); margin-bottom: 8px; line-height: 1.3; }
  .mh-rec-card__meta { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
  .mh-rec-card__meta span { display: flex; align-items: center; gap: 4px; }
}

/* ---------- Mobile Login (login.html) ---------- */
.mobile-login-shell { display: none; }

@media (max-width: 640px) {
  .auth2 { display: none; }
  .mobile-login-shell {
    display: block; min-height: 100vh; background: #fff; padding: 20px 20px calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .ml-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
  .ml-header__brand { display: flex; align-items: center; gap: 8px; }
  .ml-header__brand img { height: 28px; }
  .ml-header__brand-text { display: flex; flex-direction: column; line-height: 1.15; }
  .ml-header__brand-text strong { font-size: 14px; color: var(--ink-900); }
  .ml-header__brand-text span { font-size: 13px; color: var(--text-secondary); }
  .ml-header__lang {
    display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-700);
    border: none; background: none; padding: 4px;
  }

  /* ---- Hero: headline, then the provided brand graphic full-width below it ---- */
  .ml-hero { margin-bottom: 20px; }
  .ml-hero__text { margin-bottom: 6px; }
  .ml-hero__title { font-size: 26px; font-weight: 800; color: var(--ink-900); line-height: 1.2; margin-bottom: 10px; }
  .ml-hero__title span { color: var(--blue-500); }
  .ml-hero__sub { font-size: 13px; color: var(--text-secondary); line-height: 1.55; }
  .ml-hero__art { display: block; width: 82%; max-width: 300px; height: auto; margin: 0 auto; }

  .ml-form-card { background: #fff; }
  .ml-form-card h2 { font-size: 15px; margin-bottom: 20px; color: var(--ink-900); }
  .ml-social-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
  .ml-social-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 10px; border-radius: 12px;
    border: 1px solid var(--border-default); background: #fff; font-size: 13px; font-weight: 600; color: var(--ink-900);
  }
}
