/* ─────────────────────────────────────────────────────────────────
 * OTM Viewer — read-only, canvas-first layout
 * Layout: top bar · left activity rail · main workspace · slide-in inspector
 * ───────────────────────────────────────────────────────────────── */

:root {
  --topbar-h: 46px;
  --rail-w: 76px;
  --filterbar-h: 44px;
  --inspector-w: 400px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --sev-critical: #ff3b5c;
  --sev-high: #ff8a4a;
  --sev-medium: #ffd24a;
  --sev-low: #4ad6a8;
  --sev-info: #6aa7ff;

  --brand: #7c5cff;
  --brand-2: #2bd4d9;
}

body[data-theme="dark"] {
  --bg: #07090f;
  --bg-2: #0c0f18;
  --bg-3: #11141f;
  --bg-hover: #161a27;
  --bg-active: #1c2030;
  --border: #1d2230;
  --border-strong: #2a3145;
  --text: #e9ecf6;
  --text-2: #aab1c3;
  --text-3: #6b7390;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

body[data-theme="light"] {
  --bg: #f7f8fb;
  --bg-2: #ffffff;
  --bg-3: #ffffff;
  --bg-hover: #eef0f6;
  --bg-active: #e4e7f0;
  --border: #e3e6ee;
  --border-strong: #cdd1dc;
  --text: #0e1322;
  --text-2: #4a5170;
  --text-3: #7b86a3;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "rail   work";
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}
input, select, textarea {
  font-family: inherit;
  color: inherit;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text-2);
}
code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px 0 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--text);
}
.brand:hover { color: var(--brand); }
.brand-name { white-space: nowrap; }

.project-tag {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  min-width: 0;
}
.project-tag-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.project-tag-meta {
  color: var(--text-3);
  font-size: 11.5px;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.kpi-strip {
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-3);
  min-width: 0;
}
.kpi-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.kpi-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kpi.sev-critical-bg { border-color: rgba(255, 59, 92, 0.4); background: rgba(255, 59, 92, 0.06); }
.kpi.sev-critical-bg .kpi-num { color: var(--sev-critical); }
.kpi.sev-high-bg { border-color: rgba(255, 138, 74, 0.4); background: rgba(255, 138, 74, 0.06); }
.kpi.sev-high-bg .kpi-num { color: var(--sev-high); }

.topbar-spacer { flex: 1 1 auto; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cmdk-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12.5px;
  height: 28px;
}
.cmdk-trigger:hover { background: var(--bg-hover); color: var(--text); }
.cmdk-trigger kbd { margin-left: 6px; }

