:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --muted: #64748b;
  --text: #0f172a;
  --line: #cbd5e1;
  --blue: #1f4e78;
  --blue2: #d9eaf7;
  --red: #b91c1c;
  --orange: #b45309;
  --green: #166534;
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #eef2f7;
}
.app-header {
  background: linear-gradient(135deg, #0f172a, #1f4e78);
  color: white;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
}
.app-header h1 { margin: 0 0 6px; font-size: 26px; }
.app-header p { margin: 0; color: #dbeafe; max-width: 900px; }
.header-actions { display: flex; gap: 8px; }
button {
  border: 0;
  background: var(--blue);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 650;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: #475569; }
.upload-card {
  margin: 18px 24px;
  padding: 16px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
#uploadForm { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
input[type="file"], input[type="search"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}
input[type="search"] { width: 100%; }
#statusText { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); margin-top: 10px; font-size: 14px; }
.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  padding: 0 24px 24px;
}
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.side-panel section, .workspace {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.side-panel section { padding: 14px; }
h2 { margin: 0 0 10px; font-size: 16px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.download-links a {
  display: inline-block;
  margin: 8px 8px 0 0;
  color: var(--blue);
  font-weight: 700;
}
.download-links a.dl-primary {
  background: var(--blue);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
}
.search-results { margin-top: 8px; max-height: 220px; overflow: auto; }
.search-hit {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.search-hit:hover { background: #eff6ff; }
.save-box { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.save-box input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
  width: 100%;
}
.saved-list { max-height: 260px; overflow: auto; }
.saved-hit {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.saved-hit:hover { background: #eff6ff; border-color: var(--blue); }
.saved-hit b { color: var(--blue); }
.details, .ai-summary {
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.workspace { min-height: 720px; overflow: hidden; }
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  border-radius: 0;
  background: white;
  color: var(--text);
  border-right: 1px solid var(--line);
}
.tab.active { background: var(--blue2); color: var(--blue); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.diagram-toolbar {
  height: 42px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.diagram-viewport {
  height: calc(100vh - 260px);
  min-height: 640px;
  overflow: hidden;
  position: relative;
  background-image: radial-gradient(#dbe3ef 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
}
.diagram-viewport.dragging { cursor: grabbing; }
.diagram-canvas {
  position: absolute;
  transform-origin: 0 0;
  width: 2000px;
  height: 2000px;
}
#edgesSvg {
  position: absolute;
  left: 0;
  top: 0;
  width: 2000px;
  height: 2000px;
  overflow: visible;
  pointer-events: none;
}
.edge-line {
  fill: none;
  stroke: #64748b;
  stroke-width: 2;
}
.node-card {
  position: absolute;
  width: 205px;
  min-height: 82px;
  background: white;
  border: 1px solid #b8c6d9;
  border-radius: 12px;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
  padding: 10px;
  cursor: pointer;
}
.node-card:hover { border-color: var(--blue); box-shadow: 0 10px 22px rgba(31, 78, 120, 0.2); }
.node-card.selected { outline: 3px solid #60a5fa; }
.node-title { font-weight: 800; font-size: 12px; margin-bottom: 4px; word-break: break-word; }
.node-tree { color: var(--blue); font-weight: 800; font-size: 12px; }
.node-type { display: inline-block; font-size: 11px; color: #334155; background: #f1f5f9; border-radius: 999px; padding: 2px 7px; margin: 3px 0; }
.node-rating { font-size: 11px; color: #475569; margin-top: 3px; }
.type-Utility { border-top: 5px solid #7c3aed; }
.type-Transformer { border-top: 5px solid #0891b2; }
.type-Equipment { border-top: 5px solid #2563eb; }
.type-Protective-Device { border-top: 5px solid #dc2626; }
.type-Cable { border-top: 5px solid #16a34a; }
.type-Motor { border-top: 5px solid #ca8a04; }
.type-VFD { border-top: 5px solid #9333ea; }
.node-card.qc-FAIL { border-color: var(--red); background: #fef2f2; box-shadow: 0 0 0 2px var(--red), 0 6px 14px rgba(15, 23, 42, 0.12); }
.node-card.qc-WARNING { border-color: var(--orange); background: #fff7ed; box-shadow: 0 0 0 2px var(--orange), 0 6px 14px rgba(15, 23, 42, 0.12); }
.node-card.qc-UNVERIFIED, .node-card.qc-RFI { border-color: #475569; background: #f8fafc; box-shadow: 0 0 0 2px #475569, 0 6px 14px rgba(15, 23, 42, 0.12); }
.node-card.qc-FAIL:hover { box-shadow: 0 0 0 2px var(--red), 0 10px 22px rgba(31, 78, 120, 0.2); }
.node-card.qc-WARNING:hover { box-shadow: 0 0 0 2px var(--orange), 0 10px 22px rgba(31, 78, 120, 0.2); }
.node-card.qc-UNVERIFIED:hover, .node-card.qc-RFI:hover { box-shadow: 0 0 0 2px #475569, 0 10px 22px rgba(31, 78, 120, 0.2); }
.qc-legend { display: inline-flex; gap: 12px; align-items: center; }
.qc-key { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.qc-key::before { content: ''; width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.qc-k-fail::before { background: var(--red); }
.qc-k-warn::before { background: var(--orange); }
.qc-k-info::before { background: #475569; }
.node-card.reviewed::after { content: '✓'; position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; line-height: 20px; text-align: center; font-size: 13px; font-weight: 700; color: white; background: var(--green); border-radius: 50%; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.3); }

.report-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.report-overlay.hidden { display: none; }
.report-modal { background: white; width: min(760px, 100%); max-height: 88vh; display: flex; flex-direction: column; border-radius: 10px; box-shadow: 0 20px 60px rgba(15, 23, 42, 0.4); overflow: hidden; }
.report-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.report-title { font-size: 16px; font-weight: 700; color: var(--blue); }
.report-title .report-sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 3px; }
.report-close { background: none; border: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.report-close:hover { color: var(--red); }
.report-body { padding: 16px 20px; overflow: auto; }
.report-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); }
.report-empty { color: var(--muted); font-size: 13px; }
.finding-card { border: 1px solid var(--line); border-left-width: 5px; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.finding-card.sev-FAIL { border-left-color: var(--red); }
.finding-card.sev-WARNING { border-left-color: var(--orange); }
.finding-card.sev-UNVERIFIED, .finding-card.sev-RFI { border-left-color: #475569; }
.finding-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.finding-check { font-weight: 600; font-size: 13px; }
.finding-row { font-size: 12.5px; margin: 4px 0; color: var(--text); }
.finding-row b { color: var(--muted); font-weight: 600; }
.finding-calc { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; background: #f1f5f9; padding: 6px 8px; border-radius: 5px; white-space: pre-wrap; }
.review-block { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.review-block label { display: block; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }
.review-block select, .review-block textarea { width: 100%; font: inherit; font-size: 13px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; box-sizing: border-box; }
.review-block textarea { margin-top: 8px; resize: vertical; min-height: 56px; }
.table-wrap { padding: 14px; overflow: auto; height: calc(100vh - 220px); min-height: 680px; }
table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 12px; }
th, td { border: 1px solid var(--line); padding: 8px; vertical-align: top; max-width: 440px; }
th { background: var(--blue); color: white; position: sticky; top: 0; z-index: 2; }
tr:nth-child(even) td { background: #f8fafc; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; font-weight: 800; color: white; font-size: 11px; }
.badge.FAIL { background: var(--red); }
.badge.WARNING, .badge.POSSIBLE { background: var(--orange); }
.badge.UNVERIFIED, .badge.RFI { background: #475569; }
.badge.PASS { background: var(--green); }
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .side-panel { order: 2; }
}
