/* ConduitFlow theme */
:root {
  --navy: #1A3A6D;
  --navy-900: color-mix(in srgb, var(--navy) 68%, #000);
  --navy-800: color-mix(in srgb, var(--navy) 82%, #000);
  --navy-700: var(--navy);
  --navy-600: color-mix(in srgb, var(--navy) 86%, #fff);
  --navy-500: color-mix(in srgb, var(--navy) 62%, #fff);
  --cyan: #00D2FF;
  --cyan-soft: color-mix(in srgb, var(--cyan) 13%, transparent);
  --risk-high: #FB7185;
  --risk-medium: #F59E0B;
  --risk-low: #2DD4BF;
  --risk-high-bg: rgba(251, 113, 133, 0.12);
  --risk-medium-bg: rgba(245, 158, 11, 0.13);
  --risk-low-bg: rgba(45, 212, 191, 0.14);

  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --border: #E4E8EF;
  --border-strong: #CFD6E0;
  --text: #0F172A;
  --text-muted: #5B6678;
  --text-faint: #8A95A8;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.08);

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

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01", "ss03";
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* App shell ------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 420ms cubic-bezier(0.4, 0, 0.2, 1);
}
.app.nav-collapsed { grid-template-columns: 0 1fr; }
.app.nav-collapsed .sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Sidebar collapse / reopen */
.sb-collapse {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  color: #9FB0CC;
  cursor: pointer;
}
.sb-collapse:hover { color: #fff; background: rgba(255,255,255,0.10); }
.nav-reopen {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--navy-900);
  border: none;
  border-radius: 8px;
  color: #DCE5F2;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}
.nav-reopen:hover { color: #fff; }
.app.nav-collapsed .topbar { padding-left: 58px; }
.app.nav-collapsed .topbar { transition: padding-left 420ms cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes navReopenIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
.nav-reopen { animation: navReopenIn 300ms 120ms cubic-bezier(0.4, 0, 0.2, 1) both; }

/* Sidebar --------------------------------------------------------------- */
.sidebar {
  background: var(--navy-900);
  color: #DCE5F2;
  display: flex;
  flex-direction: column;
  transition: width 420ms cubic-bezier(0.4, 0, 0.2, 1), padding 420ms cubic-bezier(0.4, 0, 0.2, 1), opacity 300ms ease;
  padding: 20px 0;
}
.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 16px;
}
.sb-logo-mark {
  width: 30px; height: 30px;
  object-fit: contain;
  flex-shrink: 0;
}
.sb-logo-name {
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
  font-size: 15px;
}
.sb-logo-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}
.sb-section-label {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  padding: 14px 20px 6px;
}
.sb-nav { display: flex; flex-direction: column; }
.sb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  color: rgba(255,255,255,0.78);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  text-align: left;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.sb-item:hover { background: rgba(255,255,255,0.04); color: #fff; }
.sb-item.active {
  background: rgba(0, 210, 255, 0.08);
  color: #fff;
  border-left-color: var(--cyan);
}
.sb-item svg { flex-shrink: 0; opacity: 0.9; }
.sb-item .count {
  margin-left: auto;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.sb-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 11.5px;
  color: rgba(255,255,255,0.55);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-footer .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--risk-low);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.18);
}

/* Topbar + content ------------------------------------------------------ */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}
.tb-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.tb-crumb b { color: var(--text); font-weight: 600; }
.tb-crumb .sep { color: var(--text-faint); }
.tb-search {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  width: 280px;
  color: var(--text-faint);
  font-size: 13px;
}
.tb-search input {
  border: none; background: none; outline: none; flex: 1;
  font-size: 13px; color: var(--text);
}
.tb-icon {
  width: 34px; height: 34px;
  border-radius: var(--radius);
  display: grid; place-items: center;
  color: var(--text-muted);
  background: none; border: 1px solid transparent;
  position: relative;
}
.tb-icon:hover { background: var(--bg); color: var(--text); }
.tb-icon .badge-dot {
  position: absolute; top: 7px; right: 8px;
  width: 8px; height: 8px;
  background: var(--risk-high);
  border-radius: 50%;
  border: 2px solid #fff;
}
.tb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4F7BC5, #1A3A6D);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.tb-org {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 6px;
  border-radius: var(--radius);
  cursor: pointer;
}
.tb-org:hover { background: var(--bg); }
.tb-org-mark {
  width: 26px; height: 26px;
  background: var(--navy);
  color: #fff;
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.02em;
}
.tb-org-name { font-weight: 600; font-size: 13.5px; }
.tb-org-sub { font-size: 11.5px; color: var(--text-muted); }

.content {
  flex: 1;
  overflow: auto;
  padding: 24px 28px 40px;
}

/* Cards / common -------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.card-sub { font-size: 12px; color: var(--text-muted); }
.card-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.page-header {
  display: flex;
  align-items: flex-end;
  margin-bottom: 20px;
  gap: 16px;
}
.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.018em;
  margin: 0;
}
.page-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}
.page-actions { margin-left: auto; display: flex; gap: 8px; }

/* Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background 120ms;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-primary:hover { background: var(--navy-600); }
.btn-cyan {
  background: var(--cyan);
  color: var(--navy-900);
  border-color: var(--cyan);
  font-weight: 600;
}
.btn-cyan:hover { background: #1FDDFF; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* Risk pills ------------------------------------------------------------ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.pill-high { background: var(--risk-high-bg); color: #BE2A45; }
.pill-medium { background: var(--risk-medium-bg); color: #B0700A; }
.pill-low { background: var(--risk-low-bg); color: #0F8A7C; }
.pill-plain {
  background: var(--bg);
  color: var(--text-muted);
}
.pill-plain::before { display: none; }

/* Score chips ----------------------------------------------------------- */
.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 2px 8px 2px 6px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 12.5px;
}
.score-chip .bar {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: rgba(15, 23, 42, 0.06);
  position: relative;
  overflow: hidden;
}
.score-chip .bar > i {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 2px;
  display: block;
  background: currentColor;
}

/* Table ----------------------------------------------------------------- */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.tbl thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 14px;
  background: #FAFBFD;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tbl thead th:hover { color: var(--text); }
.tbl thead th .arr { opacity: 0.6; margin-left: 4px; }
.tbl tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tbody tr:hover td { background: #FAFBFD; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl .right { text-align: right; }
.tbl .strong { font-weight: 600; color: var(--text); }
.tbl .muted { color: var(--text-muted); }
.cell-stack { display: flex; flex-direction: column; gap: 2px; }
.cell-stack .sub { font-size: 11.5px; color: var(--text-muted); }

/* Sparkline ------------------------------------------------------------- */
.spark { display: block; }

/* KPI ------------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.kpi-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.kpi-delta {
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.kpi-delta.up { color: #BE2A45; }
.kpi-delta.down { color: #0F8A7C; }
.kpi-icon {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--cyan-soft);
  color: var(--navy);
}

/* Dashboard layout ------------------------------------------------------ */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}

/* Top-risk list --------------------------------------------------------- */
.tr-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.tr-item:last-child { border-bottom: none; }
.tr-rank {
  width: 22px; height: 22px;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tr-body { flex: 1; min-width: 0; }
.tr-name { font-weight: 500; font-size: 13px; }
.tr-bar {
  height: 4px;
  background: rgba(15,23,42,0.06);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
  position: relative;
}
.tr-bar > i { position: absolute; left:0; top:0; bottom:0; border-radius:2px; }
.tr-score { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }

/* Segmented ------------------------------------------------------------- */
.seg {
  display: inline-flex;
  background: var(--bg);
  border-radius: 7px;
  padding: 2px;
  border: 1px solid var(--border);
}
.seg button {
  border: none;
  background: none;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 5px;
}
.seg button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Filter chip ----------------------------------------------------------- */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}
.filter-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px 5px 30px;
  font-size: 13px;
  min-width: 240px;
  position: relative;
}

