:root {
  --font-display: "Familjen Grotesk", "Noto Sans", sans-serif;
  --font-body: "Noto Sans", sans-serif;
  --bg: oklch(0.965 0.008 245);
  --surface: oklch(0.99 0.003 245);
  --surface-raised: oklch(1 0 0);
  --ink: oklch(0.22 0.025 248);
  --muted: oklch(0.48 0.025 248);
  --line: oklch(0.88 0.015 245);
  --accent: oklch(0.52 0.145 158);
  --accent-dark: oklch(0.37 0.11 158);
  --focus: oklch(0.62 0.18 250);
  --agent: oklch(0.58 0.15 247);
  --crm: oklch(0.56 0.14 151);
  --manager: oklch(0.65 0.17 55);
  --admin: oklch(0.56 0.16 302);
  --danger: oklch(0.58 0.2 28);
  --r-sm: 8px;
  --r-md: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --topbar-h: 72px;
  --panel-w: 272px;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { font-family: var(--font-body); color: var(--ink); background: var(--bg); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, .screen-node:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: fixed; z-index: 1000; top: var(--space-2); left: var(--space-2); padding: var(--space-3); background: var(--ink); color: var(--surface); }

.app-shell { display: grid; grid-template-columns: var(--panel-w) 1fr; grid-template-rows: var(--topbar-h) 1fr; height: 100dvh; }
.topbar {
  grid-column: 1 / -1; display: grid; grid-template-columns: var(--panel-w) minmax(320px, 640px) 1fr;
  align-items: center; gap: var(--space-6); padding: 0 var(--space-6); background: var(--surface);
  border-bottom: 1px solid var(--line); z-index: 20;
}
.brand-block { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-mark { width: 12px; height: 32px; background: var(--accent); border-radius: 2px; flex: none; }
h1, h2 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
.brand-block h1 { font-size: 18px; line-height: 1.1; letter-spacing: -0.02em; }
.brand-block p { margin: var(--space-1) 0 0; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.search-wrap { height: 44px; display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: var(--space-2); padding: 0 var(--space-3); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); }
.search-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 2px color-mix(in oklch, var(--focus) 20%, transparent); }
.search-wrap svg, .tool-button svg, .icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.search-wrap input { min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; }
.search-wrap input::placeholder { color: var(--muted); }
kbd { padding: var(--space-1) var(--space-2); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.tool-button { min-height: 44px; display: inline-flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-3); border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; transition: transform 180ms var(--ease), background 180ms var(--ease); }
.tool-button:hover { transform: translateY(-2px); background: var(--bg); }
.tool-button:active { transform: translateY(1px); }

.control-panel { overflow-y: auto; padding: var(--space-6) var(--space-4); background: var(--surface); border-right: 1px solid var(--line); }
.control-panel section + section { margin-top: var(--space-8); padding-top: var(--space-6); border-top: 1px solid var(--line); }
.control-panel h2 { font-size: 14px; letter-spacing: 0.01em; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.text-button { min-height: 44px; padding: 0 var(--space-2); border: 0; background: transparent; color: var(--accent-dark); cursor: pointer; font-weight: 600; }
.text-button:hover { text-decoration: underline; text-underline-offset: 4px; }
.filter-list, .journey-list { display: grid; gap: var(--space-2); }
.filter-button, .journey-button { width: 100%; min-height: 44px; display: grid; align-items: center; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); cursor: pointer; text-align: left; transition: transform 180ms var(--ease), background 180ms var(--ease); }
.filter-button { grid-template-columns: 12px 1fr auto; gap: var(--space-3); padding: 0 var(--space-3); }
.journey-button { grid-template-columns: auto 1fr; gap: var(--space-2); padding: var(--space-2) var(--space-3); }
.filter-button:hover, .journey-button:hover { transform: translateX(2px); background: var(--bg); }
.filter-button[aria-pressed="true"], .journey-button[aria-pressed="true"] { background: color-mix(in oklch, var(--accent) 12%, var(--surface)); color: var(--accent-dark); }
.filter-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--role-color); }
.filter-count, .journey-code { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.journey-title { display: block; margin-top: 2px; font-size: 13px; font-weight: 600; }
.switch-row { min-height: 44px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.switch-row span { display: flex; align-items: center; gap: var(--space-3); font-size: 13px; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.line-key { width: 24px; height: 0; border-top: 2px solid var(--muted); }
.line-key.dashed { border-top-style: dashed; }
.line-key.dotted { border-top-style: dotted; }
.help-block dl { margin: var(--space-3) 0 0; display: grid; gap: var(--space-2); }
.help-block dl div { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.help-block dt { color: var(--ink); }

.canvas-viewport { position: relative; overflow: hidden; cursor: grab; background-color: var(--bg); background-image: radial-gradient(circle, color-mix(in oklch, var(--muted) 20%, transparent) 1px, transparent 1px); background-size: 24px 24px; touch-action: none; }
.canvas-viewport.is-panning { cursor: grabbing; }
.world { position: absolute; width: 5340px; height: 6960px; transform-origin: 0 0; will-change: transform; }
.lane-layer, .node-layer, .edge-layer { position: absolute; inset: 0; }
.lane-layer { z-index: 0; }
.edge-layer { z-index: 1; }
.node-layer { z-index: 2; }
.edge-layer { width: 5340px; height: 6960px; overflow: visible; pointer-events: none; }
.lane { position: absolute; left: 40px; width: 4960px; border: 1px solid color-mix(in oklch, var(--role-color) 34%, var(--line)); background: color-mix(in oklch, var(--role-color) 5%, var(--surface)); border-radius: var(--r-md); }
.lane-heading { position: absolute; left: 40px; top: 32px; }
.lane-heading strong { display: block; font-family: var(--font-display); font-size: 24px; color: var(--role-color); }
.lane-heading span { display: block; margin-top: var(--space-2); color: var(--muted); font-size: 14px; }

.screen-node { position: absolute; width: 500px; height: 346px; padding: 0; overflow: hidden; border: 2px solid var(--role-color); border-radius: var(--r-md); background: var(--surface-raised); cursor: pointer; box-shadow: 0 2px 0 color-mix(in oklch, var(--role-color) 22%, transparent); transition: transform 200ms var(--ease), opacity 200ms var(--ease), filter 200ms var(--ease), box-shadow 200ms var(--ease); }
.screen-node:hover { transform: translateY(-4px); box-shadow: 0 8px 0 color-mix(in oklch, var(--role-color) 18%, transparent); }
.screen-node:active { transform: translateY(1px); }
.screen-node.is-dimmed { opacity: 0.18; filter: grayscale(1); }
.screen-node.is-hidden { display: none; }
.screen-node.is-match { box-shadow: 0 0 0 6px color-mix(in oklch, var(--focus) 35%, transparent); }
.node-head { height: 64px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-3); padding: 0 var(--space-4); border-bottom: 1px solid var(--line); text-align: left; }
.node-code { color: var(--role-color); font-family: var(--font-display); font-size: 16px; font-weight: 700; }
.node-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.node-open { color: var(--muted); font-size: 12px; }
.screen-node img { display: block; width: 500px; height: 282px; object-fit: cover; background: var(--bg); }

.flow-edge { fill: none; stroke: var(--edge-color); stroke-width: 4; marker-end: url(#arrowHead); transition: opacity 180ms var(--ease); }
.flow-edge[data-kind="secondary"] { stroke-dasharray: 14 10; }
.flow-edge[data-kind="support"] { stroke-dasharray: 3 9; }
.flow-edge.is-dimmed { opacity: 0.08; }
.flow-edge.is-hidden { display: none; }
.edge-label { font-family: var(--font-body); font-size: 15px; font-weight: 600; fill: var(--edge-color); paint-order: stroke; stroke: var(--surface); stroke-width: 8px; stroke-linejoin: round; transition: opacity 180ms var(--ease); }
.edge-label.is-dimmed { opacity: 0.08; }
.edge-label.is-hidden { display: none; }

.zoom-control { position: absolute; left: var(--space-4); bottom: var(--space-4); display: grid; grid-template-columns: 44px 64px 44px; height: 44px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); z-index: 5; }
.zoom-control button { border: 0; background: transparent; color: var(--ink); font-size: 24px; cursor: pointer; }
.zoom-control button:hover { background: var(--bg); }
.zoom-control output { display: grid; place-items: center; border-inline: 1px solid var(--line); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.minimap-wrap { position: absolute; right: var(--space-4); bottom: var(--space-4); width: 248px; height: 168px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); z-index: 5; }
#minimap { width: 100%; height: 100%; display: block; }
.empty-state { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); padding: var(--space-6); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); text-align: center; }
.empty-state span { display: block; margin-top: var(--space-2); color: var(--muted); font-size: 14px; }

.screen-dialog { width: min(1480px, calc(100vw - 48px)); max-height: calc(100dvh - 48px); padding: 0; border: 0; border-radius: var(--r-md); background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px color-mix(in oklch, var(--ink) 28%, transparent); }
.screen-dialog::backdrop { background: color-mix(in oklch, var(--ink) 55%, transparent); }
.dialog-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--line); }
.dialog-header > div { display: flex; align-items: baseline; gap: var(--space-3); }
.dialog-code { color: var(--accent-dark); font-family: var(--font-display); font-weight: 700; }
.dialog-header h2 { font-size: 24px; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); cursor: pointer; }
.icon-button:hover { background: var(--bg); }
.dialog-body { display: grid; grid-template-columns: minmax(0, 1fr) 280px; max-height: calc(100dvh - 120px); }
.dialog-body > img { width: 100%; height: 100%; min-height: 520px; object-fit: contain; background: var(--bg); }
.dialog-body > aside { overflow-y: auto; padding: var(--space-6); border-left: 1px solid var(--line); }
.dialog-body aside > div + div { margin-top: var(--space-6); }
.meta-label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.dialog-body p { font-size: 14px; line-height: 1.6; }
.route-list { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.route-chip { padding: var(--space-2) var(--space-3); background: var(--bg); border-radius: var(--r-sm); font-size: 12px; }
.primary-link { min-height: 44px; display: grid; place-items: center; margin-top: var(--space-8); border-radius: var(--r-sm); background: var(--accent); color: oklch(0.99 0.005 158); text-decoration: none; font-weight: 600; transition: transform 150ms var(--ease), background 150ms var(--ease); }
.primary-link:hover { transform: translateY(-2px); background: var(--accent-dark); }
.primary-link:active { transform: translateY(1px); }

@media (max-width: 900px) {
  :root { --panel-w: 0px; }
  .app-shell { grid-template-columns: 1fr; }
  .topbar { grid-template-columns: 1fr auto; padding: 0 var(--space-3); gap: var(--space-3); }
  .brand-block p, .tool-button span, .top-actions a { display: none; }
  .search-wrap { position: fixed; left: var(--space-3); right: var(--space-3); top: calc(var(--topbar-h) + var(--space-3)); z-index: 30; box-shadow: 0 4px 12px color-mix(in oklch, var(--ink) 8%, transparent); }
  .control-panel { display: none; }
  .canvas-viewport { grid-row: 2; padding-top: 68px; }
  .minimap-wrap { display: none; }
  .dialog-body { grid-template-columns: 1fr; }
  .dialog-body > aside { border-left: 0; border-top: 1px solid var(--line); }
  .dialog-body > img { min-height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
