/* Hallmark · pre-emit critique: P5 H5 E5 S5 R5 V5 */

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('./fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('./fonts/ibm-plex-sans-latin-700-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('./fonts/ibm-plex-mono-latin-600-normal.woff2') format('woff2');
}

@font-face {
  /* impeccable-disable-next-line overused-font -- design.md locks Instrument Serif as the display face */
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/instrument-serif-latin-400-normal.woff2') format('woff2');
}

:root {
  color-scheme: dark;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --bg-canvas: oklch(0.15 0.012 245);
  --bg-surface: oklch(0.19 0.014 245);
  --bg-elevated: oklch(0.23 0.016 245);
  --bg-subtle: oklch(0.17 0.013 245);
  --bg-transparent: oklch(0 0 0 / 0);

  --text-primary: oklch(0.95 0.008 245);
  --text-secondary: oklch(0.78 0.018 245);
  --text-muted: oklch(0.66 0.020 245);

  --border-hairline: oklch(0.29 0.018 245);
  --border-strong: oklch(0.42 0.025 245);

  --accent-primary: oklch(0.74 0.14 195);
  --accent-surface: oklch(0.25 0.045 195);
  --selection-bg: oklch(0.35 0.09 195);

  --status-approved: oklch(0.76 0.15 155);
  --status-approved-bg: oklch(0.24 0.045 155);

  --status-warning: oklch(0.80 0.15 75);
  --status-warning-bg: oklch(0.25 0.050 75);

  --status-danger: oklch(0.72 0.18 25);
  --status-danger-bg: oklch(0.25 0.055 25);

  --shadow-panel: 0 8px 24px oklch(0.08 0.01 245 / 0.35);
}