/* BOM graph ------------------------------------------------------------- */
.graph-wrap {
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 16px;
}
/* Full-width, movable canvas */
.graph-stage {
  position: relative;
  width: 100%;
  height: calc(100vh - 56px - 132px);
  min-height: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.graph-stage.dragging { cursor: grabbing; }
.graph-stage .bg-layer {
  position: absolute; inset: 0;
  background-color: #FAFBFD;
  background-image: radial-gradient(circle, #E1E6EE 1.1px, transparent 1.1px);
  background-size: 22px 22px;
}
.graph-stage.nogrid .bg-layer { background-image: none; }
.graph-viewport {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.graph-viewport svg { display: block; }
.graph-canvas {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 620px;
  position: relative;
  overflow: hidden;
}
.graph-canvas svg { display: block; width: 100%; height: 100%; }

/* Floating overlay panels on the stage */
.graph-float {
  position: absolute;
  z-index: 4;
  width: 268px;
  max-height: calc(100% - 28px);
  overflow: auto;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.graph-float.left { left: 14px; top: 14px; }
.graph-float.right { right: 14px; top: 14px; width: 300px; }
.graph-float .card-header { background: transparent; }

/* Zoom / move controls */
.graph-controls {
  position: absolute;
  right: 14px; bottom: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
.graph-controls .grp {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.graph-controls button {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.graph-controls .grp button:last-child { border-bottom: none; }
.graph-controls button:hover { background: var(--bg); color: var(--text); }
.graph-zoom-readout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  padding: 5px 0;
  text-align: center;
  font-weight: 600;
}
.graph-hint {
  position: absolute;
  left: 14px; bottom: 14px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.legend {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  z-index: 4;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  display: flex; gap: 14px;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-sm);
}
.legend .swatch {
  display: inline-flex; align-items: center; gap: 6px;
}
.legend .swatch i {
  width: 10px; height: 10px; border-radius: 50%;
}

/* Side panel ------------------------------------------------------------ */
.side-panel-section { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.side-panel-section:last-child { border-bottom: none; }
.kv-row { display:flex; justify-content:space-between; padding: 4px 0; font-size: 13px; }
.kv-row .k { color: var(--text-muted); }
.kv-row .v { font-weight: 500; font-variant-numeric: tabular-nums; }

/* Tabs ------------------------------------------------------------------ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 18px; }
.tab {
  padding: 12px 12px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.on { color: var(--text); border-bottom-color: var(--navy); }

/* Supplier hero --------------------------------------------------------- */
.sup-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 18px 20px;
  align-items: center;
}
.sup-hero-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.sup-hero-meta {
  display: flex; gap: 16px; align-items: center;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12.5px;
}
.sup-hero-meta span { display: inline-flex; gap: 5px; align-items: center; }
.score-dial {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px 8px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.score-dial .big {
  font-size: 28px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.score-dial .lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Line chart axis */
.lc-axis { font-size: 10.5px; fill: var(--text-faint); }
.lc-grid { stroke: var(--border); stroke-dasharray: 3 3; }
.lc-threshold { stroke: var(--risk-high); stroke-dasharray: 4 3; }
.lc-line { stroke: var(--navy); stroke-width: 2; fill: none; }
.lc-area { fill: url(#lc-grad); }
.lc-dot { fill: var(--navy); }

/* What-if --------------------------------------------------------------- */
.wi-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
}
.toggle {
  width: 38px; height: 22px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  border: none;
  padding: 0;
  transition: background 160ms;
}
.toggle::after {
  content: "";
  position: absolute;
  left: 2px; top: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left 160ms;
  box-shadow: 0 1px 2px rgba(0,0,0,0.18);
}
.toggle.on { background: var(--navy); }
.toggle.on::after { left: 18px; }

/* AI Assistant ---------------------------------------------------------- */
.chat-wrap {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  height: calc(100vh - 56px - 64px - 24px);
}
.chat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-scroll { flex: 1; overflow: auto; padding: 24px 26px; }
.msg { display: flex; gap: 12px; margin-bottom: 22px; }
.msg-avatar {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  display: grid; place-items: center;
  font-weight: 600; font-size: 12px;
}
.msg-avatar.user {
  background: linear-gradient(135deg, #4F7BC5, #1A3A6D);
  color: #fff;
}
.msg-avatar.ai {
  background: linear-gradient(135deg, var(--cyan), #5BB6FF);
  color: var(--navy-900);
}
.msg-body { flex: 1; min-width: 0; }
.msg-name { font-weight: 600; font-size: 12.5px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.msg-name .when { color: var(--text-faint); font-weight: 400; font-size: 11.5px; }
.msg-text { font-size: 14px; line-height: 1.6; color: var(--text); }
.msg-text p { margin: 0 0 10px; }

.ai-callout {
  background: var(--bg);
  border-left: 3px solid var(--cyan);
  border-radius: 0 8px 8px 0;
  padding: 12px 14px;
  margin: 10px 0 12px;
  font-size: 13px;
  color: var(--text);
}

.chat-suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 18px 0;
}
.chip-suggest {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text);
}
.chat-input-bar {
  border-top: 1px solid var(--border);
  padding: 14px 18px;
  display: flex; align-items: center; gap: 10px;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
}
.chat-input:focus { border-color: var(--navy); background: #fff; }

.ctx-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ctx-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.ctx-section:last-child { border-bottom: none; }
.ctx-label {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.ctx-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px 4px 6px;
  font-size: 12.5px;
  margin: 0 4px 4px 0;
}
.ctx-pill i {
  width: 8px; height: 8px; border-radius: 2px; display: inline-block;
}

/* Upload ---------------------------------------------------------------- */
.upload-wrap {
  max-width: 1100px;
  margin: 0 auto;
}
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.dropzone {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
}
.dropzone.success { border-style: solid; border-color: var(--risk-low); background: linear-gradient(180deg, rgba(45,212,191,0.04), #fff); }
.dz-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--cyan-soft);
  color: var(--navy);
  display: grid; place-items: center;
  margin-bottom: 8px;
}
.dz-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.dz-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.dz-area {
  margin-top: 14px;
  padding: 26px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  text-align: center;
  background: #FAFBFD;
}
.dz-area .or { color: var(--text-faint); font-size: 12px; margin: 8px 0; }
.dz-cols {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 12px;
}
.dz-col {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  color: var(--text-muted);
}
.dz-progress {
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.dz-stage {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px;
}
.dz-stage .b {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  color: var(--text-faint);
  font-size: 11px; font-weight: 600;
}
.dz-stage.on .b { background: var(--risk-low); border-color: var(--risk-low); color: #fff; }
.dz-stage.cur .b { background: var(--navy); border-color: var(--navy); color: #fff; }
.dz-bar {
  margin-left: auto;
  width: 90px; height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}
.dz-bar i { display: block; height: 100%; background: var(--risk-low); }

.warn-panel {
  margin-top: 16px;
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.32);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
}
.warn-panel .ico {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.16);
  color: #B0700A;
  display: grid; place-items: center;
  flex-shrink: 0;
}

.steps-bar {
  display: flex;
  gap: 0;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.steps-bar .step {
  flex: 1;
  padding: 14px 16px;
  border-right: 1px solid var(--border);
  display: flex; gap: 10px;
  align-items: center;
}
.steps-bar .step:last-child { border-right: none; }
.steps-bar .step .n {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg); color: var(--text-muted);
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600;
}
.steps-bar .step.cur .n { background: var(--navy); border-color: var(--navy); color: #fff; }
.steps-bar .step.done .n { background: var(--risk-low); border-color: var(--risk-low); color: #fff; }
.steps-bar .step .ttl { font-size: 13px; font-weight: 500; }
.steps-bar .step .sub { font-size: 11.5px; color: var(--text-muted); }

.divider-h { height: 1px; background: var(--border); margin: 14px 0; }

/* Scrollbars ------------------------------------------------------------ */
.content::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.content::-webkit-scrollbar-thumb, .chat-scroll::-webkit-scrollbar-thumb {
  background: rgba(15,23,42,0.16); border-radius: 6px;
}
.content::-webkit-scrollbar-thumb:hover, .chat-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(15,23,42,0.26);
}

/* BOM graph — full width + pannable ------------------------------------- */
.graph-side { align-self: start; }
.graph-canvas svg { user-select: none; touch-action: none; }

.graph-stage-full { position: relative; }
.graph-canvas.full {
  height: calc(100vh - 56px - 132px);
  min-height: 460px;
}
.graph-stage-full.has-bar .graph-canvas.full {
  height: calc(100vh - 56px - 132px - 60px);
  min-height: 420px;
}

/* Product dropdown bar (above the graph) -------------------------------- */
.product-bar {
  position: relative;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.product-bar-label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.product-dd { position: relative; }
.product-dd-trigger {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 360px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-align: left;
}
.product-dd-trigger:hover { border-color: #B9C2D0; }
.product-dd-name { font-weight: 600; font-size: 14px; color: var(--text); }
.product-dd-sku {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  color: var(--text-muted);
}
.product-dd-risk {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.product-dd-caret { display: inline-flex; transition: transform 0.15s ease; }
.product-dd-caret.open { transform: rotate(180deg); }

.product-dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.product-dd-meta {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.product-dd-list { padding: 12px 12px 14px; }
.product-dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.product-dd-item:hover { background: var(--bg); color: var(--text); }
.product-dd-item.active { background: var(--bg); color: var(--text); font-weight: 600; }
.product-dd-item-risk {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
}

.graph-wrap-noleft { grid-template-columns: 1fr 320px; }
.graph-wrap-bare { grid-template-columns: 1fr; }

/* Collapsible detail drawer --------------------------------------------- */
.drawer-close {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.drawer-close:hover { color: var(--text); border-color: #B9C2D0; }

.detail-reopen {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.detail-reopen:hover { border-color: #B9C2D0; }
.detail-reopen-label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail-reopen-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.detail-reopen-inline { position: static; align-self: start; }

.graph-float {
  position: absolute;
  top: 14px;
  z-index: 6;
  max-height: calc(100% - 28px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius);
}
.graph-float .card { box-shadow: none; }
.graph-float-left { left: 14px; width: 252px; }
.graph-float-right { right: 14px; width: 320px; }
.graph-float::-webkit-scrollbar { width: 8px; }
.graph-float::-webkit-scrollbar-thumb { background: rgba(15,23,42,0.16); border-radius: 6px; }

/* zoom controls */
.zoom-ctrl {
  position: absolute;
  bottom: 14px; left: 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  z-index: 7;
}
.bom-full .zoom-ctrl { left: 14px; right: auto; }
.zoom-ctrl button {
  width: 34px; height: 32px;
  background: var(--surface);
  border: none;
  color: var(--text-muted);
  display: grid; place-items: center;
}
.zoom-ctrl button:hover { background: var(--bg); color: var(--text); }
.zoom-pct {
  background: var(--surface);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.pan-hint {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  background: rgba(15,23,42,0.7);
  color: #fff;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  animation: panhint 4.5s ease forwards;
}
.bom-full .pan-hint { left: calc(50% - 34px); }
@keyframes panhint {
  0% { opacity: 0; } 12% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; }
}

/* Density --------------------------------------------------------------- */
[data-density="compact"] .content { padding: 16px 20px 32px; }
[data-density="comfy"]   .content { padding: 32px 38px 56px; }
[data-density="compact"] .tbl tbody td { padding: 8px 14px; }
[data-density="comfy"]   .tbl tbody td { padding: 16px 14px; }
[data-density="compact"] .kpi { padding: 12px 14px; }
[data-density="comfy"]   .kpi { padding: 20px 22px; }
