/* ============================================================
   FCA Interactive Floor-Plans — MOBILE chrome
   Served when the viewport is phone-sized (≤820px). A full-bleed
   Three.js scene under a translucent control layer: top chrome
   (building chip + Call for Quote), a 4-segment bottom bar, device
   bottom sheets, systems/sims half-sheets, a sim dock, and a PiP.

   Pixel values are ported VERBATIM from the design handoff
   (mobile-spec/spec.css) so the menu + icons match the spec.
   The only adaptations: the 270px phone-mock coordinate space is
   replaced by the real viewport, and OS chrome is cleared with
   env(safe-area-inset-*) instead of the mock status bar / home pill.
   Everything is scoped under #m-shell so the desktop page is untouched.
   ============================================================ */

/* ---- activate the mobile experience on phone-sized viewports ---- */
#m-shell { display: none; }

@media (max-width: 820px) {
  /* the 3D canvas becomes the full-viewport backdrop */
  #plan-3d {
    position: fixed; inset: 0; z-index: 1;
    width: 100vw !important; height: 100svh !important; height: 100dvh !important;
    aspect-ratio: auto !important; cursor: default; border-radius: 0;
  }
  /* hide every desktop chrome surface; the mobile shell replaces them */
  .page-header, .hero, .switcher, .systems-sec, .cta-band,
  .sidebar, .plan-strip, .plan-blurb, .zoom-ctl, .zoom-hint,
  .sim-toast, .pip-frame, .grid-bg { display: none !important; }
  .stage, .plan-col { margin: 0 !important; padding: 0 !important; gap: 0 !important; display: block !important; }
  .plan-card { border: 0 !important; border-radius: 0 !important; box-shadow: none !important; background: transparent !important; overflow: visible !important; }
  .plan-svg-wrap { position: static !important; }
  body { overflow: hidden; }

  #m-shell { display: block; }
}

/* ============================================================
   SHELL + TOKENS (exact design-system values from the spec)
   ============================================================ */
#m-shell {
  position: fixed; inset: 0; z-index: 60;
  pointer-events: none;                 /* overlay — only controls catch touch */
  font-family: 'Montserrat', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  --red: #e02222; --yellow: #e0c14a; --live: #22c55e;
  --ink: #f3f5f7; --label: #8b93a1; --dim: #5a6373;
  --line: rgba(255,255,255,0.10); --line-2: rgba(255,255,255,0.16);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sys-fire: #e02222; --sys-intrusion: #c45a10; --sys-access: #1a5a9a;
  --sys-surveillance: #0e7a8a; --sys-audio: #5a3cb0; --sys-network: #4a5565;
}
#m-shell * { box-sizing: border-box; }
#m-shell .live-pip, #m-shell .chip, #m-shell .botbar, #m-shell .sheet,
#m-shell .simsheet, #m-shell .simdock, #m-shell .simbanner, #m-shell .pip,
#m-shell .coach, #m-shell .scrim { pointer-events: auto; }

@keyframes m-pulse { 0%{box-shadow:0 0 0 0 rgba(224,34,34,.5)} 70%{box-shadow:0 0 0 7px rgba(224,34,34,0)} 100%{box-shadow:0 0 0 0 rgba(224,34,34,0)} }
@media (prefers-reduced-motion: reduce) { #m-shell *, #m-shell *::before, #m-shell *::after { animation: none !important; } }

/* scene vignette for depth (matches spec) */
#m-shell .scene-vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: radial-gradient(140% 100% at 50% 40%, transparent 55%, rgba(0,0,0,0.45) 100%);
}

/* ============================================================
   TOP CHROME — building switcher chip + quote
   ============================================================ */
#m-shell .topchrome {
  position: absolute; top: 0; left: 0; right: 0; z-index: 52;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 14px 0;
}
#m-shell .chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: 999px;
  background: rgba(12,16,24,0.72); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--line); color: var(--ink);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis;
}
#m-shell .chip .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#m-shell .chip .mono { font-family: var(--mono); color: var(--label); font-weight: 400; font-size: 10px; flex: none; }
#m-shell .chip .live-pip { width: 6px; height: 6px; border-radius: 999px; background: var(--live); box-shadow: 0 0 6px var(--live); flex: none; }
#m-shell .chip svg { width: 14px; height: 14px; stroke: currentColor; }
#m-shell .chip.quote { background: var(--red); border-color: transparent; color: #fff; box-shadow: 0 4px 14px rgba(224,34,34,0.4); flex: none; }

/* ============================================================
   BOTTOM CONTROL BAR — 4 segments
   ============================================================ */
