/* ===== layout: the application shell =====
 *
 * A fixed three-part frame — command bar across the top, an icon rail down the
 * left, and the routed view filling the rest. The rail persists across routes
 * so the operator never loses their place; only `#view` is replaced.
 */

/* `minmax(0, 1fr)` rather than `1fr`: a bare `1fr` floors at the column's
 * min-content, and the command bar spans both columns — so a crowded bar would
 * widen the grid past the window and push the map off-screen. */
#shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: grid;
  grid-template-rows: var(--topbar) 1fr;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  grid-template-areas:
    "top top"
    "rail view";
}

/* ---------- command bar ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s5);
  padding: 0 var(--s5) 0 var(--s4);
  border-bottom: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
}
.brand svg {
  width: 32px;
  height: 32px;
  flex: none;
}
.brand .name {
  font-family: var(--disp);
  font-weight: 700;
  letter-spacing: 2.4px;
  font-size: var(--fs-lead);
  line-height: 1;
}
.brand .name span {
  color: var(--accent);
}
.brand .tag {
  font-size: var(--fs-micro);
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 4px;
}

.topmeta {
  display: flex;
  align-items: center;
  gap: var(--s5);
  min-width: 0;
  overflow: hidden;
}
/* On a narrow window the descriptive readouts give way; worker state, jobs and
 * accelerator temperature are the ones an operator is actually watching. */
@media (max-width: 1340px) {
  .topmeta .readout.optional {
    display: none;
  }
}
.readout {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.readout b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-small);
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- icon rail ---------- */
.rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s1);
  padding: var(--s3) 0;
  border-right: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(16px);
}
.rail a {
  position: relative;
  width: 56px;
  padding: var(--s2) 0 7px;
  display: grid;
  justify-items: center;
  gap: 5px;
  border-radius: var(--r-md);
  color: var(--ink-3);
  transition: color 0.16s var(--ease), background 0.16s var(--ease);
}
.rail a svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.rail a span {
  font-size: var(--fs-micro);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  font-weight: 600;
}
.rail a:hover {
  color: var(--ink);
  background: var(--surface-2);
}
.rail a.on {
  color: var(--accent);
  background: var(--accent-wash);
}
/* the active marker is a rail edge, not a colour change alone */
.rail a.on::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
/* Setup used to be pinned to the bottom with a flex spacer. At shorter window
 * heights it ended up off-screen — a navigation item nobody could reach — so
 * every destination now sits in the normal flow where it is always visible. */
.rail .spacer {
  flex: 1;
}

/* If the rail ever does outgrow its column, scroll it rather than clip it. */
.rail {
  overflow-y: auto;
}

/* ---------- routed view ---------- */
#view {
  grid-area: view;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Operations: a control column beside the map theatre. */
.ops {
  height: 100%;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 0;
}
.ops .panel {
  border-right: 1px solid var(--stroke);
  background: var(--surface);
  backdrop-filter: blur(16px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s4);
}
.theatre {
  position: relative;
  min-width: 0;
}

/* Document-style views (jobs, database, settings) share one scroll page. */
.page {
  height: 100%;
  overflow-y: auto;
  padding: var(--s5) var(--gutter, var(--s6)) var(--s6);
}
.page > header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s5);
}
.page > header p {
  color: var(--ink-2);
  margin-top: 6px;
  max-width: 66ch;
}

.grid-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s3);
  margin-bottom: var(--s5);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: var(--s4);
  align-items: start;
}

@media (max-width: 1180px) {
  .split {
    grid-template-columns: 1fr;
  }
  .ops {
    grid-template-columns: 340px 1fr;
  }
}

/* Long values (file paths) wrap inside their column instead of widening the page, and a grid
 * column may shrink below its content. Found by lean/design/check_design.py at 1181 px. */
.split > * {
  min-width: 0;
  /* a column that is itself a stack of cards: its one track may shrink below its content too */
  grid-template-columns: minmax(0, 1fr);
}
.split > * > * {
  min-width: 0;
}
.kv dd,
.kv dt {
  min-width: 0;
  overflow-wrap: anywhere;
}
/* The map's search bar never exceeds the map; where the map is narrow the readout drops below
 * it instead of sitting on top of it (found at 760 px). */
.searchbar {
  max-width: calc(100% - 28px);
}
@media (min-width: 760px) and (max-width: 1100px) {
  .hud {
    top: 66px;
  }
}
/* A status note beside buttons may hold a long path: it shrinks and wraps, it never pushes the
 * row past the card (found on Settings at 1181 px). */
.btnrow > .hint {
  min-width: 0;
  flex: 0 1 auto;
  overflow-wrap: anywhere;
}
