/* ═══════════════════════════════════════════════════
   BASE
════════════════════════════════════════════════════ */
:root {
  --bg:       #0a0f1d;
  --panel:    #11192d;
  --panel-2:  #18233d;
  --panel-3:  #223154;
  --text:     #edf3ff;
  --muted:    #aeb8d2;
  --border:   rgba(255,255,255,0.08);
  --accent:   #8ab4ff;
  --accent-2: #7ee7d4;
  --shadow:   0 16px 40px rgba(0,0,0,0.32);
  --r:        14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  overflow-x: hidden;
  height: 100%;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select { font: inherit; color: var(--text); }

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover { background: var(--panel-3); }
button:disabled { opacity: 0.38; pointer-events: none; }

input[type="search"],
select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.7rem 0.85rem;
  width: 100%;
  outline: none;
}
input[type="range"] {
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

h1, h2, h3 { line-height: 1.25; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.eyebrow {
  color: var(--accent-2);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.small-text { font-size: 0.88rem; margin-top: 0.45rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

/* ═══════════════════════════════════════════════════
   DESKTOP LAYOUT  (>860px)
════════════════════════════════════════════════════ */
.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
  max-width: 100vw;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #0f172b, #0b1121);
  border-right: 1px solid var(--border);
  padding: 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}
.brand h1 { font-size: 1.35rem; margin: 0.2rem 0 0.5rem; }
.brand .muted { font-size: 0.9rem; }
.controls { display: grid; gap: 0.8rem; margin: 1rem 0 1.1rem; }
.controls label { display: grid; gap: 0.3rem; }
.controls span { color: var(--muted); font-size: 0.9rem; }

.series-list { display: grid; gap: 0.6rem; }
.series-card {
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.85rem;
}
.series-card:hover { background: var(--panel-2); }
.series-card.active {
  border-color: rgba(138,180,255,.85);
  box-shadow: inset 0 0 0 1px rgba(138,180,255,.2);
}
.series-card .small { color: var(--accent-2); font-size: 0.82rem; }
.series-card h3 { margin: 0.2rem 0 0.35rem; font-size: 0.98rem; }
.series-card p { color: var(--muted); font-size: 0.88rem; }

/* Desktop main */
.main { min-width: 0; padding: 1.2rem; overflow-x: hidden; }

/* Desktop topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.topbar h2 { font-size: 1.6rem; margin: 0.2rem 0 0.4rem; }
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.action-pill, .links a {
  padding: 0.42rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  white-space: nowrap;
  font-size: 0.9rem;
}
.action-pill { cursor: pointer; }
.action-pill:hover, .links a:hover { background: var(--panel-3); text-decoration: none; }
.action-pill.is-active {
  border-color: rgba(138,180,255,.85);
  box-shadow: inset 0 0 0 1px rgba(138,180,255,.25);
}

/* Stage */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
}

/* Hero */
.hero {
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: stretch;
  min-height: 520px;
}
.hero-image-stage {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#mainImage {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  border-radius: 18px;
  transform: translate3d(0,0,0) scale(1);
  will-change: transform;
}
.hero.zoomed .hero-image-stage { cursor: grab; }
.hero.is-panning .hero-image-stage { cursor: grabbing; }

.hero-nav {
  position: absolute;
  z-index: 3;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(12,18,34,.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.14);
  font-size: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
}
.hero-nav:hover { background: rgba(30,46,80,.9); }
.hero-nav-prev { left: 14px; }
.hero-nav-next { right: 14px; }

.hero-overlay-label {
  position: absolute;
  left: 14px; right: 14px; bottom: 14px;
  z-index: 2;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  background: rgba(9,13,23,.72);
  color: #eef3ff;
  font-size: 0.88rem;
  line-height: 1.35;
  pointer-events: none;
}

/* Sidepanel */
.sidepanel {
  display: grid;
  gap: 1rem;
  align-content: start;
}
.sidepanel .card { padding: 1rem; }
.sidepanel h3 { font-size: 0.95rem; margin-bottom: 0.65rem; }
.button-row { display: flex; gap: 0.5rem; }
.button-row button { flex: 1; padding: 0.7rem 0.4rem; font-size: 0.9rem; }
#sliceSlider { margin-top: 0.85rem; }
.contact-preview { width: 100%; display: block; border-radius: 10px; background: #000; margin-top: 0.1rem; }

/* Thumbnails (desktop grid) */
.thumbs-section { margin-top: 1rem; padding: 1rem; }
.thumbs-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.thumbs-head h3 { font-size: 1rem; }
.thumb-strip-row { display: flex; align-items: center; gap: 0.5rem; }
.thumb-nav-btn { display: none; } /* hidden desktop */
.thumb-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.65rem;
}
.thumb {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d1427;
  padding: 0.35rem;
  cursor: pointer;
}
.thumb.active {
  border-color: rgba(138,180,255,.9);
  box-shadow: inset 0 0 0 1px rgba(138,180,255,.3);
}
.thumb img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  background: #000;
}
.thumb-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.25rem;
}
.empty { color: var(--muted); padding: 1rem 0.25rem; }

/* Mobile-specific elements — hidden on desktop */
.mobile-topbar   { display: none; }
.mobile-slice-bar { display: none; }