/* ── Buttons / dropdowns ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  font-size: 12.5px;
  height: 28px;
  white-space: nowrap;
  transition: background 100ms, border-color 100ms;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-sm { padding: 4px 10px; font-size: 12px; height: 26px; }
.btn-primary {
  background: linear-gradient(180deg, var(--brand) 0%, #6447ff 100%);
  color: #fff;
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn.full { width: 100%; justify-content: center; }

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border); }

.icon-sun, .icon-moon { display: none; }
body[data-theme="dark"] .icon-moon { display: inline; }
body[data-theme="light"] .icon-sun { display: inline; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 220px;
  z-index: 100;
  display: none;
}
.dropdown-menu.wide { min-width: 460px; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu .menu-section { padding: 6px 8px; }
.menu-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 6px; }
.menu-url-row { display: flex; gap: 6px; }
.menu-url-row input {
  flex: 1;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12.5px;
}
.menu-hint { font-size: 11.5px; color: var(--text-3); margin: 6px 0 0; }
.menu-group-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); padding: 4px 8px; }
.dropdown-menu button:not(.btn) {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 12.5px;
  color: var(--text);
}
.dropdown-menu button:not(.btn):hover { background: var(--bg-hover); }
.dropdown-menu .menu-item .mi-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 4px; font-size: 11px; color: var(--text-2);
}

/* ── Activity rail ─────────────────────────────────────────────── */
.rail {
  grid-area: rail;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 8px 6px;
  gap: 4px;
}
.rail-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px;
  border-radius: var(--radius-md);
  color: var(--text-3);
  transition: background 100ms, color 100ms;
  min-width: 0;
}
.rail-btn:hover { background: var(--bg-hover); color: var(--text); }
.rail-label {
  font-size: 9.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.rail-btn .rail-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  background: var(--sev-critical);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Workspace & views ─────────────────────────────────────────── */
.workspace {
  grid-area: work;
  position: relative;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
}

.view {
  display: none;
  grid-row: 2;
  grid-column: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* Filter bar lives at row 1 of the workspace.
 * position+z-index needed so its multi-select dropdowns paint above the
 * cytoscape canvas (which creates its own stacking context).
 * overflow is left at the default `visible` so dropdowns aren't clipped —
 * CSS makes a single overflow:auto axis force the other to auto too. */
.filterbar {
  grid-row: 1;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: var(--filterbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  position: relative;
  z-index: 30;
}
.fb-group { display: inline-flex; align-items: center; gap: 4px; }
.fb-divider { width: 1px; height: 22px; background: var(--border); }
.fb-spacer { flex: 1 1 auto; }
.fb-chips { gap: 4px; }
.fb-search {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  width: 200px;
}
.fb-search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 12.5px;
  color: var(--text);
  min-width: 0;
}
.fb-tools { display: inline-flex; align-items: center; gap: 4px; }
.fb-select {
  height: 26px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
}
.fb-reset {
  height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12px;
  background: transparent;
}
.fb-reset:hover { color: var(--text); background: var(--bg-hover); }

/* fb-multi dropdown for zones/types */
.fb-multi { position: relative; }
.fb-multi-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12.5px;
  white-space: nowrap;
}
.fb-multi-trigger:hover { background: var(--bg-hover); }
.fb-multi-label { color: var(--text-2); }
.fb-multi-count {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.fb-multi-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 9999;
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 240px;
  max-height: 320px;
  overflow: auto;
}
.fb-multi.open .fb-multi-menu { display: block; }
.fb-multi-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
}
.fb-multi-row:hover { background: var(--bg-hover); }
.fb-multi-row input { margin: 0; accent-color: var(--brand); }
.fb-multi-row .fb-multi-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-multi-row .fb-multi-meta { color: var(--text-3); font-size: 11px; font-family: var(--font-mono); }
.fb-multi-actions {
  display: flex; justify-content: space-between;
  padding: 4px 6px 0;
  margin-top: 4px; border-top: 1px solid var(--border);
}
.fb-multi-actions button {
  font-size: 11.5px; color: var(--text-3); padding: 4px 6px; border-radius: 4px;
}
.fb-multi-actions button:hover { color: var(--text); background: var(--bg-hover); }

/* Severity chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 8px;
  border-radius: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 100ms, border-color 100ms, color 100ms, opacity 100ms;
}
.chip:hover { background: var(--bg-hover); color: var(--text); }
.chip .chip-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.chip[aria-pressed="false"] { opacity: 0.4; }
.chip.sev-critical { color: var(--sev-critical); border-color: rgba(255, 59, 92, 0.35); }
.chip.sev-high     { color: var(--sev-high);     border-color: rgba(255, 138, 74, 0.35); }
.chip.sev-medium   { color: #d6a72c;             border-color: rgba(255, 210, 74, 0.35); }
.chip.sev-low      { color: var(--sev-low);      border-color: rgba(74, 214, 168, 0.35); }
.chip.sev-info     { color: var(--sev-info);     border-color: rgba(106, 167, 240, 0.35); }
.chip[aria-pressed="true"].sev-critical { background: rgba(255, 59, 92, 0.10); }
.chip[aria-pressed="true"].sev-high     { background: rgba(255, 138, 74, 0.10); }
.chip[aria-pressed="true"].sev-medium   { background: rgba(255, 210, 74, 0.10); }
.chip[aria-pressed="true"].sev-low      { background: rgba(74, 214, 168, 0.10); }
.chip[aria-pressed="true"].sev-info     { background: rgba(106, 167, 240, 0.10); }

/* Show filter bar only on these views */
body[data-view="diagram"]    .filterbar,
body[data-view="threats"]    .filterbar,
body[data-view="components"] .filterbar,
body[data-view="flows"]      .filterbar { display: flex; }
body[data-view="diagram"] #fb-diagram-tools { display: inline-flex; }
body:not([data-view="diagram"]) #fb-diagram-tools { display: none; }

