/* Mobile shell — below 768px (or with ?view=mobile). Replaces the
   desktop dashboard chrome with: small topbar, compact stats line,
   sticky scatter at top, vertical node graph (spine centered), and
   an in-place detail panel that replaces the graph on tap. */

#mobile-shell { display: none; }

body.force-mobile #topbar,
body.force-mobile #main-area > #center-col,
body.force-mobile #main-area > .sidebar-backdrop,
body.force-mobile .footnote {
  display: none !important;
}
body.force-mobile #main-area {
  display: block;
  grid-template-columns: none !important;
}
body.force-mobile {
  background: #020203;
  /* The dashboard's body is display:flex;flex-direction:column. We override
     to plain block flow so #mobile-shell can be auto-margined and stays at
     a stable 430px width regardless of expand state. */
  display: block !important;
  flex-direction: initial !important;
  overflow-y: auto !important;
  height: auto !important;
  min-height: 100vh !important;
}
body.force-mobile #mobile-shell {
  display: block;
  width: 430px;
  max-width: 100vw;
  margin: 0 auto;
  min-height: 100vh;
  border-left: 1px solid #1c1c1f;
  border-right: 1px solid #1c1c1f;
  position: relative;
  flex: 0 0 auto;
  align-self: center;
}

@media (max-width: 768px) {
  body > #topbar,
  body > #main-area > #center-col,
  body > #main-area > .sidebar-backdrop,
  body > .footnote {
    display: none !important;
  }
  /* Mirror the body.force-mobile overrides so real phones (viewport <
     768px, no ?view=mobile) also get a scrollable page. Without this,
     desktop's body { overflow:hidden; height:100vh; display:flex } leaks
     through and the page is locked to one screenful. */
  body {
    background: #020203;
    display: block !important;
    flex-direction: initial !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh !important;
  }
  body > #main-area {
    display: block;
    grid-template-columns: none !important;
  }
  #mobile-shell {
    display: block;
    position: relative;
    width: 430px;
    max-width: 100vw;
    margin: 0 auto;
    min-height: 100vh;
    border-left: 1px solid #1c1c1f;
    border-right: 1px solid #1c1c1f;
  }
}

/* ─── Layout ──────────────────────────────────────────────── */
#mobile-shell {
  font-family: "Inter", -apple-system, sans-serif;
  background: #050507;
  color: #fafafa;
  min-height: 100vh;
  padding-bottom: 32px;
}