/* sq-btn used in mobile toolbar */
.sq-btn {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 1.3rem;
  padding: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

/* Study pills (rendered inside mobile-topbar) */
.study-pills { display: flex; gap: 8px; }
.study-pill {
  flex: 1;
  height: 44px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.study-pill.active {
  background: var(--panel-3);
  border-color: rgba(138,180,255,.8);
  color: var(--accent);
}

/* ── Fullscreen ────────── */
#heroViewer:fullscreen {
  width: 100vw; height: 100vh;
  border-radius: 0;
}
#heroViewer:fullscreen #mainImage,
#heroViewer:fullscreen .hero-image-stage { border-radius: 0; }

/* ── Doctor / Review mode ─ */
body.review-mode .sidebar,
body.review-mode .sidepanel .card:last-child { display: none; }
body.review-mode .app-shell { grid-template-columns: 1fr; }
body.review-mode .stage { grid-template-columns: 1fr; }
body.review-mode .hero { min-height: min(88vh, 960px); }
body.review-mode .sidepanel { grid-template-columns: repeat(2, 1fr); }
body.review-mode .thumbs-section { display: none; }

/* ═══════════════════════════════════════════════════
   MOBILE  ≤ 860px
   Stacked layout — no sidebar, dedicated controls
════════════════════════════════════════════════════ */
@media (max-width: 860px) {

  /* ── Layout ── */
  .app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    min-height: 100dvh;
  }
  .sidebar   { display: none; }
  .main {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    padding: 0;
    overflow-x: hidden;
    flex: 1;
  }

  /* ── Mobile topbar ── */
  .mobile-topbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    width: 100%;
    flex: 0 0 auto;   /* don't grow */
  }
  .topbar { display: none; }

  /* Study pills — full row */
  .study-pills { width: 100%; }

  /* Series picker row: ‹ [select] › */
  .series-picker-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
  }
  .series-picker-row select {
    flex: 1;
    min-width: 0;         /* allow shrinking */
    height: 44px;
    padding: 0 8px;
    font-size: 0.9rem;
    border-radius: 10px;
  }

  /* ── Stage: hero only, grows to fill remaining height ── */
  .stage {
    display: block;
    width: 100%;
    flex: 1;          /* take all leftover height in .main flex column */
    min-height: 0;
  }
  .sidepanel { display: none; }

  /* ── Hero fills the full stage ── */
  .hero {
    width: 100%;
    height: 100%;     /* fill .stage */
    min-height: 240px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  #mainImage  { border-radius: 0; }

  .hero-nav {
    width: 52px;
    height: 52px;
    top: 50%;
    transform: translateY(-50%);
  }
  .hero-nav-prev { left: 8px; }
  .hero-nav-next { right: 8px; }
  .hero-overlay-label {
    left: 8px; right: 8px; bottom: 8px;
    font-size: 0.82rem;
  }

  /* ── Mobile slice bar ── */
  .mobile-slice-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    width: 100%;
    flex: 0 0 auto;   /* don't grow, keep fixed height */
  }
  .mobile-slice-bar input[type="range"] {
    flex: 1;
    min-width: 0;
  }
  .slice-count {
    flex: 0 0 auto;
    min-width: 44px;
    text-align: right;
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
  }

  /* ── Thumbnails ── */
  .thumbs-section {
    width: 100%;
    flex: 0 0 auto;   /* don't grow, keep fixed height */
    margin: 0;
    padding: 8px 12px 12px;
    border-radius: 0;
    border-top: 1px solid var(--border);
    background: var(--panel);
    border-left: none;
    border-right: none;
    box-shadow: none;
  }
  .thumbs-head { display: none; }  /* save vertical space */

  .thumb-nav-btn { display: flex; } /* show flanking buttons */

  .thumb-strip-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
  }
  .thumb-grid {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 2px 2px 6px;
    /* hide scrollbar but keep scroll */
    scrollbar-width: none;
  }
  .thumb-grid::-webkit-scrollbar { display: none; }

  .thumb {
    flex: 0 0 82px;
    width: 82px;
    scroll-snap-align: start;
    border-radius: 10px;
    padding: 4px;
  }
  .thumb img {
    width: 74px;
    height: 74px;
    aspect-ratio: auto;
    border-radius: 6px;
  }
  .thumb-label { font-size: 0.78rem; }

  /* ── Review mode on mobile ── */
  body.review-mode .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
  }
  body.review-mode .hero { height: 100%; min-height: 300px; }
  body.review-mode .mobile-slice-bar {
    position: sticky;
    bottom: 0;
    z-index: 10;
  }
  body.review-mode .thumbs-section { display: none; }
}

/* ── Extra small phones ≤ 420px ── */
@media (max-width: 420px) {
  .mobile-topbar { padding: 8px 10px; gap: 6px; }
  .hero { min-height: 200px; }
  .sq-btn { width: 40px; height: 40px; flex: 0 0 40px; font-size: 1.15rem; }
  .thumb { flex: 0 0 72px; width: 72px; }
  .thumb img { width: 64px; height: 64px; }
  .study-pill { font-size: 0.88rem; }
  .series-picker-row select { font-size: 0.85rem; }
}