#m-shell .botbar {
  position: absolute; left: 10px; right: 10px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); z-index: 54;
  background: rgba(12,16,24,0.82); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--line-2); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  padding: 7px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px;
}
#m-shell .seg {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 2px 6px; border-radius: 12px; cursor: pointer;
  font-size: 10px; font-weight: 600; color: var(--label); letter-spacing: 0.01em;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
#m-shell .seg svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.8; }
#m-shell .seg.active { background: rgba(224,34,34,0.14); color: #ff6b6b; }
#m-shell .seg.active svg { stroke: #ff6b6b; }
#m-shell .seg:active { background: rgba(255,255,255,0.05); }

/* ============================================================
   BOTTOM SHEET (device peek + expanded)
   ============================================================ */
#m-shell .scrim { position: absolute; inset: 0; z-index: 55; background: rgba(0,0,0,0.4); }
/* Device drawer: a height-following bottom sheet. Its inline `height` tracks the
   thumb during a drag (set in mobile.js); the header stays visible, the body is
   revealed as it grows. overflow:hidden clips the body at peek height. */
#m-shell .sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 56;
  display: flex; flex-direction: column; overflow: hidden;
  background: linear-gradient(180deg, #11151c, #0c1016);
  border-top: 1px solid var(--line-2); border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.55);
  padding: 10px 16px 0;
  touch-action: none; will-change: height;
}
#m-shell .sheet .grab { width: 38px; height: 4px; border-radius: 999px; background: rgba(255,255,255,0.22); margin: 2px auto 12px; flex: none; }
#m-shell .sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#m-shell .sheet-head > div { min-width: 0; }
#m-shell .sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
#m-shell .sheet-head .micon {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  display: grid; place-items: center; border: 1.4px solid currentColor; background: rgba(255,255,255,0.03);
}
#m-shell .sheet-head .micon svg { width: 22px; height: 22px; }
#m-shell .sheet-cat { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; }
#m-shell .sheet-name { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; margin: 3px 0 2px; }
#m-shell .sheet-model { font-family: var(--mono); font-size: 11px; color: var(--label); }
#m-shell .sheet-bul { list-style: none; margin: 14px 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
#m-shell .sheet-bul li { display: grid; grid-template-columns: 14px 1fr; gap: 9px; font-size: 13px; color: #d7dbe2; line-height: 1.45; }
#m-shell .sheet-bul .di { color: currentColor; font-size: 11px; line-height: 1.4; }
#m-shell .sheet-spec { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 2px; }
#m-shell .spectag { font-family: var(--mono); font-size: 10px; color: var(--label); border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px; }
#m-shell .sheet-cta {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; border-radius: 12px; font-weight: 700; font-size: 14px; color: #fff; margin-top: 4px; cursor: pointer;
}
#m-shell .sheet-cta svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
#m-shell .sheet .note { font-size: 12.5px; color: var(--dim); font-style: italic; margin-top: 10px; text-align: center; }
#m-shell .sheet-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; max-height: 100%; }

/* sims / systems half-sheet */
#m-shell .simsheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 56;
  background: linear-gradient(180deg, #11151c, #0c1016); border-top: 1px solid var(--line-2);
  border-radius: 20px 20px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,0.55);
  padding: 10px 14px calc(20px + env(safe-area-inset-bottom, 0px)); touch-action: none;
}
#m-shell .simsheet .grab, #m-shell .sheet .grab { width: 38px; height: 4px; border-radius: 999px; background: rgba(255,255,255,0.22); margin: 2px auto 12px; }
#m-shell .sheet-title { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 10px; }
#m-shell .sheet-title h4 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
#m-shell .sheet-title .x { width: 26px; height: 26px; border-radius: 999px; border: 1px solid var(--line); display: grid; place-items: center; color: var(--label); cursor: pointer; }
#m-shell .sysrow { display: flex; align-items: center; gap: 11px; padding: 9px 8px; border-radius: 10px; cursor: pointer; }
#m-shell .sysrow + .sysrow { border-top: 1px solid var(--line); }
#m-shell .sysrow .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
#m-shell .sysrow .sn { font-weight: 600; font-size: 13.5px; flex: 1; color: var(--ink); }
#m-shell .sysrow .sn .dur { color: var(--dim); font-weight: 400; }
#m-shell .sysrow .sc { font-family: var(--mono); font-size: 11px; color: var(--label); }
#m-shell .sysrow.on { background: rgba(255,255,255,0.04); }
#m-shell .sysrow .toggle { width: 30px; height: 18px; border-radius: 999px; background: rgba(255,255,255,0.12); position: relative; flex: none; }
#m-shell .sysrow.on .toggle { background: var(--red); }
#m-shell .sysrow .toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 999px; background: #fff; transition: 0.15s; }
#m-shell .sysrow.on .toggle::after { left: 14px; }

