/* =========================
   Soma3D Viewer v2 – Calm UI (Hybrid Option B)
   Header aligned to site menu bar feel
   ========================= */

:root{
  /* Core palette (restrained) */
  --bg: #ffffff;
  --surface: #f8fafc;          /* very light slate */
  --surface-2: #f1f5f9;        /* slightly stronger */
  --text: #0f172a;             /* slate-900 */
  --muted: #64748b;            /* slate-500 */
  --border: #e2e8f0;           /* slate-200 */

  /* Brand accent (use sparingly) */
  --accent: #1d4ed8;           /* blue-700-ish */
  --accent-soft: rgba(29, 78, 216, 0.12);
  --focus: rgba(29, 78, 216, 0.35);

  /* “Danger” hint for Clear (hover only) */
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.12);

  /* Geometry */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);

  /* Layout */
  --panel-width: clamp(320px, 28vw, 440px);
  --hud-gap: 12px;

  /* Header (match site menu feel) */
  --header-bg: #000000;
  --header-border: rgba(255, 255, 255, 0.10);
  --header-text: rgba(255, 255, 255, 0.92);
  --header-muted: rgba(255, 255, 255, 0.68);
  --header-control-bg: rgba(255, 255, 255, 0.08);
  --header-control-border: rgba(255, 255, 255, 0.14);
  --header-control-hover: rgba(255, 255, 255, 0.12);
}

/* Embed selection label shown in header (pill badge) */
.embed-struct-label {
  display: none;
  margin-left: 0;
  align-items: center;

  padding: 6px 12px;
  border-radius: 999px;

  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);

  color: rgba(255, 255, 255, 0.92);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.15px;

  line-height: 1;              /* prevents vertical drift */
  white-space: nowrap;
  max-width: 52vw;
  overflow: hidden;
  text-overflow: ellipsis;
}



/* ============ Global, no page scroll ============ */
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Montserrat", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);

  /* IMPORTANT: prevent white side gutters in iframe */
  background: #000;
}

/* App layout: header + viewer fills viewport */
#app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

/* ============ Header (aligned with site menu bar) ============ */
/* ============ Header (aligned with site menu bar, full width, no seams) ============ */
header {
  background: var(--header-bg);
  color: var(--header-text);

  position: sticky;
  top: 0;
  z-index: 10;

  width: 100%;

  /* Remove divider seams */
  border: none;
  box-shadow: none;

  /* Full-width bar layout */
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;

  /* IMPORTANT: no max-width centering */
  max-width: none;
  margin: 0;
}

/* Inner header content: same rhythm as .topnav */
header > * {
  box-sizing: border-box;
}

/* Make the header content look like your .topnav container */
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;  /* left | center | right */
  align-items: center;

  padding: 10px 18px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Brand */
header .brand {
  justify-self: start;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--header-text);
}

header .subtle {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--header-muted);
}

/* Controls group */
header .controls {
  justify-self: end;
  display: flex;
  gap: 12px;
  align-items: center;
}

header .ctl {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  min-width: 160px;
  position: relative;
}

header .ctl span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--header-muted);
  letter-spacing: 0.2px;
}

/* Dropdowns (native select, styled to match dark header) */
header select.pill {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  padding: 8px 34px 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--header-control-border);
  background: var(--header-control-bg);
  color: var(--header-text);

  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;

  box-shadow: none;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

/* ---------- Select dropdown (opened list) ---------- */

/* Force readable dropdown options */
header select.pill option {
  background: #ffffff;
  color: #0f172a;
  font-weight: 600;
}

/* Selected option */
header select.pill option:checked {
  background: #e2e8f0;
  color: #0f172a;
}

#embedSelectionLabelHeader {
  justify-self: center;
}


/* Dropdown chevron */
header .ctl::after{
  content: "▾";
  position: absolute;
  right: 12px;
  bottom: 9px;
  color: var(--header-muted);
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0.95;
}

header select.pill:hover:not(:disabled){
  background: var(--header-control-hover);
}

header select.pill:focus{
  outline: none;
  border-color: rgba(29,78,216,0.55);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.28);
}

header select.pill:disabled{
  opacity: 0.55;
  cursor: not-allowed;
}

/* ============ Viewer area ============ */
#viewer {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #000; /* model canvas backdrop */
}

#canvas, #canvas:focus {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* ============ HUD buttons ============ */
#hud {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 10px;
  z-index: 30;
}

#hud button {
  border: 1px solid rgba(226, 232, 240, 0.85);
  border-radius: 999px;
  padding: 8px 12px;

  background: rgba(248, 250, 252, 0.88);
  backdrop-filter: blur(10px);
  color: var(--text);

  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.15px;

  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.08s ease,
    box-shadow 0.15s ease,
    color 0.15s ease;
}

#hud button:hover:not(:disabled){
  background: rgba(241, 245, 249, 0.95);
  border-color: rgba(148, 163, 184, 0.8);
}

#hud button:active:not(:disabled){
  transform: translateY(1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

#hud button:focus{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus), var(--shadow-soft);
}

#hud button:disabled{
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---------- Isolate active state (high contrast, calm) ---------- */
#isolate.active,
#isolate[aria-pressed="true"]{
  background: rgba(255, 255, 255, 0.95); /* stay visible on black */
  border-color: rgba(105, 194, 197, 0.55);

  box-shadow:
    0 0 0 7px rgba(105, 194, 197, 0.55),
    var(--shadow-soft);

  color: var(--text);
}

