/* Base: reset, the app shell (rail, top bar, breadcrumb, content, copilot dock), and the layout
 * rules. Hue carries state only; nothing here introduces a new colour. Widths that vary at run time
 * go through CSS custom properties set with setProperty (no style= attribute, CSP style lint). */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: var(--t-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
ul { margin: 0; padding: 0; list-style: none; }
code, .mono { font: var(--t-code); }
/* long identifiers wrap at the dots (design 4.5) */
.wrapid { word-break: break-word; }

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--r-1);
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: var(--z-toast);
  background: var(--surface); color: var(--link); padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r-2);
}
.skip-link:focus { left: var(--sp-2); top: var(--sp-2); }

.boot { padding: var(--sp-16) var(--gutter); color: var(--ink-3); font: var(--t-body); }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --------------------------------------------------------------- the shell */
.shell { display: grid; grid-template-columns: auto 1fr; min-height: 100vh; }
.shell[data-rail="collapsed"] { --rail-current: var(--rail-w-collapsed); }

/* rail */
.rail {
  grid-column: 1; width: var(--rail-w); background: var(--surface);
  border-right: 1px solid var(--line); z-index: var(--z-rail);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: var(--sp-3); gap: var(--sp-1);
}
.shell[data-rail="collapsed"] .rail { width: var(--rail-w-collapsed); align-items: center; }
.rail-brand {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2) var(--sp-4);
}
.rail-mark {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: var(--r-2);
  background: var(--accent); color: var(--on-accent); font: var(--t-h3);
  display: grid; place-items: center;
}
.rail-brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.rail-brand-text b { font: var(--t-h3); }
.rail-brand-text span { font: var(--t-caption); color: var(--ink-3); }
.shell[data-rail="collapsed"] .rail-brand-text,
.shell[data-rail="collapsed"] .rail-link .lbl { display: none; }

.rail-link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-2);
  color: var(--ink-2); font: var(--t-body); position: relative;
}
.rail-link:hover { background: var(--surface-2); text-decoration: none; }
.rail-link[aria-current="page"] { background: var(--sel-bg); color: var(--ink); font: var(--t-body-strong); }
.rail-link .ic { flex: 0 0 20px; }
.rail-link .count {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 var(--sp-1);
  border-radius: var(--r-pill); background: var(--decision-bg); color: var(--decision-ink);
  font: var(--t-label); display: grid; place-items: center;
}
.shell[data-rail="collapsed"] .rail-link .count {
  position: absolute; top: 2px; right: 2px; margin: 0;
}

/* main column */
.main { grid-column: 2; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--gutter); background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: var(--z-topbar);
}
.topbar .title { font: var(--t-h1); }
.topbar .spacer { flex: 1 1 auto; }
.icon-btn {
  width: var(--control-h); height: var(--control-h); border-radius: var(--r-2);
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.crumbs {
  height: 32px; flex: 0 0 32px; display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--gutter); font: var(--t-caption); color: var(--ink-3);
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.crumbs a { color: var(--ink-3); }
.crumbs .sep { color: var(--line-strong); }
.crumbs [aria-current="page"] { color: var(--ink-2); }

.content-row { display: flex; flex: 1 1 auto; min-height: 0; }
.content {
  flex: 1 1 auto; min-width: 0; padding: var(--gutter);
  container-type: inline-size; overflow-x: hidden;
}

/* copilot dock */
.dock {
  flex: 0 0 var(--dock-w); width: var(--dock-w); border-left: 1px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column; min-height: 0;
}
.dock[hidden] { display: none; }

@container (max-width: 1000px) {
  .home-readouts { grid-template-columns: 1fr 1fr; }
}
@container (max-width: 940px) {
  .master-detail { grid-template-columns: 1fr; }
  .lineage-body { grid-template-columns: 1fr; }
}

/* narrow viewport: rail hides behind the menu button, gutters tighten */
@media (max-width: 900px) {
  :root { --gutter: 16px; --card-pad: 16px; }
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform var(--dur-3) var(--ease-enter); box-shadow: var(--e-2);
  }
  .shell[data-rail="open"] .rail { transform: translateX(0); }
  .main { grid-column: 1; }
  .dock { position: fixed; inset: 0; z-index: var(--z-drawer); width: 100%; }
}
