:root {
  --ink: #17233b;
  --muted: #69758b;
  --line: #d8e0ea;
  --surface: #ffffff;
  --canvas: #f4f7fb;
  --navy: #13263f;
  --blue: #2563eb;
  --orange: #ea7a1b;
  --purple: #8b5cf6;
  --red: #dc3f55;
  --green: #159769;
  --shadow: 0 14px 38px rgba(25, 42, 70, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 1120px; background: var(--canvas); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }

.app-header {
  height: 76px;
  padding: 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: linear-gradient(118deg, #0d2038, #183b5e 68%, #1d4d6f);
  border-bottom: 3px solid #db8a31;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.36); border-radius: 10px;
  font: 700 21px Georgia, serif; color: #ffbd73;
  background: rgba(255,255,255,.06);
}
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .08em; font-weight: 650; }
.brand p { margin: 3px 0 0; font-size: 11px; letter-spacing: .22em; color: #b8c8dc; }
.brand p span { color: #f3a85b; }
.source-badge {
  max-width: 470px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px; color: #cad7e6; background: rgba(0,0,0,.13); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.query-bar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 180px minmax(230px, 1.3fr) repeat(3, minmax(170px, 1fr)) auto;
  align-items: end; gap: 10px; padding: 12px 18px;
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97);
  box-shadow: 0 5px 18px rgba(20, 37, 60, .06);
}
.control { display: flex; min-width: 0; flex-direction: column; gap: 5px; }
.control > span { color: #6c788c; font-size: 11px; font-weight: 700; letter-spacing: .05em; }
.control input, .control select {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid #cbd5e1;
  border-radius: 7px; color: #27364d; background: #fbfcfe; outline: none;
}
.control input:focus, .control select:focus { border-color: #5386d8; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.control.is-disabled { opacity: .38; pointer-events: none; }
.autocomplete-wrap { position: relative; }
.suggestions {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  max-height: 290px; overflow: auto; padding: 5px; border: 1px solid var(--line);
  border-radius: 9px; background: white; box-shadow: var(--shadow);
}
.suggestion { display: flex; gap: 9px; align-items: start; padding: 8px 9px; border-radius: 6px; cursor: pointer; }
.suggestion:hover, .suggestion.active { background: #eef5ff; }
.suggestion .tag { flex: none; padding: 2px 5px; border-radius: 4px; color: #1d5dad; background: #dbeafe; font-size: 10px; }
.suggestion strong { display: block; font-size: 13px; }
.suggestion small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.query-actions { display: flex; gap: 7px; }
.button { height: 38px; padding: 0 14px; border-radius: 7px; border: 1px solid transparent; font-weight: 650; white-space: nowrap; }
.button-primary { color: white; background: #1e5792; box-shadow: 0 5px 12px rgba(30,87,146,.18); }
.button-primary:hover { background: #17497d; }
.button-ghost { color: #526078; border-color: #cbd5e1; background: white; }
.button-ghost:hover { background: #f2f5f9; }

.workspace {
  display: grid; grid-template-columns: minmax(720px, 1fr) 350px; gap: 14px;
  height: calc(100vh - 226px); min-height: 590px; padding: 14px;
}
.map-card, .info-card, .paths-card { border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.map-card { min-width: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: 12px; }
.map-toolbar {
  flex: 0 0 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); background: #fbfcfe;
}
.map-toolbar strong { font-size: 14px; }
.map-toolbar span { margin-left: 9px; color: var(--muted); font-size: 11px; }
.map-controls { display: flex; align-items: center; gap: 4px; }
.map-controls button {
  min-width: 31px; height: 29px; border: 1px solid #ccd5e0; border-radius: 6px;
  color: #45536b; background: white;
}
.map-controls button:hover { color: #174f8a; border-color: #8faed1; }
.map-controls #zoom-level { width: 44px; margin: 0; text-align: center; }
.map-viewport {
  position: relative; flex: 1; overflow: hidden; touch-action: none;
  background-color: #edf2f7;
  background-image: radial-gradient(#b9c6d6 0.65px, transparent .65px);
  background-size: 18px 18px;
}
.svg-host { width: 100%; height: 100%; cursor: grab; user-select: none; }
.svg-host.is-panning { cursor: grabbing; }
.svg-host svg { display: block; width: 100%; height: 100%; }
.map-help {
  position: absolute; left: 12px; bottom: 10px; z-index: 3; pointer-events: none;
  padding: 6px 9px; border-radius: 6px; color: #6a7688; background: rgba(255,255,255,.88); font-size: 10px;
}

.info-card { min-width: 0; overflow: auto; border-radius: 12px; }
.panel-heading {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  min-height: 72px; padding: 15px 17px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96);
}
.eyebrow { color: #8a95a7; font-size: 9px; font-weight: 800; letter-spacing: .18em; }
.panel-heading h2, .paths-heading h2 { margin: 3px 0 0; font-size: 17px; }
.kind-chip { padding: 4px 8px; border-radius: 999px; color: #38516e; background: #e7edf4; font-size: 10px; font-weight: 750; }
.query-status { margin: 13px 15px 0; padding: 10px 11px; border-left: 3px solid #9ca8b8; border-radius: 4px; font-size: 12px; line-height: 1.5; }
.query-status.neutral { color: #667286; background: #f1f4f7; }
.query-status.success { color: #116042; border-color: var(--green); background: #eaf8f1; }
.query-status.warning { color: #92510c; border-color: var(--orange); background: #fff7e8; }
.query-status.error { color: #9b2638; border-color: var(--red); background: #fff0f2; }
.info-content { padding: 16px; color: #47556c; font-size: 12px; line-height: 1.65; }
.info-content .intro { margin-top: 0; }
.logic-note { margin-top: 14px; padding: 12px; border: 1px solid #ecd7bc; border-radius: 8px; background: #fffaf3; }
.logic-note p { margin: 4px 0 0; }
.detail-grid { display: grid; grid-template-columns: 94px 1fr; gap: 0; margin: 0; }
.detail-grid dt, .detail-grid dd { margin: 0; padding: 8px 0; border-bottom: 1px solid #edf0f4; }
.detail-grid dt { color: #8590a1; font-weight: 650; }
.detail-grid dd { color: #344157; overflow-wrap: anywhere; }
.pill-list { display: flex; flex-wrap: wrap; gap: 5px; }
.pill { padding: 3px 7px; border-radius: 999px; color: #375671; background: #eaf0f6; font-size: 10px; }
.warning-box { margin-top: 12px; padding: 10px; border-left: 3px solid var(--orange); background: #fff8ec; }
.path-list { margin: 6px 0 0; padding-left: 18px; }
.path-list li { margin: 7px 0; }

.paths-card { margin: 0 14px 18px; border-radius: 12px; overflow: hidden; }
.paths-heading { display: flex; align-items: center; justify-content: space-between; min-height: 62px; padding: 10px 16px; }
.paths-heading h2 span { color: var(--blue); }
.empty-state { padding: 20px; border-top: 1px solid var(--line); color: #8993a3; text-align: center; font-size: 12px; }
.table-wrap { max-height: 360px; overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; min-width: 1960px; border-collapse: collapse; font-size: 11px; }
th { position: sticky; top: 0; z-index: 2; padding: 9px 10px; color: #56647b; background: #eef2f6; text-align: left; white-space: nowrap; }
td { max-width: 300px; padding: 9px 10px; border-top: 1px solid #e8edf2; color: #3f4d63; vertical-align: top; line-height: 1.5; }
tbody tr:nth-child(even) { background: #fafbfd; }
tbody tr:hover { background: #eef6ff; }
.chain-cell { min-width: 320px; color: #203a58; font-weight: 600; }
.confidence-high { color: #11704b; font-weight: 700; }
.confidence-medium { color: #a15d11; font-weight: 700; }

.tooltip {
  position: fixed; z-index: 100; max-width: 320px; pointer-events: none;
  padding: 9px 11px; border: 1px solid #263a53; border-radius: 7px;
  color: white; background: rgba(17, 31, 49, .96); box-shadow: 0 10px 28px rgba(0,0,0,.22);
  font-size: 11px; line-height: 1.45;
}
.tooltip strong { color: #ffc47f; }
.toast {
  position: fixed; z-index: 120; left: 50%; bottom: 28px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 8px; color: white; background: #182a42;
  box-shadow: 0 12px 34px rgba(0,0,0,.22); font-size: 12px;
}

/* SVG map styling */
.svg-host .region { stroke: #ccd6e3; stroke-width: 1.2; }
.svg-host .region-primary { fill: #f0f6fb; }
.svg-host .region-naphtha { fill: #fffaf1; }
.svg-host .region-vgo { fill: #f4f8f3; }
.svg-host .region-resid { fill: #f9f4f2; }
.svg-host .region-product { fill: #f7f3fb; }
.svg-host .region-utility { fill: #f1f8f5; }
.svg-host .region-title { fill: #314762; font-size: 19px; font-weight: 700; letter-spacing: .04em; }
.svg-host .process-edge {
  fill: none; stroke: #8e9aab; stroke-width: 2; color: #8e9aab;
  marker-end: url(#arrow); opacity: .74; transition: opacity .18s, stroke .18s, stroke-width .18s;
  pointer-events: stroke;
}
.svg-host .process-edge:hover { stroke: #3f74a8; stroke-width: 4; opacity: 1; }
.svg-host .h2-edge { stroke: #44a078; color: #44a078; stroke-dasharray: 7 4; }
.svg-host .unit-label { cursor: pointer; transition: opacity .18s; }
.svg-host .unit-label rect { fill: #fff4e3; stroke: #d87518; stroke-width: 1.7; }
.svg-host .unit-label text { fill: #8d4a0a; font-size: 12px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.svg-host .unit-label:hover rect { fill: #ffe1b8; stroke-width: 2.5; }
.svg-host .unit-warning rect { stroke-dasharray: 5 3; }
.svg-host .material-node { cursor: pointer; transition: opacity .18s; }
.svg-host .material-node rect { fill: var(--node-fill); stroke: #62748a; stroke-width: 1.4; }
.svg-host .material-node text { fill: #26384f; font-size: 12px; font-weight: 650; text-anchor: middle; pointer-events: none; }
.svg-host .material-node:hover rect { stroke: #1d5ea2; stroke-width: 2.6; }
.svg-host .type-product rect { stroke: #7e55a7; }
.svg-host .type-utility rect { stroke: #21825e; }
.svg-host .node-warning rect { stroke: #d26b15; stroke-dasharray: 4 3; }
.svg-host .map-legend rect:first-child { fill: rgba(255,255,255,.9); stroke: #c9d4df; }
.svg-host .map-legend text { fill: #536177; font-size: 12px; }
.svg-host .map-legend .legend-title { fill: #263c57; font-size: 15px; font-weight: 700; }
.svg-host .legend-feed { fill: #dbeafe; stroke: #58728f; }
.svg-host .legend-intermediate { fill: #fef3c7; stroke: #967225; }
.svg-host .legend-product { fill: #f3e8ff; stroke: #7e55a7; }
.svg-host .legend-unit { fill: #fff4e3 !important; stroke: #d87518 !important; }
.svg-host .legend-h2 { stroke: #159769; stroke-width: 3; stroke-dasharray: 7 4; }
.svg-host .legend-note { fill: #7c8798; font-size: 10px; }

/* Query state: dim everything, then light selected graph elements. */
.svg-host.has-highlight .process-edge,
.svg-host.has-highlight .material-node,
.svg-host.has-highlight .unit-label { opacity: .09; }
.svg-host.has-highlight .process-edge.is-relevant { opacity: 1; stroke: var(--purple); color: var(--purple); stroke-width: 5; filter: url(#glow); }
.svg-host.has-highlight .process-edge.is-relevant.h2-edge { stroke: var(--green); color: var(--green); }
.svg-host.has-highlight .material-node.is-relevant,
.svg-host.has-highlight .unit-label.is-relevant { opacity: 1; }
.svg-host .material-node.is-query rect { stroke: var(--blue); stroke-width: 4; filter: url(#glow); }
.svg-host .material-node.is-inferred rect { stroke: var(--purple); stroke-width: 3.4; filter: url(#glow); }
.svg-host .material-node.h2-node.is-relevant rect { stroke: var(--green); stroke-width: 4; filter: url(#glow); }
.svg-host .unit-label.is-relevant rect { fill: #ffd9a7; stroke: var(--orange); stroke-width: 3.2; filter: url(#glow); }

@media (max-width: 1350px) {
  .query-bar { grid-template-columns: 165px minmax(220px, 1.3fr) repeat(3, minmax(145px, 1fr)) auto; }
  .workspace { grid-template-columns: minmax(680px, 1fr) 320px; }
}