/* Clear: only warn on hover (keeps calm UI) */
#clear:hover:not(:disabled){
  background: var(--danger-soft);
  border-color: rgba(185, 28, 28, 0.35);
  color: var(--danger);
}

/* ============ Anatomy Explorer Panel ============ */
#anatomyExplorerPanel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: var(--panel-width);

  display: grid;
  grid-template-rows: auto 1fr;

  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);

  border-left: 1px solid var(--border);
  overflow: hidden;

  z-index: 20;
  transition: transform 0.2s ease;
}

#anatomyExplorerPanel[data-open="false"] {
  transform: translateX(100%);
}

#anatomyExplorerPanel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;

  padding: 12px 14px;

  border-bottom: 1px solid var(--border);
  background: rgba(248, 250, 252, 0.92);

  font-weight: 800;
  letter-spacing: 0.15px;
}

/* ============ Anatomy Explorer Search ============ */

#anatomyExplorerPanel .panel-header {
  gap: 10px;
}

#anatomyExplorerPanel .panel-title {
  flex: 1;
  white-space: nowrap;
}

/* Search input */
#anatomyExplorerSearch {
  flex: 1.2;
  max-width: 220px;

  padding: 6px 10px;
  border-radius: 999px;

  border: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);

  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;

  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

#anatomyExplorerSearch::placeholder {
  color: var(--muted);
  font-weight: 500;
}

#anatomyExplorerSearch:hover {
  background: #ffffff;
}

#anatomyExplorerSearch:focus {
  border-color: rgba(29, 78, 216, 0.45);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.28);
  background: #ffffff;
}

/* Dark header contrast safety (just in case panel bg changes later) */
#anatomyExplorerSearch {
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
}

#anatomyExplorerPanel .panel-body {
  overflow-y: auto;
  overflow-x: hidden;              /* prevents any horizontal weirdness */
  scrollbar-gutter: stable;        /* reserves scrollbar space (Chrome/Edge ok) */
  padding: 10px 10px 14px 8px;     /* slightly more right padding than left */
  padding-right: 18px;   /* give pills breathing room on the right */
}

/* ============ Explorer toggle (floating) ============ */
#anatomyExplorerToggleFloating {
  position: absolute;
  top: 14px;
  right: calc(var(--panel-width) + var(--hud-gap));
  z-index: 25;

  border-radius: 999px;
  border: 1px solid rgba(226, 232, 240, 0.85);

  background: rgba(248, 250, 252, 0.88);
  backdrop-filter: blur(10px);

  padding: 8px 12px;
  cursor: pointer;

  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;

  box-shadow: var(--shadow-soft);
  transition:
    right 0.2s ease,
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.08s ease,
    box-shadow 0.15s ease;
}

#anatomyExplorerToggleFloating:hover {
  background: rgba(241, 245, 249, 0.95);
  border-color: rgba(148, 163, 184, 0.8);
}

#anatomyExplorerToggleFloating:active{
  transform: translateY(1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

#anatomyExplorerToggleFloating:focus{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus), var(--shadow-soft);
}

#anatomyExplorerPanel[data-open="false"] + #anatomyExplorerToggleFloating {
  right: 14px;
}

/* ============ Explorer (Anatomy Explorer) styling ============ */

.ax-node {
  margin: 2px 0;
}

.ax-row{
  display: grid;
  grid-template-columns: 22px 20px minmax(0, 1fr); /* IMPORTANT */
  align-items: center;
  gap: 8px;

  padding: 3px 6px 3px calc(4px + (var(--depth) * 10px));
  border-radius: 12px;
}

.ax-twisty{
  width: 22px;
  height: 22px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);

  font-family: inherit;
  font-weight: 800;
  line-height: 1;

  cursor: pointer;
  display: grid;
  place-items: center;

  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.08s ease;
}

.ax-twisty:hover{
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.25);
  color: var(--text);
}

.ax-twisty:active{
  transform: translateY(1px);
}

.ax-twisty:focus{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.ax-twisty-spacer{
  width: 22px;
  height: 22px;
  display: block;
}

.ax-check{
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.ax-item{
  box-sizing: border-box;   /* <--- ADD THIS */
  min-width: 0;
  width: 100%;
  text-align: left;

  background: transparent;
  color: var(--text);

  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;

  padding: 6px 10px;
  line-height: 1.25;

  border-radius: 12px;
  border: 1px solid transparent;

  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 650;
  letter-spacing: 0.1px;

  cursor: pointer;

  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.ax-item:hover{
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.18);
}

.ax-item:active{
  transform: translateY(1px);
}

.ax-item:focus{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.ax-item.ax-system{
  font-weight: 800;
  letter-spacing: 0.2px;
  background: rgba(248, 250, 252, 0.65);
  border-color: rgba(226, 232, 240, 0.7);
}

.ax-item.active{
  background-color: rgba(0, 180, 90, 0.18);
  border-color: rgba(0, 180, 90, 0.22);
}

.ax-item.hovered:not(.active){
  background-color: rgba(0, 220, 255, 0.18);
  border-color: rgba(0, 220, 255, 0.22);
}

.ax-children{
  margin: 2px 0 6px 0;
  padding-left: 2px;
}

/* =====================================================================
   Share feedback toast (calm, unobtrusive)
   ===================================================================== */

#shareToast{
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(6px);

  padding: 10px 14px;
  border-radius: 999px;

  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;

  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.15px;

  box-shadow: var(--shadow-soft);
  z-index: 9999;

  opacity: 0;
  pointer-events: none;

  transition:
    opacity 160ms ease,
    transform 160ms ease;
}