/* Tight brand-only topbar — score block moved into the scatter section. */
.m-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid #1c1c1f;
  background: #111114;
  position: sticky;
  top: 0;
  z-index: 30;
}
.m-topbar-logo { height: 18px; width: auto; color: #fafafa; display: block; flex: 0 0 auto; }
.m-topbar-project {
  font-size: 13px;
  font-weight: 600;
  color: #fafafa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* BEST SCORE block — lives in the scatter section header now. Same
   typography as the desktop's .stat-block. */
.m-score-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex: 0 0 auto;
  gap: 1px;
  line-height: 1;
}
.m-score-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.m-score-value {
  font-family: "JetBrains Mono", monospace;
  font-size: 22px;
  font-weight: 600;
  color: #fafafa;
  line-height: 1;
}
.m-score-delta {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: #22c55e;
}
.m-score-delta.neg { color: #ef4444; }
.m-score-sub {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: #71717a;
  margin-top: 2px;
}

/* Sticky scatter — holds the BEST SCORE block in the right of its header. */
.m-scatter {
  position: sticky;
  top: 48px;
  z-index: 28;
  background: #050507;
  border-bottom: 1px solid #1c1c1f;
  padding: 14px 14px 12px;
  height: 178px;
}
.m-scatter-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.m-scatter-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #71717a;
  padding-top: 8px;
}
.m-scatter-plot {
  width: 100%;
  height: 110px;
}
.m-scatter-plot svg { display: block; width: 100%; height: 100%; }

/* ─── Vertical node graph (single column) ────────────────── */
.m-graph {
  padding: 16px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.m-graph-step {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* Amber connector tick between spine steps */
.m-graph-step:not(:last-child)::after {
  content: "";
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  height: 20px;
  background: linear-gradient(180deg, rgba(255, 106, 42, 0.5), rgba(255, 106, 42, 0.15));
}

/* Spine card — full width, meaty */
.m-spine-card {
  background: #0c0c0e;
  border: 1px solid rgba(255, 106, 42, 0.3);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-tap-highlight-color: rgba(255, 106, 42, 0.12);
  background-image: linear-gradient(180deg, rgba(255, 106, 42, 0.04), transparent);
  transition: border-color 0.15s, background 0.15s;
}
.m-spine-card:active { border-color: #FF6A2A; background: #141416; }
/* Best card — slight amber glow */
.m-spine-card.best {
  border-color: rgba(255, 106, 42, 0.6);
  box-shadow: 0 0 24px rgba(255, 106, 42, 0.1);
  background-image: linear-gradient(180deg, rgba(255, 106, 42, 0.08), transparent);
}

.m-spine-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #1c1c1f;
}
.m-spine-id {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  color: #FF6A2A;
  background: rgba(255, 106, 42, 0.1);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.02em;
}
.m-spine-score-block { display: flex; align-items: baseline; gap: 6px; }
.m-spine-score {
  font-family: "JetBrains Mono", monospace;
  font-size: 20px;
  font-weight: 600;
  color: #fafafa;
  line-height: 1;
}
.m-spine-delta {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: #22c55e;
  text-transform: lowercase;
}
.m-spine-delta.neg { color: #ef4444; }
.m-spine-delta.zero { color: #52525b; }
.m-spine-hyp {
  font-size: 13px;
  color: #d4d4d8;
  line-height: 1.5;
}

/* Off-spine dot row */
.m-off {
  padding: 0 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.m-off-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #71717a;
}
.m-off-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #1c1c1f;
}
.m-off-dots {
  display: flex;
  flex-direction: row;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 4px 0 6px;
  scroll-snap-type: x proximity;
}
.m-off-dots::-webkit-scrollbar { display: none; }

/* Each off-spine dot — visible 8px square with a 32px tap target */
.m-off-dot {
  flex: 0 0 auto;
  width: 24px;
  height: 28px;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  scroll-snap-align: start;
}
.m-off-dot-glyph {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: #52525b;
  opacity: 0.55;
  transition: opacity 0.12s, transform 0.12s, background 0.12s;
}
.m-off-dot:hover .m-off-dot-glyph,
.m-off-dot:active .m-off-dot-glyph {
  opacity: 1;
  transform: scale(1.4);
  background: #FF6A2A;
}
.m-off-dot.failed .m-off-dot-glyph {
  background: #ef4444;
  opacity: 0.45;
}
.m-off-dot.failed:hover .m-off-dot-glyph,
.m-off-dot.failed:active .m-off-dot-glyph {
  opacity: 0.95;
  background: #ef4444;
}
.m-off-dot:focus-visible { outline: 2px solid #FF6A2A; outline-offset: 1px; border-radius: 4px; }

/* Long-press tooltip — floats above (or below) the touched dot */
.m-off-tip {
  position: fixed;
  z-index: 300;
  background: #18181b;
  border: 1px solid rgba(255, 106, 42, 0.4);
  border-radius: 6px;
  padding: 10px 12px;
  max-width: 260px;
  min-width: 180px;
  font-family: "Inter", sans-serif;
  color: #fafafa;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}
.m-off-tip.hidden { display: none; }
.m-off-tip-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.m-off-tip-id {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  color: #FF6A2A;
  background: rgba(255, 106, 42, 0.1);
  padding: 1px 5px;
  border-radius: 3px;
}
.m-off-tip-score {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 600;
  color: #fafafa;
}
.m-off-tip-delta {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: #22c55e;
}
.m-off-tip-delta.neg { color: #ef4444; }
.m-off-tip-delta.zero { color: #52525b; }
.m-off-tip-hyp {
  font-size: 11.5px;
  line-height: 1.5;
  color: #d4d4d8;
}
.m-off-tip-hint {
  margin-top: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  color: #52525b;
  letter-spacing: 0.04em;
}

.m-foot {
  padding: 12px 14px 0;
  border-top: 1px solid #1c1c1f;
  margin-top: 16px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: #52525b;
  line-height: 1.5;
}

/* ─── Expand button injected into drawer header on mobile ─── */
.m-expand-btn {
  background: transparent;
  border: none;
  color: #71717a;
  width: 32px;
  height: 32px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0;
  margin: 0 2px;
  transition: color 0.12s, background 0.12s;
}
.m-expand-btn:hover { color: #fafafa; background: rgba(255, 255, 255, 0.04); }
.m-expand-btn:focus-visible { outline: 2px solid #FF6A2A; outline-offset: 2px; }
.m-expand-btn svg { display: block; }
/* Hide the expand button on desktop — only relevant on mobile */
@media (min-width: 769px) {
  body:not(.force-mobile) .m-expand-btn { display: none; }
}

/* When expanded, hide the scatter so the detail can use that space too */
body.m-detail-expanded .m-scatter { display: none; }

/* ─── Detail panel: replaces the graph in place ──────────── */
/* When the sidebar (#sidebar) is open AND we're on mobile, hide the
   graph + foot and slot the sidebar into their space.
   mobile.js toggles body.m-detail-open via a MutationObserver on #sidebar. */
body.m-detail-open .m-graph,
body.m-detail-open .m-foot {
  display: none;
}

/* Real mobile (<768px) — sidebar fills the area below the sticky scatter */
@media (max-width: 768px) {
  body.m-detail-open #main-area > #sidebar:not(.hidden) {
    position: fixed !important;
    top: 226px !important; /* topbar 48 + scatter 178 */
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    z-index: 50 !important;
    background: #050507 !important;
    border-left: none !important;
    transform: none !important;
    overflow-y: auto !important;
    transition: top 0.18s ease;
  }
  /* Expanded: slide up to cover the scatter too */
  body.m-detail-open.m-detail-expanded #main-area > #sidebar:not(.hidden) {
    top: 48px !important;
  }
}

/* Force-mobile preview — sidebar fills the area within the 430px frame */
body.force-mobile.m-detail-open #main-area > #sidebar:not(.hidden) {
  position: fixed !important;
  top: 226px !important;
  bottom: 0 !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: 430px !important;
  max-width: 100vw !important;
  z-index: 50 !important;
  background: #050507 !important;
  border-left: 1px solid #1c1c1f !important;
  border-right: 1px solid #1c1c1f !important;
  overflow-y: auto !important;
  transition: top 0.18s ease;
}
body.force-mobile.m-detail-open.m-detail-expanded #main-area > #sidebar:not(.hidden) {
  top: 48px !important;
}

/* Strong reset on the sidebar at mobile breakpoints — wipe the desktop
   width var / center-peek box-shape / inline resize state. Applies whether
   or not the dashboard added .peek-center, so the layout can't drift. */
@media (max-width: 768px) {
  body #main-area > #sidebar,
  body #main-area > #sidebar.peek-center {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
  }
  body #sidebar-backdrop { display: none !important; }
}
body.force-mobile #main-area > #sidebar,
body.force-mobile #main-area > #sidebar.peek-center {
  width: 430px !important;
  max-width: 100vw !important;
  min-width: 0 !important;
  height: auto !important;
  max-height: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  margin: 0 !important;
}
body.force-mobile #sidebar-backdrop { display: none !important; }

/* Drawer chrome on mobile: bigger close target, hide peek/diff-mode toggles */
@media (max-width: 768px) {
  #sidebar .drawer-close-btn,
  #sidebar .close-btn,
  #sidebar button[onclick*="close"] {
    min-width: 44px;
    min-height: 44px;
  }
  .drawer-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Drop peek/centered-mode toggle — mobile only has one mode */
  #sidebar .drawer-peek-toggle { display: none !important; }
  /* Drop diff Split/Unified switcher — unified is forced */
  #sidebar .diff-view-btn { display: none !important; }
}
body.force-mobile #sidebar .drawer-close-btn,
body.force-mobile #sidebar .close-btn,
body.force-mobile #sidebar button[onclick*="close"] {
  min-width: 44px;
  min-height: 44px;
}
body.force-mobile .drawer-tabs { overflow-x: auto; }
body.force-mobile #sidebar .drawer-peek-toggle { display: none !important; }
body.force-mobile #sidebar .diff-view-btn { display: none !important; }