[data-theme="light"] {
  color-scheme: light;
  --bg-canvas: oklch(0.97 0.006 245);
  --bg-surface: oklch(0.99 0.003 245);
  --bg-elevated: oklch(0.93 0.008 245);
  --bg-subtle: oklch(0.95 0.006 245);
  --bg-transparent: oklch(1 0 0 / 0);

  --text-primary: oklch(0.18 0.015 245);
  --text-secondary: oklch(0.36 0.020 245);
  --text-muted: oklch(0.46 0.020 245);

  --border-hairline: oklch(0.84 0.012 245);
  --border-strong: oklch(0.68 0.018 245);

  --accent-primary: oklch(0.44 0.14 195);
  --accent-surface: oklch(0.91 0.035 195);
  --selection-bg: oklch(0.85 0.07 195);

  --status-approved: oklch(0.42 0.14 155);
  --status-approved-bg: oklch(0.92 0.035 155);

  --status-warning: oklch(0.48 0.15 75);
  --status-warning-bg: oklch(0.93 0.040 75);

  --status-danger: oklch(0.46 0.18 25);
  --status-danger-bg: oklch(0.93 0.040 25);

  --shadow-panel: 0 8px 24px oklch(0.20 0.01 245 / 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

::selection {
  background-color: var(--selection-bg);
  color: var(--text-primary);
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: clip;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  caret-color: var(--accent-primary);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background-color: var(--bg-subtle);
}

::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: 4px;
}

h1,
h2,
h3,
h4 {
  font-style: normal;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 2.4vw, 2.35rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-top: 0.75rem;
  margin-bottom: 0.35rem;
}

h2 {
  font-family: var(--font-sans);
  font-size: clamp(1.35rem, 1.8vw, 1.65rem);
  font-weight: 600;
  line-height: 1.25;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

h3 {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

p {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.prose-copy {
  max-width: 68ch;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.6;
}

.meta-line {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  max-width: 1920px;
  margin: 0 auto;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
}

.app-sidebar {
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-hairline);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.brand-block {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-hairline);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.brand-row h1 {
  margin: 0;
}

.sidebar-collapse-btn {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-collapse-btn:hover {
  border-color: var(--accent-primary);
}

.sidebar-collapse-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.brand-meta {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.35rem;
  margin-bottom: 0;
}

@media (width >= 1024px) {
  .app-shell--collapsed {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .app-shell--collapsed .app-sidebar {
    padding: 0.75rem 0.45rem;
    align-items: center;
  }

  .app-shell--collapsed .brand-title,
  .app-shell--collapsed .brand-meta,
  .app-shell--collapsed .nav-section-title,
  .app-shell--collapsed .nav-item-meta,
  .app-shell--collapsed .sidebar-footer {
    display: none;
  }

  .app-shell--collapsed .nav-btn {
    padding: 0.45rem;
    width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
  }
}

.sidebar-section h2 {
  font-size: 0.95rem;
  margin-top: 0.75rem;
  margin-bottom: 0.4rem;
}

.nav-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-btn,
.step-btn,
.action-btn {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-btn:hover,
.step-btn:hover,
.action-btn:hover:not(:disabled) {
  border-color: var(--accent-primary);
}

.nav-btn:focus-visible,
.step-btn:focus-visible,
.action-btn:focus-visible,
.lab-input:focus-visible,
.topbar-filter-input:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.nav-btn.is-active,
.step-btn.is-active {
  background-color: var(--accent-surface);
  border-color: var(--accent-primary);
}

.nav-btn-title,
.step-btn-title {
  display: block;
  font-weight: 600;
}

.nav-btn-meta,
.step-btn-time {
  display: block;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  margin-top: 0.2rem;
}

.action-btn:disabled {
  color: var(--text-muted);
  border-color: var(--border-hairline);
  cursor: not-allowed;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.5rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-hairline);
}

.topbar-metrics,
.topbar-actions,
.topbar-controls,
.badge-group,
.scrubber-controls,
.inline-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.topbar-search {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  height: 32px;
}

.topbar-filter-input {
  background-color: var(--bg-transparent);
  color: var(--text-primary);
  border: none;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  min-width: 280px;
  height: 28px;
}

.topbar-filter-input::placeholder {
  color: var(--text-muted);
}

.topbar-kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}

.app-canvas {
  padding: 1.25rem 1.5rem;
  flex: 1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1.25rem;
  width: 100%;
}

.panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 1.15rem 1.35rem;
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.span-8 {
  grid-column: span 8;
}

.span-7 {
  grid-column: span 7;
}

.span-5 {
  grid-column: span 5;
}

.span-4 {
  grid-column: span 4;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.step-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.step-btn {
  padding: 0.45rem 0.65rem;
}

.step-index {
  display: block;
  font-size: 0.75rem;
  color: var(--accent-primary);
  font-weight: 600;
}

.step-btn-title {
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-btn-time {
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.step-inspector {
  margin-top: 0.75rem;
  padding: 0.75rem 0.9rem;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.step-inspector-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.step-inspector-title {
  font-size: 0.875rem;
  color: var(--text-primary);
  flex: 1;
}

.step-inspector-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.step-inspector-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.step-inspector-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ledger-list,
.narrative-stack,
.lab-actions-grid {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.ledger-row {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-hairline);
}

.ledger-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.ledger-note {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-hairline);
}

.badge-accent {
  background-color: var(--accent-surface);
  color: var(--accent-primary);
}

.badge-approved {
  background-color: var(--status-approved-bg);
  color: var(--status-approved);
}

.badge-warning {
  background-color: var(--status-warning-bg);
  color: var(--status-warning);
}

.badge-danger {
  background-color: var(--status-danger-bg);
  color: var(--status-danger);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 0.4rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border-hairline);
  text-align: left;
  font-size: 0.875rem;
}

.data-table th {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: 600;
}

.mono-cell {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.num-cell {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.code-well {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 360px;
}

.monitor-frame-wrap {
  width: 100%;
  margin-top: 0.5rem;
}

.monitor-provenance-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.monitor-svg {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
}

.monitor-bg {
  fill: var(--bg-subtle);
}

.monitor-grid-line {
  stroke: var(--border-hairline);
  stroke-width: 1;
}

.monitor-wave-line {
  fill: var(--bg-transparent);
  stroke: var(--status-approved);
  stroke-width: 2.5;
}

.monitor-pleth-line {
  fill: var(--bg-transparent);
  stroke: var(--accent-primary);
  stroke-width: 2;
}

.monitor-readout-label {
  fill: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 13px;
}

.monitor-readout-value {
  fill: var(--status-approved);
  font-family: var(--font-mono);
  font-size: 40px;
  font-weight: 700;
}

.monitor-readout-meta {
  fill: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.alert-banner {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.9rem 1.1rem;
  border-radius: 6px;
  border: 1px solid var(--status-danger);
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
}

.alert-danger {
  background-color: var(--status-danger-bg);
  color: var(--status-danger);
}

.lab-input {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  width: 110px;
}

.lab-input:user-invalid {
  border-color: var(--status-danger);
}

.kv-list {
  margin: 0.5rem 0 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-hairline);
  font-size: 0.875rem;
}

.kv-row dt {
  color: var(--text-secondary);
}

.kv-row dd {
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
}

@media (width < 1024px) {
  /* minmax(0, 1fr) stops the nowrap story row from widening the column. */
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border-hairline);
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .brand-block {
    padding-bottom: 0.5rem;
  }

  .sidebar-collapse-btn {
    display: none;
  }

  .brand-block h1 {
    font-size: 1.25rem;
    margin: 0;
  }

  .brand-meta {
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar-section h2 {
    font-size: 0.8125rem;
    margin-top: 0;
    margin-bottom: 0.25rem;
  }

  .sidebar-section .meta-line {
    font-size: 0.8125rem;
    line-height: 1.4;
    margin-bottom: 0;
  }

  .sidebar-section .nav-stack {
    flex-direction: row;
  }

  .sidebar-section .nav-btn {
    min-height: 40px;
    padding: 0.5rem 0.6rem;
    font-size: 0.8125rem;
  }

  nav[aria-label="Primary views"] .nav-btn {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
  }

  /* The edge fade shows that the story row scrolls. */
  nav[aria-label="Scripted demonstration selector"] .nav-stack::after {
    content: '';
    position: sticky;
    right: 0;
    flex: 0 0 2rem;
    margin-left: -2rem;
    align-self: stretch;
    background: linear-gradient(to right, var(--bg-transparent), var(--bg-surface));
    pointer-events: none;
  }

  nav[aria-label="Scripted demonstration selector"] .nav-stack {
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-bottom: 0.25rem;
    padding-inline-end: 2rem;
    scroll-padding-inline-end: 2rem;
  }

  nav[aria-label="Scripted demonstration selector"] .nav-btn {
    scroll-snap-align: start;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  nav[aria-label="Scripted demonstration selector"] .nav-btn-meta {
    display: none;
  }

  /* The badges and the theme button share one flow, so the topbar keeps two rows. */
  .app-topbar {
    justify-content: flex-start;
    padding: 0.5rem 1rem;
    gap: 0.35rem;
  }

  .app-topbar .topbar-metrics {
    display: contents;
  }

  .app-topbar .topbar-actions {
    width: 100%;
    gap: 0.35rem;
  }

  .topbar-search {
    flex: 1 1 100%;
    width: 100%;
    justify-content: space-between;
  }

  .topbar-filter-input {
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  .app-topbar .badge {
    padding: 0.2rem 0.45rem;
    font-size: 0.75rem;
  }

  .step-inspector-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .span-8,
  .span-7,
  .span-5,
  .span-4 {
    grid-column: span 12;
  }
}