/* Active view */
body[data-view="overview"]    #view-overview    { display: block; overflow: auto; }
body[data-view="diagram"]     #view-diagram     { display: block; position: relative; }
body[data-view="threats"]     #view-threats     { display: block; overflow: auto; }
body[data-view="components"]  #view-components  { display: block; overflow: auto; }
body[data-view="flows"]       #view-flows       { display: block; overflow: auto; }
body[data-view="mitigations"] #view-mitigations { display: block; overflow: auto; }

/* Activity rail active state mirrors data-view */
body[data-view="overview"]    .rail-btn[data-view="overview"],
body[data-view="diagram"]     .rail-btn[data-view="diagram"],
body[data-view="threats"]     .rail-btn[data-view="threats"],
body[data-view="components"]  .rail-btn[data-view="components"],
body[data-view="flows"]       .rail-btn[data-view="flows"],
body[data-view="mitigations"] .rail-btn[data-view="mitigations"] {
  background: linear-gradient(180deg, rgba(124, 92, 255, 0.16), rgba(43, 212, 217, 0.10));
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--brand);
}

/* Hide views & filter bar before an OTM is loaded */
body[data-has-otm="false"] .view,
body[data-has-otm="false"] .filterbar,
body[data-has-otm="false"] .kpi-strip,
body[data-has-otm="false"] .project-tag { display: none !important; }
body[data-has-otm="true"] #empty-state { display: none !important; }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 5;
}
.empty-inner {
  text-align: center;
  max-width: 480px;
  padding: 32px;
}
.empty-icon { color: var(--brand); margin-bottom: 14px; opacity: 0.95; }
.empty-state h2 { margin: 0 0 6px; font-size: 22px; }
.empty-state p { margin: 0 0 16px; color: var(--text-2); }
.empty-actions { display: flex; gap: 8px; justify-content: center; margin-bottom: 18px; }
.hint-list { list-style: none; padding: 0; margin: 0; display: flex; gap: 14px; justify-content: center; color: var(--text-3); font-size: 12px; }
.hint-list li { display: inline-flex; gap: 6px; align-items: center; }

/* ── Diagram view ──────────────────────────────────────────────── */
#view-diagram { position: relative; }
.canvas {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(124, 92, 255, 0.06), transparent),
    radial-gradient(1000px 500px at 100% 100%, rgba(43, 212, 217, 0.05), transparent),
    var(--bg);
}
body[data-theme="light"] .canvas {
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(124, 92, 255, 0.04), transparent),
    radial-gradient(1000px 500px at 100% 100%, rgba(43, 212, 217, 0.04), transparent),
    var(--bg);
}
.minimap {
  position: absolute !important;
  right: 14px !important;
  bottom: 14px !important;
  left: auto !important;
  top: auto !important;
  width: 180px;
  height: 112px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.canvas-toolbar {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

/* ── Overview ──────────────────────────────────────────────────── */
.overview-grid {
  display: grid;
  gap: 14px;
  padding: 18px 20px 28px;
  grid-template-columns: repeat(12, 1fr);
  max-width: 1480px;
  margin: 0 auto;
}
.ov-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  min-width: 0;
}
.ov-card h3 {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 0 0 10px;
}
.ov-project { grid-column: span 12; }
.ov-project h2 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.ov-project p {
  margin: 0;
  color: var(--text-2);
  max-width: 90ch;
  line-height: 1.55;
  white-space: pre-wrap;
}
.ov-project-meta {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-top: 10px;
  color: var(--text-3);
  font-size: 12px;
  font-family: var(--font-mono);
}
.ov-project-meta span strong { color: var(--text-2); font-weight: 500; }

.ov-severity { grid-column: span 6; }
.ov-coverage { grid-column: span 3; }
.ov-abuse    { grid-column: span 3; }
.ov-top      { grid-column: span 7; }
.ov-zones    { grid-column: span 5; }
.ov-risk     { grid-column: span 7; }
.ov-assets   { grid-column: span 5; }
@media (max-width: 1200px) {
  .ov-severity, .ov-coverage, .ov-abuse,
  .ov-top, .ov-zones,
  .ov-risk, .ov-assets { grid-column: span 12; }
}

.sev-bar {
  display: flex;
  width: 100%;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg-3);
  margin-bottom: 10px;
}
.sev-bar span { display: block; height: 100%; }
.sev-bar .sev-critical { background: var(--sev-critical); }
.sev-bar .sev-high     { background: var(--sev-high); }
.sev-bar .sev-medium   { background: var(--sev-medium); }
.sev-bar .sev-low      { background: var(--sev-low); }
.sev-bar .sev-info     { background: var(--sev-info); }
.sev-legend {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}
.sev-legend span {
  display: flex; align-items: center; gap: 6px;
}
.sev-legend .dot { width: 8px; height: 8px; border-radius: 50%; }
.sev-legend .num { font-variant-numeric: tabular-nums; color: var(--text-3); margin-left: auto; }

