:root {
  --brand-primary: #0079bd;
  --brand-primary-dark: #005b8f;
  --brand-accent: #f58220;
  --ink: #17232d;
  --muted: #5c6872;
  --line: #d8dee3;
  --line-strong: #b8c2ca;
  --canvas: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --success: #207a4b;
  --success-soft: #e6f4ec;
  --warning: #9b5d00;
  --warning-soft: #fff2d8;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --focus: #174ea6;
  --shadow: 0 12px 32px rgba(23, 35, 45, 0.08);
  --radius: 10px;
  --font-ui: Aptos, "IBM Plex Sans", "Trebuchet MS", sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--canvas); font-family: var(--font-ui); font-size: 15px; line-height: 1.5; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { color: inherit; }
a { color: var(--brand-primary-dark); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.35rem; font: 700 clamp(1.85rem, 3vw, 2.75rem)/1.08 var(--font-display); letter-spacing: -0.025em; }
h2 { margin-bottom: 0.35rem; font: 700 1.2rem/1.2 var(--font-display); }
small { color: var(--muted); }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: 0.7rem 1rem; background: var(--ink); color: white; }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 250px minmax(220px, 1fr) auto; align-items: center; min-height: 68px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 0.75rem; height: 68px; padding: 0 1.25rem; border-right: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50% 50% 50% 10px; background: var(--brand-primary); color: white; font: 700 1.1rem var(--font-display); box-shadow: inset 0 -4px 0 var(--brand-accent); }
.brand > span:last-child { display: grid; line-height: 1.05; }
.brand strong { font-size: 1rem; }
.brand small { margin-top: 0.25rem; font-size: 0.7rem; letter-spacing: 0.05em; text-transform: uppercase; }
.project-switcher { display: grid; justify-self: start; gap: 0.1rem; min-width: 240px; margin-left: 1.35rem; padding: 0.45rem 2rem 0.45rem 0.7rem; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.project-switcher:hover { background: var(--surface-soft); }
.project-switcher span { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }
.project-switcher strong::after { content: "⌄"; margin-left: 0.55rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 0.45rem; padding-right: 1.15rem; }
.quiet-button { min-height: 38px; padding: 0.45rem 0.65rem; border: 0; border-radius: 6px; background: transparent; color: var(--muted); text-decoration: none; cursor: pointer; }
.quiet-button:hover { background: var(--surface-soft); color: var(--ink); }
kbd { margin-left: 0.35rem; padding: 0.05rem 0.35rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: white; font: 0.68rem var(--font-mono); }
.profile-chip { display: grid; place-items: center; width: 36px; height: 36px; overflow: hidden; border-radius: 50%; background: var(--ink); color: white; font-weight: 700; text-transform: uppercase; }

.app-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.primary-nav { position: sticky; top: 68px; display: flex; flex-direction: column; height: calc(100vh - 68px); padding: 1.15rem 0.8rem; border-right: 1px solid var(--line); background: var(--surface); }
.nav-item { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; min-height: 46px; padding: 0 0.8rem; border: 0; border-radius: 7px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.nav-item:hover { background: var(--surface-soft); color: var(--ink); }
.nav-item.active { background: #e9f4fa; color: var(--brand-primary-dark); font-weight: 700; box-shadow: inset 3px 0 0 var(--brand-primary); }
.nav-count { min-width: 1.6rem; padding: 0.1rem 0.4rem; border-radius: 999px; background: var(--canvas); font-size: 0.75rem; text-align: center; }
.nav-footer { display: flex; align-items: flex-start; gap: 0.65rem; margin-top: auto; padding: 0.9rem 0.75rem; border-top: 1px solid var(--line); }
.nav-footer span:last-child { display: grid; }
.nav-footer small { margin-top: 0.15rem; font-size: 0.72rem; }
.status-dot { width: 9px; height: 9px; margin-top: 0.35rem; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
main { min-width: 0; }
.pilot-notice { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.8rem; min-height: 44px; padding: 0.55rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid #eed6a6; background: var(--warning-soft); color: #5d3a00; font-size: 0.86rem; }
.pilot-notice button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.view { padding: clamp(1.25rem, 3.2vw, 3rem); }
.page-header, .feature-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 1.7rem; }
.page-header p:not(.breadcrumb), .feature-header p:not(.breadcrumb) { max-width: 720px; margin-bottom: 0; color: var(--muted); }
.breadcrumb { margin-bottom: 0.55rem; color: var(--brand-primary-dark); font-size: 0.77rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.eyebrow { margin-bottom: 0.35rem; color: var(--brand-primary-dark); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.muted { color: var(--muted); }
.button { min-height: 42px; padding: 0.65rem 1rem; border: 1px solid transparent; border-radius: 6px; font-weight: 700; cursor: pointer; }
.button.primary { background: var(--brand-primary); color: white; box-shadow: 0 4px 12px rgba(0, 121, 189, 0.2); }
.button.primary:hover { background: var(--brand-primary-dark); }
.button.secondary { border-color: var(--line-strong); background: white; color: var(--ink); }
.button.secondary:hover { border-color: var(--brand-primary); color: var(--brand-primary-dark); }
.button.danger { color: var(--danger); }
.button:disabled { cursor: not-allowed; opacity: 0.48; box-shadow: none; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; margin-bottom: 1rem; }
.metric-grid article { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 1rem; min-height: 112px; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric-grid span { color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; }
.metric-grid strong { grid-column: 1 / -1; align-self: center; min-width: 0; font: 700 clamp(1.3rem, 1.7vw, 1.55rem) var(--font-display); color: var(--brand-primary-dark); white-space: nowrap; }
.metric-grid small { align-self: end; }
.content-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 0.8fr); gap: 1rem; }
.surface { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 8px rgba(23, 35, 45, 0.03); }
.surface-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 74px; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.surface-header h2, .surface-header p { margin-bottom: 0; }
.feature-list { min-height: 180px; }
.feature-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 1rem; width: 100%; min-height: 78px; padding: 0.9rem 1.2rem; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.feature-row:last-child { border-bottom: 0; }
.feature-row:hover { background: var(--surface-soft); }
.feature-row > span:first-child { display: grid; gap: 0.2rem; }
.feature-row small { display: block; }
.feature-arrow { color: var(--brand-primary); font-size: 1.25rem; }
.empty-state { padding: 2rem; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 0.35rem; color: var(--ink); }
.activity-card { min-height: 260px; }

.status-chip, .revision-chip, .proposal-chip, .save-status { display: inline-flex; align-items: center; width: max-content; min-height: 28px; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em; white-space: nowrap; }
.status-chip.neutral, .revision-chip { border: 1px solid var(--line-strong); background: var(--surface-soft); color: var(--muted); }
.status-chip.success { background: var(--success-soft); color: var(--success); }
.status-chip.warning { background: var(--warning-soft); color: var(--warning); }
.status-chip.danger { background: var(--danger-soft); color: var(--danger); }
.status-chip.info { background: #e9f4fa; color: var(--brand-primary-dark); }
.proposal-chip { background: #e9f4fa; color: var(--brand-primary-dark); }
.save-status { margin-left: 0.4rem; background: var(--success-soft); color: var(--success); }
.stack-list { overflow: hidden; }
.stack-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1rem; min-height: 78px; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.stack-item:last-child { border-bottom: 0; }
.stack-item p { margin-bottom: 0; color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr); gap: 1rem; }
.member-list, .gate-list { padding: 0.6rem 1.2rem; }
.member-row, .gate-list article { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1rem; min-height: 64px; border-bottom: 1px solid var(--line); }
.member-row:last-child, .gate-list article:last-child { border-bottom: 0; }
.member-row > span:first-child { min-width: 0; overflow-wrap: anywhere; font-family: var(--font-mono); font-size: 0.78rem; }
.role-list { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.3rem; }
.role-list span { padding: 0.15rem 0.45rem; border-radius: 4px; background: var(--canvas); color: var(--muted); font-size: 0.72rem; }
.member-form { display: grid; grid-template-columns: minmax(160px, 1fr) auto; gap: 0.65rem; padding: 1.2rem; border-top: 1px solid var(--line); }
.member-form > label { grid-column: 1 / -1; }
.member-form fieldset { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.7rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: 6px; }
.member-form fieldset label { font-weight: 400; }
.gate-list article { grid-template-columns: 42px 1fr auto; }
.gate-list div { display: grid; }
.gate-icon { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); color: var(--brand-primary-dark); font: 700 0.7rem var(--font-mono); }
.text-link { display: inline-block; margin: 0.5rem 1.2rem 1.2rem; font-weight: 700; }

input, textarea { width: 100%; min-width: 0; border: 1px solid var(--line-strong); border-radius: 6px; background: white; color: var(--ink); padding: 0.75rem 0.85rem; }
input { min-height: 43px; }
textarea { resize: vertical; line-height: 1.55; }
label, legend { font-weight: 700; }
.form-stack { display: grid; gap: 0.7rem; max-width: 780px; }
.form-stack .button { justify-self: start; margin-top: 0.35rem; }

.feature-view { padding: 0; }
.feature-header { align-items: center; margin: 0; padding: 1.4rem clamp(1rem, 2.5vw, 2rem); border-bottom: 1px solid var(--line); background: var(--surface); }
.feature-header h1 { font-size: clamp(1.6rem, 2.5vw, 2.15rem); }
.back-link, .text-button { padding: 0; border: 0; background: transparent; color: var(--brand-primary-dark); font-weight: 700; cursor: pointer; }
.feature-header-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.55rem; }
.workspace-grid { display: grid; grid-template-columns: 230px minmax(430px, 1fr) minmax(260px, 330px); min-height: calc(100vh - 240px); }
.workflow-panel, .context-rail { padding: 1.4rem 1.15rem; background: var(--surface-soft); }
.workflow-panel { border-right: 1px solid var(--line); }
.context-rail { border-left: 1px solid var(--line); }
.document-panel { min-width: 0; background: var(--surface); }
.workflow-list { margin: 1.2rem 0; padding: 0; list-style: none; }
.workflow-list li { position: relative; display: grid; grid-template-columns: 25px 1fr; gap: 0.65rem; min-height: 50px; color: var(--muted); font-size: 0.8rem; }
.workflow-list li::after { content: ""; position: absolute; left: 11px; top: 27px; bottom: 1px; width: 1px; background: var(--line-strong); }
.workflow-list li:last-child::after { display: none; }
.workflow-list span { display: grid; place-items: center; width: 23px; height: 23px; border: 1px solid var(--line-strong); border-radius: 50%; background: white; font-size: 0.68rem; }
.workflow-list li.active { color: var(--brand-primary-dark); font-weight: 800; }
.workflow-list li.active span { border-color: var(--brand-primary); background: var(--brand-primary); color: white; box-shadow: 0 0 0 4px #dff0f9; }
.workflow-list li.complete { color: var(--success); }
.workflow-list li.complete span { border-color: var(--success); background: var(--success-soft); }
.boundary-card, .context-card { padding: 0.85rem; border: 1px solid var(--line); border-radius: 7px; background: white; }
.boundary-card { border-left: 3px solid var(--brand-accent); }
.boundary-card p, .context-card p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.8rem; }
.tab-list { display: flex; flex-wrap: wrap; gap: 0.2rem; padding: 0.65rem 1.3rem 0; border-bottom: 1px solid var(--line); }
.tab-list button { min-height: 43px; padding: 0.6rem 0.85rem; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); white-space: nowrap; cursor: pointer; }
.tab-list button[aria-selected="true"] { border-bottom-color: var(--brand-primary); color: var(--brand-primary-dark); font-weight: 800; }
.tab-panel { padding: clamp(1.25rem, 3vw, 2.3rem); }
.document-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.document-heading h2 { font-size: 1.55rem; }
.spec-editor { min-height: 54vh; font: 0.86rem/1.55 var(--font-mono); tab-size: 2; }
.diff-box, .technical-evidence { margin-top: 1rem; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
summary { padding: 0.75rem 0.9rem; font-weight: 700; cursor: pointer; }
.evidence-list { display: grid; grid-template-columns: 120px 1fr; gap: 0.45rem 1rem; margin: 0; padding: 0.9rem; border-top: 1px solid var(--line); }
.evidence-list dt { color: var(--muted); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.evidence-list dd { margin: 0; overflow-wrap: anywhere; font-family: var(--font-mono); font-size: 0.76rem; }
.artifact-list { display: grid; gap: 0.8rem; }
.artifact-card { border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.artifact-card header { display: flex; justify-content: space-between; padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.artifact-card pre, .markdown-surface pre, .technical-evidence pre { max-height: 26rem; margin: 0; padding: 1rem; overflow: auto; background: #fbfcfd; font: 0.78rem/1.5 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.context-card { margin: 1rem 0; }
.timeline { margin: 1.2rem 0 0; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: 0.6rem; padding-bottom: 1rem; color: var(--muted); font-size: 0.76rem; }
.timeline li div { display: grid; gap: 0.1rem; }
.timeline li strong { color: var(--ink); font-size: 0.8rem; }
.timeline-dot { width: 9px; height: 9px; margin-top: 0.25rem; border: 2px solid var(--brand-primary); border-radius: 50%; background: white; }
.timeline.compact { padding: 0 1.2rem; }
.conformance-item { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; padding: 0.9rem; border-bottom: 1px solid var(--line); text-align: left; }
.conformance-item p { grid-column: 1 / -1; margin: 0; color: var(--muted); font: 0.76rem var(--font-mono); overflow-wrap: anywhere; }

.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 50; max-width: 430px; padding: 0.85rem 1rem; border: 1px solid var(--success); border-radius: 7px; background: white; box-shadow: var(--shadow); }
.toast.error { max-width: min(56rem, calc(100vw - 2rem)); border-color: var(--danger); background: var(--danger-soft); white-space: pre-wrap; }
dialog { padding: 0; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24); }
dialog::backdrop { background: rgba(17, 32, 44, 0.42); backdrop-filter: blur(2px); }
.command-dialog { width: min(600px, calc(100vw - 2rem)); margin-top: 12vh; }
.command-dialog form { padding: 1rem; }
.command-dialog label { display: block; margin-bottom: 0.55rem; }
.command-results { margin-top: 0.6rem; }
.command-result { display: flex; justify-content: space-between; width: 100%; min-height: 44px; padding: 0.6rem; border: 0; border-radius: 5px; background: transparent; text-align: left; cursor: pointer; }
.command-result:hover { background: var(--surface-soft); }
.modal { width: min(560px, calc(100vw - 2rem)); }
.modal form { padding: 1.3rem; }
.modal-header { display: flex; justify-content: space-between; gap: 1rem; }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--surface-soft); font-size: 1.4rem; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.65rem; margin-top: 1rem; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: 210px 1fr auto; }
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .workspace-grid { grid-template-columns: 205px minmax(420px, 1fr); }
  .context-rail { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; border-top: 1px solid var(--line); border-left: 0; }
  .context-rail > .eyebrow, .context-rail > h2 { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .brand { width: 68px; padding: 0 1rem; }
  .brand > span:last-child { display: none; }
  .app-shell { grid-template-columns: 68px minmax(0, 1fr); }
  .primary-nav { align-items: center; padding-inline: 0.45rem; }
  .nav-item { width: 50px; grid-template-columns: 1fr; justify-items: center; font-size: 0; }
  .nav-item > span:first-child { font-size: 1rem; }
  .nav-count { position: absolute; margin: -25px 0 0 25px; font-size: 0.65rem; }
  .nav-footer span:last-child { display: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid, .settings-grid { grid-template-columns: 1fr; }
  .workspace-grid { display: block; }
  .workflow-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .workflow-list { display: flex; overflow-x: auto; }
  .workflow-list li { min-width: 150px; }
  .workflow-list li::after { display: none; }
}
@media (max-width: 680px) {
  .project-switcher { min-width: 0; margin-left: 0.3rem; padding-right: 0.4rem; }
  .project-switcher span { display: none; }
  .topbar-actions .quiet-button { display: none; }
  .pilot-notice { grid-template-columns: 1fr auto; }
  .pilot-notice span { grid-column: 1 / -1; grid-row: 2; }
  .page-header, .feature-header { align-items: stretch; flex-direction: column; gap: 1rem; }
  .feature-header-meta { justify-content: flex-start; }
  .metric-grid { grid-template-columns: 1fr; }
  .feature-row { grid-template-columns: 1fr auto; }
  .feature-row .status-chip { grid-column: 1; }
  .view { padding: 1rem; }
  .context-rail { display: block; }
  .member-form { grid-template-columns: 1fr; }
  .member-form > * { grid-column: 1 !important; }
  .modal-actions { align-items: stretch; flex-direction: column-reverse; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