/* ============================================================
   SIM RUN — status banner + PiP + dock
   ============================================================ */
#m-shell .simbanner {
  position: absolute; left: 10px; right: 10px; top: calc(env(safe-area-inset-top, 0px) + 56px); z-index: 52;
  display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 12px;
  background: rgba(20,8,10,0.85); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid rgba(224,34,34,0.4);
}
#m-shell .simbanner .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--red); box-shadow: 0 0 8px var(--red); animation: m-pulse 1.4s infinite; flex: none; }
#m-shell .simbanner.calm { border-color: var(--line-2); background: rgba(12,16,24,0.85); }
#m-shell .simbanner.calm .dot { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
#m-shell .simbanner .st { font-size: 12px; font-weight: 700; color: var(--ink); }
#m-shell .simbanner .ss { font-family: var(--mono); font-size: 10px; color: #ff9a9a; }
#m-shell .simbanner.calm .ss { color: var(--label); }

#m-shell .pip {
  position: absolute; z-index: 53; top: calc(env(safe-area-inset-top, 0px) + 62px); right: 12px;
  width: 116px; height: 78px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line-2); background: #05080c; box-shadow: 0 8px 22px rgba(0,0,0,0.6);
  touch-action: none;
}
#m-shell .pip .pip-feed { position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 3px),
    radial-gradient(80% 80% at 40% 30%, #14202b, #070c12); }
#m-shell .pip .pip-fov { position: absolute; inset: 0; background: conic-gradient(from 200deg at 30% 20%, rgba(14,122,138,0.22), transparent 60deg); }
#m-shell .pip .pip-fig { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); width: 18px; height: 30px; border-radius: 8px 8px 4px 4px; background: rgba(224,34,34,0.5); filter: blur(0.4px); }
#m-shell .pip .pip-label { position: absolute; top: 5px; left: 6px; font-family: var(--mono); font-size: 8px; color: #cfe; letter-spacing: 0.08em; display: flex; align-items: center; gap: 4px; }
#m-shell .pip .rec { width: 6px; height: 6px; border-radius: 999px; background: var(--red); box-shadow: 0 0 6px var(--red); animation: m-pulse 1.1s infinite; }

#m-shell .simdock {
  position: absolute; left: 10px; right: 10px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); z-index: 54;
  background: rgba(12,16,24,0.86); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--line-2); border-radius: 16px; padding: 11px 13px 12px;
}
#m-shell .simdock .row1 { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
#m-shell .simdock .sname { font-weight: 700; font-size: 13px; color: var(--ink); }
#m-shell .simdock .sphase { font-family: var(--mono); font-size: 10px; color: var(--label); max-width: 58%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#m-shell .simdock .track { height: 5px; border-radius: 999px; background: rgba(255,255,255,0.1); position: relative; overflow: hidden; }
#m-shell .simdock .fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0%; background: linear-gradient(90deg, var(--red), #ff6b6b); border-radius: 999px; transition: width 0.25s linear; }
#m-shell .simdock .chips { display: flex; gap: 7px; margin-top: 11px; }
#m-shell .simbtn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; border-radius: 10px; font-size: 12px; font-weight: 600; color: var(--ink);
  background: rgba(255,255,255,0.05); border: 1px solid var(--line); cursor: pointer; -webkit-tap-highlight-color: transparent; }
#m-shell .simbtn.exit { color: #ff9a9a; border-color: rgba(224,34,34,0.3); background: rgba(224,34,34,0.08); }
#m-shell .simbtn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ============================================================
   COACHMARK (first-touch onboarding)
   ============================================================ */
#m-shell .coach {
  position: absolute; z-index: 57; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); transform: translateX(-50%);
  background: rgba(12,16,24,0.92); border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); width: max-content; max-width: 270px;
}
#m-shell .coach .crow { display: flex; align-items: center; gap: 10px; }
#m-shell .coach .ci { width: 24px; height: 24px; flex: none; color: var(--yellow); }
#m-shell .coach .ci svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.7; }
#m-shell .coach .ct { font-size: 12px; color: #d7dbe2; line-height: 1.35; }
#m-shell .coach .cgot { align-self: flex-end; font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; color: var(--yellow); border: 1px solid rgba(224,193,74,0.4); border-radius: 8px; padding: 5px 12px; cursor: pointer; }
#m-shell .coach-dim { position: absolute; inset: 0; z-index: 56; background: rgba(0,0,0,0.45); pointer-events: auto; }

/* utility */
#m-shell [hidden] { display: none !important; }
