/* App shell & page regions — handoff §4, §6 */
* { box-sizing: border-box; }

html, body, #react-entry-point {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--ink-900);
  background: var(--surface-app);
}

button, input, select, textarea { font: inherit; }

/* ---- top navigation ---- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr auto;
  align-items: center;
  padding: 0 var(--space-5);
  background: var(--brand-700);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

/* ---- dashboard workspace: sidebar / main / details ---- */
#layout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-4);
  min-height: calc(100vh - var(--topbar-height));
}

#sidebar {
  position: sticky;
  top: calc(var(--topbar-height) + var(--space-4));
  max-height: calc(100vh - var(--topbar-height) - 2 * var(--space-4));
  overflow-y: auto;
  width: var(--sidebar-width);
  flex: none;
  padding: var(--space-4);
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  font-size: 13.5px;
}

#main {
  flex: 1;
  min-width: 0;
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-3);
  /* graph fills the visual viewport under the top bar */
  height: calc(100vh - var(--topbar-height) - 2 * var(--space-4));
  min-height: 420px;
}
#ts-graph, #main .dash-graph { height: 100%; }

#framepanel {
  width: var(--details-width);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
#framepanel.wide { width: 33vw; }
#framepanel.hidden { display: none; }

/* ---- secondary pages share the warm background; cards do the framing.
       Content is centered in the viewport. ---- */
#al-wrap, #sv-wrap {
  display: flex; gap: var(--space-4); align-items: flex-start;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
}
#tr-wrap {
  display: flex; justify-content: center;
  padding: var(--space-6) var(--space-4);
}

/* ---- segmentation page: edit toolbar on top, image box + graph below ---- */
#seg-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  height: calc(100vh - var(--topbar-height));
}
/* edit toolbar — above the image, shown only in correct-leaves mode */
#seg-edit-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2);
  flex: none;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}
#seg-edit-bar .nav-item, #seg-edit-bar .btn-primary { height: 30px; padding: 0 10px; }
/* seg-page buttons sit on a light background — nav-item's white text would be
   invisible, so give them dark text on a light chip */
#seg-step .nav-item, #seg-edit-bar .nav-item {
  color: var(--ink-900);
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}
#seg-step .nav-item:hover, #seg-edit-bar .nav-item:hover {
  background: var(--surface-app);
}
/* body: image box (hugs 4:3) + graph filling the rest */
#seg-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
}
#seg-main {
  flex: 0 0 auto;
  height: 100%;
  aspect-ratio: 384 / 288;
  max-width: 72%;
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
}
#seg-main #frame-img {
  width: 100%; height: 100%;
  object-fit: contain;            /* proportional; JS microscope handles any pad */
  display: block;
}
#seg-main #seg-editor, #seg-main .dash-graph { width: 100%; height: 100%; }
/* graph column: takes all remaining space */
#seg-frame {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
#seg-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  flex: none;
}
#seg-controls .dash-dropdown { min-width: 110px; }
#seg-step { display: flex; gap: 4px; }
#seg-step .nav-item { height: 30px; padding: 0 12px; }
#seg-frame #ts-graph, #seg-frame .dash-graph { flex: 1; height: 100%; min-height: 0; }
