:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-2: #0b1120;
  --panel: rgba(17, 25, 42, .76);
  --panel-solid: #111a2e;
  --panel-soft: rgba(14, 22, 38, .9);
  --line: rgba(120, 150, 200, .16);
  --line-strong: rgba(105, 168, 205, .35);
  --text: #e6edf7;
  --text-dim: #91a4bf;
  --text-muted: #607896;
  --cyan: #22d3ee;
  --purple: #a855f7;
  --green: #34d399;
  --orange: #fb923c;
  --blue: #60a5fa;
  --red: #f87171;
  --mono: "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --detail-width: min(520px, 44vw);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(1100px 680px at 16% -10%, rgba(26, 58, 111, .38), transparent 58%),
    radial-gradient(900px 620px at 100% 0%, rgba(81, 35, 115, .25), transparent 52%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
.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; }

.app-shell { position: relative; width: 100%; height: 100dvh; overflow: hidden; }
.topbar {
  position: fixed; z-index: 50; top: 0; right: 0; left: 0; height: 64px;
  display: flex; align-items: center; gap: 16px; padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(8, 13, 25, .96), rgba(8, 13, 25, .72));
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: max-content; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid rgba(34, 211, 238, .58);
  border-radius: 10px; background: linear-gradient(145deg, rgba(34, 211, 238, .24), rgba(168, 85, 247, .24));
  box-shadow: 0 0 20px rgba(34, 211, 238, .22); color: #dffaff; font-size: 15px;
}
.brand-copy strong, .brand-copy small { display: block; }
.brand-copy strong { font-size: 15px; letter-spacing: .02em; }
.brand-copy small { margin-top: 2px; color: var(--text-dim); font-size: 10.5px; }
.search-wrap { position: relative; width: min(300px, 25vw); margin-left: auto; }
.search-box {
  display: flex; align-items: center; height: 40px; border: 1px solid var(--line); border-radius: 11px;
  background: rgba(13, 21, 37, .76); box-shadow: inset 0 1px rgba(255, 255, 255, .025);
}
.search-box:focus-within { border-color: rgba(34, 211, 238, .46); box-shadow: 0 0 0 3px rgba(34, 211, 238, .08); }
.search-box svg { width: 17px; height: 17px; margin-left: 11px; fill: none; stroke: var(--text-dim); stroke-width: 1.7; }
.search-box input { width: 100%; height: 100%; padding: 0 42px 0 8px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 12px; }
.search-box input::placeholder { color: var(--text-muted); }
.search-box kbd { position: absolute; right: 9px; padding: 2px 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--text-muted); font: 10px var(--mono); }
.topbar-stats { display: flex; gap: 8px; }
.stat-group { position: relative; display: flex; align-items: stretch; gap: 1px; padding: 17px 5px 4px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.stat-source { position: absolute; top: 4px; left: 9px; color: var(--text-muted); font: 700 8px var(--mono); letter-spacing: .08em; }
.stat { min-width: 58px; padding: 0 7px; border-right: 1px solid rgba(120, 150, 200, .1); }
.stat:last-of-type { border-right: 0; }
.stat small, .stat strong { display: block; white-space: nowrap; }
.stat small { color: var(--text-muted); font-size: 8.5px; text-transform: uppercase; }
.stat strong { margin-top: 1px; color: var(--text); font: 650 12px var(--mono); }
.sync-stat { min-width: 86px; }
.refresh-issues {
  display: grid; width: 30px; height: 30px; align-self: center; margin: 0 4px 0 3px; padding: 0; place-items: center;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(34, 211, 238, .06); color: #86e8f4; cursor: pointer;
}
.refresh-issues:hover { border-color: var(--line-strong); background: rgba(34, 211, 238, .11); }
.refresh-issues:focus-visible { outline: 2px solid #86e8f4; outline-offset: 2px; }
.refresh-issues:disabled { cursor: wait; opacity: .55; }
.refresh-issues span { display: block; font-size: 17px; line-height: 1; }
.refresh-issues.is-refreshing span { animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
.tree-workspace { position: fixed; inset: 64px 0 0; overflow: hidden; }
.app-shell.drawer-open .tree-workspace { right: var(--detail-width); }
.canvas-scroller {
  width: 100%; height: 100%; min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain;
  background-image:
    linear-gradient(rgba(104, 139, 181, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 139, 181, .045) 1px, transparent 1px);
  background-size: 38px 38px;
}
#tree-canvas { display: block; width: 100%; height: 100%; min-width: 760px; min-height: 560px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
#tree-canvas.is-panning, #tree-canvas.is-panning * { cursor: grabbing !important; }
#tree-canvas.is-unavailable { opacity: .18; }
.structure-edge { fill: none; stroke: rgba(70, 145, 178, .54); stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.feature-node { cursor: pointer; outline: none; transition: opacity .18s ease; }
.node-card { transition: transform .16s ease, filter .18s ease; transform-box: fill-box; transform-origin: center; }
.feature-node:hover .node-card { transform: translateY(-2px); filter: drop-shadow(0 0 12px rgba(34, 211, 238, .12)); }
.feature-node:focus-visible .node-card > .node-panel { stroke: #9beafe; stroke-width: 2; }
.feature-node.is-selected .node-card > .node-panel { stroke: #74e3f3; stroke-width: 2; filter: url(#node-shadow); }
.feature-node.is-dimmed, .feature-node.is-category-dimmed { opacity: .32; }
.node-panel { fill: url(#node-panel-gradient); stroke: rgba(82, 139, 166, .48); stroke-width: 1; vector-effect: non-scaling-stroke; }
.category-accent { fill: var(--category-color, var(--cyan)); }
.category-root_model { --category-color: var(--green); }
.category-model { --category-color: var(--orange); }
.node-title { fill: var(--text); font-size: 12.5px; font-weight: 720; }
.node-subtitle { fill: var(--text-dim); font-size: 8.5px; }
.node-code-hint { fill: #89a3bf; font: 9px var(--mono); }
.node-badge rect { fill: rgba(120, 150, 200, .09); stroke: rgba(120, 150, 200, .2); stroke-width: .7; }
.node-badge text { fill: #9eb0c8; font-size: 7.8px; font-weight: 720; }
.validation-badge circle { fill: #9b835a; }
.validation-badge text { fill: #c6ad7b; }
.status-open .validation-badge circle { fill: var(--green); }
.status-open .validation-badge text { fill: #a7f3d0; }
.status-closed .validation-badge circle { fill: #94a3b8; }
.status-closed .validation-badge text { fill: #cbd5e1; }
.status-under-review .validation-badge circle { fill: #fbbf24; }
.status-under-review .validation-badge text { fill: #fde68a; }
.status-in-progress .validation-badge circle { fill: #60a5fa; }
.status-in-progress .validation-badge text { fill: #bfdbfe; }
.status-declined .validation-badge circle { fill: var(--red); }
.status-declined .validation-badge text { fill: #fecaca; }
.status-done .validation-badge circle { fill: var(--green); }
.status-done .validation-badge text { fill: #a7f3d0; }
.node-toggle circle { fill: rgba(12, 20, 35, .94); stroke: rgba(128, 161, 190, .36); stroke-width: 1; vector-effect: non-scaling-stroke; }
.node-toggle text { fill: #b1c1d4; text-anchor: middle; font-size: 12px; font-weight: 650; }
.canvas-hint { position: fixed; z-index: 20; top: 74px; left: 50%; padding: 5px 13px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 999px; background: rgba(7, 11, 20, .62); color: var(--text-dim); font-size: 10px; pointer-events: none; backdrop-filter: blur(8px); }

.search-results { position: absolute; z-index: 70; top: 47px; right: 0; left: 0; padding: 6px; border: 1px solid var(--line); border-radius: 11px; background: rgba(10, 17, 30, .98); box-shadow: 0 18px 42px rgba(0, 0, 0, .48); }
.search-results button { display: block; width: 100%; padding: 8px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.search-results button:hover { background: rgba(96, 165, 250, .09); }
.search-results strong, .search-results small { display: block; }
.search-results strong { font-size: 11px; }
.search-results small { margin-top: 2px; color: var(--text-muted); font: 8.5px var(--mono); }
.search-results p { margin: 10px; color: var(--text-dim); font-size: 11px; }

.bottom-legend { position: fixed; z-index: 30; bottom: 14px; left: 14px; display: flex; max-width: calc(100% - 260px); gap: 8px; align-items: center; }
.semantic-legend { display: flex; align-items: center; gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text-muted); font-size: 9px; backdrop-filter: blur(10px); }
.semantic-legend span { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.legend-dot { width: 6px; height: 6px; border-radius: 50%; background: #9b835a; }
.review-dot { background: #fbbf24; }
.progress-dot { background: #60a5fa; }
.done-dot { background: var(--green); }
.declined-dot { background: var(--red); }
.legend-line { width: 16px; height: 0; border-top: 1px solid rgba(70, 145, 178, .72); }
.canvas-controls { position: fixed; z-index: 34; right: 14px; bottom: 14px; display: flex; gap: 6px; align-items: center; }
.canvas-controls button, .canvas-controls output { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); backdrop-filter: blur(10px); }
.canvas-controls button { cursor: pointer; }
.canvas-controls button:hover { border-color: var(--line-strong); background: var(--panel-solid); }
.canvas-controls output { width: 48px; color: var(--text-dim); font: 9px var(--mono); }
.app-shell.drawer-open .canvas-controls { right: calc(var(--detail-width) + 14px); }

.detail-panel {
  position: fixed; z-index: 45; top: 64px; right: 0; bottom: 0; width: var(--detail-width); overflow: hidden;
  border-left: 1px solid var(--line); background: linear-gradient(180deg, rgba(11, 17, 32, .98), rgba(7, 12, 23, .98));
  box-shadow: -16px 0 42px rgba(0, 0, 0, .5); backdrop-filter: blur(18px);
  transform: translateX(100%); transition: transform .26s cubic-bezier(.4, 0, .2, 1);
}
.detail-panel.is-open { transform: translateX(0); }
.drawer-topline { display: flex; height: 42px; align-items: center; justify-content: space-between; padding: 0 14px 0 18px; border-bottom: 1px solid var(--line); color: var(--text-muted); font: 700 9px var(--mono); letter-spacing: .08em; }
.drawer-topline button { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text-dim); cursor: pointer; }
.drawer-topline button:hover { color: var(--text); border-color: var(--line-strong); }
.detail-content { height: calc(100% - 42px); overflow-y: auto; }
.detail-content::-webkit-scrollbar { width: 7px; }
.detail-content::-webkit-scrollbar-thumb { border-radius: 5px; background: rgba(120, 150, 200, .18); }
.detail-empty { display: grid; min-height: 100%; place-items: center; color: var(--text-muted); font-size: 11px; }
.detail-header { padding: 20px 24px 17px; border-bottom: 1px solid var(--line); }
.detail-header h1 { margin: 8px 0 6px; color: var(--text); font-size: 21px; line-height: 1.18; letter-spacing: -.025em; }
.detail-header code { color: var(--text-muted); font: 9.5px var(--mono); word-break: break-all; }
.detail-eyebrow { display: flex; align-items: center; gap: 7px; color: var(--text-dim); font-size: 9px; font-weight: 700; }
.detail-category { padding: 2px 6px; border: 1px solid rgba(34, 211, 238, .16); border-radius: 999px; color: #79ddec; font: 700 7.5px var(--mono); text-transform: uppercase; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #9b835a; }
.detail-eyebrow.status-open .status-dot { background: var(--green); }
.detail-eyebrow.status-closed .status-dot { background: #94a3b8; }
.detail-eyebrow.status-under-review .status-dot { background: #fbbf24; }
.detail-eyebrow.status-in-progress .status-dot { background: #60a5fa; }
.detail-eyebrow.status-declined .status-dot { background: var(--red); }
.detail-eyebrow.status-done .status-dot { background: var(--green); }
.detail-section { padding: 15px 24px; border-bottom: 1px solid rgba(120, 150, 200, .12); }
.detail-section h3 { margin: 0 0 9px; color: var(--text-muted); font-size: 9px; letter-spacing: .07em; text-transform: uppercase; }
.detail-section > div { color: #c7d2e1; font-size: 11.5px; line-height: 1.58; overflow-wrap: anywhere; }
.detail-section a { color: #67dcef; }
.fact-list { margin: 0; }
.fact-list > div + div { margin-top: 7px; }
.fact-list dt { color: var(--text-muted); font-size: 8.5px; font-weight: 700; }
.fact-list dd { margin: 2px 0 0; }

.model-detail-header { padding-bottom: 15px; }
.model-tabs {
  position: sticky; z-index: 3; top: 0; display: flex; min-height: 42px; overflow-x: auto;
  border-bottom: 1px solid var(--line); background: rgba(8, 14, 26, .98);
}
.model-tabs button {
  flex: 0 0 auto; min-width: 88px; padding: 0 14px; border: 0; border-right: 1px solid rgba(120, 150, 200, .1);
  border-bottom: 2px solid transparent; background: transparent; color: var(--text-muted); font-size: 9.5px; font-weight: 700; cursor: pointer;
}
.model-tabs button:hover { color: var(--text); background: rgba(255, 255, 255, .025); }
.model-tabs button[aria-selected="true"] { border-bottom-color: var(--cyan); color: #d9f8fc; background: rgba(34, 211, 238, .06); }
.model-tab-panel { min-width: 0; }
.pr-summary {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 17px 24px;
  border-bottom: 1px solid rgba(120, 150, 200, .12); background: rgba(52, 211, 153, .035);
}
.pr-summary > div { min-width: 0; }
.pr-summary strong, .pr-summary small { display: block; }
.pr-summary strong { margin-top: 7px; color: var(--text); font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.pr-summary small { margin-top: 4px; color: var(--text-muted); font: 8.5px var(--mono); }
.pr-state { display: inline-flex; padding: 2px 6px; border: 1px solid var(--line); border-radius: 7px; color: var(--text-dim); font-size: 8px; font-weight: 750; text-transform: uppercase; }
.pr-state-open { border-color: rgba(52, 211, 153, .3); color: #a7f3d0; }
.pr-state-closed { border-color: rgba(148, 163, 184, .28); color: #cbd5e1; }
.pr-state-merged { border-color: rgba(168, 85, 247, .32); color: #e9d5ff; }
.check-list { margin: 0; padding: 0; list-style: none; }
.check-list li { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(120, 150, 200, .09); color: var(--text-muted); font-size: 9.5px; }
.check-list li span { color: #64748b; }
.check-list li.is-checked { color: #d7e3ef; }
.check-list li.is-checked span { color: var(--green); }
.copy-block { margin: 0; white-space: normal; }
.empty-value { color: var(--text-muted); font-style: italic; }
.source-link {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  padding: 5px 8px;
  border: 1px solid rgba(34, 211, 238, .2);
  border-radius: 7px;
  background: rgba(34, 211, 238, .06);
  color: #7de5f3;
  font-size: 9px;
  font-weight: 700;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.source-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.model-relation .source-link { margin-top: 11px; }

.empty-state { position: absolute; z-index: 4; top: 50%; left: 50%; width: min(390px, calc(100% - 40px)); padding: 24px; transform: translate(-50%, -50%); border: 1px solid var(--line); border-radius: 14px; background: rgba(11, 17, 32, .96); box-shadow: 0 18px 48px rgba(0, 0, 0, .5); text-align: center; }
.empty-state strong { display: block; margin-bottom: 8px; color: #fca5a5; }
.empty-state p { color: var(--text-dim); font-size: 11px; line-height: 1.5; }
.empty-state button { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-solid); cursor: pointer; }

@media (max-width: 1180px) {
  .canonical-stats .stat:nth-of-type(2), .canonical-stats .stat:nth-of-type(4) { display: none; }
  .search-wrap { width: min(270px, 24vw); }
}
@media (max-width: 900px) {
  .topbar-stats { display: none; }
  .search-wrap { width: min(330px, 44vw); }
  .brand-copy small { display: none; }
}
@media (max-width: 680px) {
  .topbar { gap: 9px; padding: 0 10px; }
  .brand-copy strong { font-size: 13px; }
  .brand-mark { width: 30px; height: 30px; }
  .search-wrap { flex: 1; width: auto; }
  .search-box { height: 38px; }
  .tree-workspace, .app-shell.drawer-open .tree-workspace { right: 0; }
  #tree-canvas { width: 1100px; height: 100%; }
  .bottom-legend { right: 10px; bottom: 10px; left: 10px; max-width: none; overflow-x: auto; }
  .semantic-legend { display: none; }
  .canvas-controls, .app-shell.drawer-open .canvas-controls { right: 10px; bottom: 58px; }
  .canvas-controls output, .canvas-controls button:nth-of-type(1), .canvas-controls button:nth-of-type(2) { display: none; }
  .canvas-hint { top: 70px; width: max-content; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-panel { top: auto; bottom: 0; left: 0; width: 100%; max-height: 72dvh; border-top: 1px solid var(--line); border-left: 0; transform: translateY(100%); }
  .detail-panel.is-open { transform: translateY(0); }
  .detail-content { max-height: calc(72dvh - 42px); }
  .pr-summary { padding: 14px 16px; }
  .detail-section { padding-right: 16px; padding-left: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation: none !important; }
}

html * { letter-spacing: 0 !important; }