.ring-wrap {
  display: flex; align-items: center; gap: 12px;
}
.ring {
  --p: 0;
  width: 68px; height: 68px; border-radius: 50%;
  background:
    conic-gradient(var(--brand) calc(var(--p) * 1%), var(--bg-3) 0);
  display: grid; place-items: center;
  position: relative;
}
.ring::after {
  content: attr(data-pct) "%";
  position: absolute;
  inset: 8px;
  background: var(--bg-2);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}
.ring-meta { font-size: 12.5px; color: var(--text-2); }
.ring-meta .ring-meta-2 { color: var(--text-3); font-size: 11.5px; margin-top: 2px; }

/* Lists in overview */
.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  cursor: pointer;
}
.simple-list li:last-child { border-bottom: 0; }
.simple-list li:hover { color: var(--brand-2); }
.simple-list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.simple-list li .meta { color: var(--text-3); font-size: 11.5px; font-family: var(--font-mono); }

/* ── Risk Matrix (Overview & Threats view) ────────────────────── */
.matrix-wrap {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: stretch;
}
.matrix {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 4px;
  min-height: 240px;
}
.matrix-axis-Y {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  align-items: center;
  font-size: 10px;
  color: var(--text-3);
  text-align: right;
  padding-right: 4px;
}
.matrix-axis-X {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
  padding-top: 4px;
}
.matrix-cell {
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  cursor: pointer;
  position: relative;
  transition: transform 100ms, border-color 100ms;
  font-size: 13px;
}
.matrix-cell:hover { transform: scale(1.04); border-color: var(--border-strong); }
.matrix-cell.has { color: var(--text); }
.matrix-cell.sev-critical { background: rgba(255, 59, 92, 0.22); border-color: rgba(255, 59, 92, 0.55); }
.matrix-cell.sev-high     { background: rgba(255, 138, 74, 0.20); border-color: rgba(255, 138, 74, 0.55); }
.matrix-cell.sev-medium   { background: rgba(255, 210, 74, 0.18); border-color: rgba(255, 210, 74, 0.45); }
.matrix-cell.sev-low      { background: rgba(74, 214, 168, 0.18); border-color: rgba(74, 214, 168, 0.45); }
.matrix-cell.sev-info     { background: rgba(106, 167, 240, 0.10); border-color: rgba(106, 167, 240, 0.30); }
.matrix-axis-label {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Data tables (Threats, Components, Flows) ─────────────────── */
.view-body {
  padding: 14px 20px 28px;
  max-width: 1480px;
  margin: 0 auto;
}
.view-head {
  display: flex; align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.view-title { margin: 0; font-size: 16px; }
.view-sub { color: var(--text-3); font-size: 12.5px; }

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-size: 12.5px;
}
.data-table thead th {
  background: var(--bg-3);
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table thead th[data-sort]::after {
  content: "";
  display: inline-block;
  width: 0; height: 0; margin-left: 6px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--text-3);
  opacity: 0;
  transform: translateY(-1px);
}
.data-table thead th.sort-asc::after  { opacity: 1; transform: rotate(180deg) translateY(1px); }
.data-table thead th.sort-desc::after { opacity: 1; }
.data-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; transition: background 80ms; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr.selected { background: var(--bg-active); }

.data-table td .row-name {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.data-table td .row-sub {
  color: var(--text-3);
  font-size: 11.5px;
  margin-top: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}
.data-table td .row-sub.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.data-table td .row-id { font-family: var(--font-mono); color: var(--text-3); font-size: 11.5px; }
.data-table td.num { font-variant-numeric: tabular-nums; text-align: right; }
.data-table td .cell-chips { display: flex; flex-wrap: wrap; gap: 3px; }

/* Severity badge */
.sev-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sev-badge .sev-dot { width: 7px; height: 7px; border-radius: 50%; }
.sev-badge.sev-critical { background: rgba(255, 59, 92, 0.15);  color: var(--sev-critical); }
.sev-badge.sev-high     { background: rgba(255, 138, 74, 0.15); color: var(--sev-high); }
.sev-badge.sev-medium   { background: rgba(255, 210, 74, 0.15); color: #c89629; }
.sev-badge.sev-low      { background: rgba(74, 214, 168, 0.15); color: var(--sev-low); }
.sev-badge.sev-info     { background: rgba(106, 167, 240, 0.15);color: var(--sev-info); }
body[data-theme="light"] .sev-badge.sev-medium { color: #a26b00; }

.sev-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sev-dot.sev-critical { background: var(--sev-critical); }
.sev-dot.sev-high     { background: var(--sev-high); }
.sev-dot.sev-medium   { background: var(--sev-medium); }
.sev-dot.sev-low      { background: var(--sev-low); }
.sev-dot.sev-info     { background: var(--sev-info); }

/* Severity stripe row indicator */
.data-table tbody tr.sev-row-critical td:first-child { box-shadow: inset 3px 0 0 var(--sev-critical); }
.data-table tbody tr.sev-row-high     td:first-child { box-shadow: inset 3px 0 0 var(--sev-high); }
.data-table tbody tr.sev-row-medium   td:first-child { box-shadow: inset 3px 0 0 var(--sev-medium); }
.data-table tbody tr.sev-row-low      td:first-child { box-shadow: inset 3px 0 0 var(--sev-low); }
.data-table tbody tr.sev-row-info     td:first-child { box-shadow: inset 3px 0 0 var(--sev-info); }

/* Tag pills (used in tables and inspector) */
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 11px;
  white-space: nowrap;
}
.tag-pill.clickable { cursor: pointer; }
.tag-pill.clickable:hover { background: var(--bg-hover); color: var(--text); }
.tag-pill.stride  { color: #c4b5fd; border-color: rgba(196, 181, 253, 0.35); background: rgba(196, 181, 253, 0.08); }
.tag-pill.linddun { color: var(--brand-2); border-color: rgba(43, 212, 217, 0.35); background: rgba(43, 212, 217, 0.08); }
.tag-pill.cwe     { color: #ffb74a; border-color: rgba(255, 183, 74, 0.35); background: rgba(255, 183, 74, 0.08); font-family: var(--font-mono); }
.tag-pill.mitre   { color: #ff8a4a; border-color: rgba(255, 138, 74, 0.35); background: rgba(255, 138, 74, 0.08); font-family: var(--font-mono); }
.tag-pill.abuse   { color: var(--sev-critical); border-color: rgba(255, 59, 92, 0.35); background: rgba(255, 59, 92, 0.08); }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-abuse { background: rgba(255, 59, 92, 0.12); color: var(--sev-critical); border-color: rgba(255, 59, 92, 0.35); }
.badge-mini { font-size: 10px; padding: 1px 4px; }

/* Components: zone tag */
.zone-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  white-space: nowrap;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.zone-pill::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--zone-color, var(--text-3));
}

/* Mitigations cards grid */
.mit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.mit-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
  transition: border-color 100ms, transform 100ms;
}
.mit-card:hover { border-color: var(--border-strong); }
.mit-card h4 { margin: 0 0 6px; font-size: 13.5px; }
.mit-card .mit-reduction {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(74, 214, 168, 0.15);
  color: var(--sev-low);
  font-weight: 700;
  font-size: 11.5px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
}
.mit-card .mit-desc { color: var(--text-2); font-size: 12px; margin: 0 0 8px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.mit-card .mit-meta { color: var(--text-3); font-size: 11.5px; }

/* ── Inspector (slide-in) ──────────────────────────────────────── */
.inspector {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--inspector-w);
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transform: translateX(100%);
  transition: transform 180ms ease;
}
.inspector[open] { transform: translateX(0); }
.insp-head {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}
.insp-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
}
.insp-body {
  flex: 1; min-height: 0;
  overflow: auto;
  padding: 14px 16px 24px;
}

.d-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.d-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 14px;
  flex-shrink: 0;
}
.d-icon.sev-critical { background: rgba(255, 59, 92, 0.15);  color: var(--sev-critical); }
.d-icon.sev-high     { background: rgba(255, 138, 74, 0.15); color: var(--sev-high); }
.d-icon.sev-medium   { background: rgba(255, 210, 74, 0.15); color: #c89629; }
.d-icon.sev-low      { background: rgba(74, 214, 168, 0.15); color: var(--sev-low); }
.d-title {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.d-sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.d-desc {
  margin: 0 0 12px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.d-h {
  margin: 16px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
}
.d-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.d-list {
  list-style: none;
  margin: 0; padding: 0;
}
.d-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 12.5px;
  cursor: pointer;
}
.d-list li:hover { background: var(--bg-hover); }
.d-list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-list.mit-list li .mit-num {
  font-weight: 700;
  font-size: 11.5px;
  color: var(--sev-low);
  font-family: var(--font-mono);
  min-width: 36px;
}

.kv {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(110px, 35%) 1fr;
  gap: 4px 12px;
  font-size: 12px;
}
.kv dt {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kv dd { margin: 0; color: var(--text); word-break: break-word; white-space: pre-wrap; }
.kv dd .attr-list { margin: 0; padding-left: 16px; }

.risk-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}
.risk-cell { display: grid; grid-template-columns: 1fr; gap: 2px; }
.risk-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.risk-bar {
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.risk-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--sev-low), var(--sev-medium) 50%, var(--sev-critical));
}
.risk-val { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.risk-val.muted { color: var(--text-3); }

.evidence-list { list-style: none; padding: 0; margin: 0; }
.evidence-list li { margin-bottom: 4px; }
.evidence-list code {
  word-break: break-all;
  display: inline-block;
  font-size: 11px;
}

/* When inspector is open, leave room for it on the workspace */
body[data-inspector="open"] .workspace { padding-right: var(--inspector-w); transition: padding 180ms ease; }
@media (max-width: 1100px) {
  body[data-inspector="open"] .workspace { padding-right: 0; }
}

/* ── Modals ────────────────────────────────────────────────────── */
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 92vw;
}
.modal::backdrop {
  background: rgba(7, 9, 15, 0.6);
  backdrop-filter: blur(4px);
}
.modal-body {
  width: min(640px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  color: var(--text);
}
.modal-body header { margin-bottom: 12px; }
.modal-body header h3 { margin: 0; font-size: 16px; }
.modal-body footer {
  display: flex; gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}
.modal-body textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  resize: vertical;
  outline: 0;
}
.modal-body textarea:focus { border-color: var(--brand); }
.shortcut-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.shortcut-table td { padding: 5px 0; }
.shortcut-table td:first-child { width: 240px; }

.cmdk-modal { width: min(620px, 92vw); padding: 0; background: transparent; }
.cmdk {
  width: min(620px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cmdk-search {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.cmdk-search input {
  flex: 1;
  border: 0;
  outline: 0;
  font-size: 14px;
  background: transparent;
  color: var(--text);
}
.cmdk-list { list-style: none; padding: 6px; margin: 0; max-height: 60vh; overflow: auto; }
.cmdk-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.cmdk-list li:hover, .cmdk-list li.active { background: var(--bg-hover); }
.cmdk-list .ico { width: 22px; text-align: center; color: var(--text-3); }
.cmdk-list .name { font-weight: 500; }
.cmdk-list .meta { color: var(--text-3); font-size: 11.5px; font-family: var(--font-mono); }
.cmdk-list .empty { color: var(--text-3); text-align: center; padding: 14px; cursor: default; }
.cmdk-footer {
  display: flex; gap: 14px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  padding: 8px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms, transform 160ms;
  z-index: 200;
  max-width: 540px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; cursor: pointer; }
.toast.error  { border-color: rgba(255, 59, 92, 0.6); color: var(--sev-critical); }
.toast.success { border-color: rgba(74, 214, 168, 0.6); color: var(--sev-low); }

/* ── Utility ───────────────────────────────────────────────────── */
.muted { color: var(--text-3); }
.small { font-size: 11.5px; }

/* ── Print ─────────────────────────────────────────────────────── */
@media print {
  body { background: #fff; color: #000; display: block; overflow: visible; }
  .topbar, .rail, .filterbar, .inspector, .canvas-toolbar, .minimap { display: none !important; }
  .workspace { padding: 0 !important; height: auto !important; }
  #view-diagram { position: relative !important; width: 100vw !important; height: 100vh !important; }
}
