:root {
  color-scheme: dark;
  --bg: #071016;
  --surface-0: #0a141b;
  --surface-1: #0f1b23;
  --surface-2: #14232d;
  --surface-3: #1a2d38;
  --line: #243944;
  --line-strong: #35505d;
  --text: #eaf4f7;
  --soft: #9fb2ba;
  --dim: #6f858f;
  --cyan: #42d3c8;
  --cyan-bright: #74f1e7;
  --cyan-muted: rgba(66, 211, 200, 0.13);
  --amber: #f5b94c;
  --red: #ff7373;
  --green: #77d69a;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--cyan-bright);
  outline-offset: 2px;
}

.project-app { height: 100vh; display: flex; flex-direction: column; }
.project-topbar {
  height: 68px;
  flex: 0 0 68px;
  display: grid;
  grid-template-columns: 250px minmax(160px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 17, 23, 0.96);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  z-index: 10;
}
.project-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(116, 241, 231, 0.55);
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(66, 211, 200, 0.24), rgba(66, 211, 200, 0.05));
  color: var(--cyan-bright);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.project-brand > span:last-child { display: grid; gap: 4px; }
.project-brand strong { font-size: 17px; }
.project-brand small { color: var(--dim); font-size: 11px; }
.project-context { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.project-context .context-label { color: var(--dim); font-size: 11px; text-transform: uppercase; }
.project-context strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.project-actions { display: flex; align-items: center; gap: 9px; }
.graph-health { display: flex; align-items: center; gap: 7px; color: var(--soft); font-size: 11px; margin-right: 4px; }
.graph-health i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.graph-health i.ok { background: var(--green); box-shadow: 0 0 11px rgba(119, 214, 154, 0.55); }
.graph-health i.error { background: var(--red); }
.text-link { color: var(--soft); font-size: 12px; text-decoration: none; padding: 7px 3px; }
.text-link:hover { color: var(--cyan-bright); }

.button {
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.button:hover:not(:disabled) { border-color: var(--cyan); background: var(--surface-3); }
.button.primary { border-color: rgba(66, 211, 200, 0.7); background: var(--cyan); color: #061114; }
.button.primary:hover:not(:disabled) { background: var(--cyan-bright); }
.button.secondary { background: transparent; }
.button.danger { border-color: rgba(255, 115, 115, 0.45); background: rgba(255, 115, 115, 0.1); color: #ffc0c0; }
.button.wide { width: 100%; margin-top: 18px; }
.button:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--soft);
  font-size: 17px;
  cursor: pointer;
}
.icon-button:hover { color: var(--cyan-bright); border-color: var(--line); background: var(--surface-2); }

.project-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 244px minmax(420px, 1fr) 320px;
  background: var(--surface-0);
}
.project-rail, .drawing-inspector { min-width: 0; min-height: 0; background: #0b171e; }
.project-rail { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.drawing-inspector { border-left: 1px solid var(--line); overflow-y: auto; }
.rail-section { min-height: 0; padding: 14px; }
.rail-section.grow { flex: 1; display: flex; flex-direction: column; }
.rail-section + .rail-section { border-top: 1px solid var(--line); }
.section-title { min-height: 28px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title > div { display: flex; align-items: center; gap: 8px; }
.section-title span { color: var(--soft); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.section-title strong { min-width: 22px; padding: 2px 6px; border-radius: 999px; background: var(--surface-2); color: var(--cyan-bright); font-size: 10px; text-align: center; }
.project-list { flex: 1; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 7px; }
.project-card {
  width: 100%;
  display: grid;
  gap: 7px;
  padding: 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #0d1a22;
  text-align: left;
  cursor: pointer;
}
.project-card:hover { border-color: var(--line-strong); background: var(--surface-1); }
.project-card.active { border-color: rgba(66, 211, 200, 0.55); background: var(--cyan-muted); }
.project-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.project-card span { display: flex; justify-content: space-between; color: var(--dim); font-size: 10px; }
.project-card span em { color: var(--amber); font-style: normal; }
.empty-small { padding: 20px 6px; color: var(--dim); font-size: 12px; text-align: center; }
.filter-list { display: grid; gap: 5px; }
.filter-list button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--soft);
  font-size: 11px;
  cursor: pointer;
}
.filter-list button:hover { background: var(--surface-2); color: var(--text); }
.filter-list button.active { border-color: rgba(66, 211, 200, 0.35); background: var(--cyan-muted); color: var(--cyan-bright); }
.filter-list b { color: var(--dim); font-size: 10px; }
.filter-list button[data-filter="ready3d"].active { border-color: rgba(119, 214, 154, 0.48); background: rgba(119, 214, 154, 0.11); color: #bdf2cf; }
.filter-list button[data-filter="ready3d"] b { color: var(--green); }

.graph-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.graph-toolbar {
  height: 50px;
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 26, 34, 0.94);
}
.graph-search {
  flex: 0 1 420px;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #09131a;
  color: var(--dim);
}
.graph-search:focus-within { border-color: var(--cyan); }
.graph-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 11px; }
.graph-search input::placeholder { color: var(--dim); }
.graph-summary { margin-left: auto; color: var(--dim); font-size: 10px; white-space: nowrap; }
.graph-tools { flex: 0 0 auto; display: flex; }
.graph-tools button {
  flex: 0 0 auto;
  min-width: 34px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-right: 0;
  background: var(--surface-1);
  color: var(--soft);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}
.graph-tools button:first-child { border-radius: 6px 0 0 6px; }
.graph-tools button:last-child { border-right: 1px solid var(--line); border-radius: 0 6px 6px 0; }
.graph-tools button:hover { color: var(--cyan-bright); background: var(--surface-2); }
.graph-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background-color: #071116;
  background-image:
    linear-gradient(rgba(61, 94, 108, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 94, 108, 0.11) 1px, transparent 1px);
  background-size: 24px 24px;
}
#dependencyCanvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#dependencyCanvas.is-panning { cursor: grabbing; }
.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 30px;
  text-align: center;
  background: radial-gradient(circle at center, rgba(66, 211, 200, 0.08), transparent 42%);
}
.graph-empty[hidden] { display: none; }
.graph-empty h1 { margin: 4px 0 0; font-size: 19px; }
.graph-empty p { max-width: 480px; margin: 0 0 6px; color: var(--soft); font-size: 12px; line-height: 1.7; }
.graph-empty-icon { width: 90px; height: 54px; position: relative; }
.graph-empty-icon::before, .graph-empty-icon::after, .graph-empty-icon span {
  content: "";
  position: absolute;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  background: #0e252a;
  box-shadow: 0 0 16px rgba(66, 211, 200, 0.2);
}
.graph-empty-icon::before { width: 18px; height: 18px; left: 2px; top: 18px; }
.graph-empty-icon::after { width: 18px; height: 18px; right: 2px; top: 18px; }
.graph-empty-icon span { width: 16px; height: 16px; left: 37px; top: 2px; }
.graph-empty-icon span:nth-child(2) { top: 36px; }
.graph-empty-icon span:nth-child(3) { width: 56px; height: 1px; left: 17px; top: 26px; border: 0; border-top: 1px solid var(--cyan); border-radius: 0; background: transparent; }
.graph-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 8px 10px;
  border: 1px solid rgba(53, 80, 93, 0.7);
  border-radius: 7px;
  background: rgba(9, 19, 26, 0.87);
  backdrop-filter: blur(10px);
  color: var(--dim);
  font-size: 9px;
  pointer-events: none;
}
.graph-legend span { display: flex; align-items: center; gap: 5px; }
.graph-legend i.node { width: 12px; height: 8px; border: 2px solid var(--cyan); border-radius: 3px; }
.graph-legend i.node.ready3d { border-color: var(--green); background: rgba(119, 214, 154, 0.22); box-shadow: 0 0 8px rgba(119, 214, 154, 0.35); }
.graph-legend i.node.missing { border-color: var(--red); border-style: dashed; }
.graph-legend i.node.review { border-color: var(--amber); }
.graph-legend i.edge { width: 16px; border-top: 1px solid var(--dim); }

.inspector-heading { height: 50px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); }
.inspector-heading span { color: var(--soft); font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.inspector-heading b { padding: 3px 7px; border-radius: 999px; background: var(--surface-2); color: var(--dim); font-size: 9px; }
.inspector-empty { min-height: 320px; display: grid; place-items: center; align-content: center; gap: 10px; padding: 24px; color: var(--dim); text-align: center; }
.inspector-empty[hidden], .node-details[hidden] { display: none; }
.inspector-empty p { max-width: 220px; font-size: 11px; line-height: 1.7; }
.select-node-icon { width: 50px; height: 50px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--surface-1); color: var(--cyan); font-size: 25px; }
.node-details { padding: 18px; }
.node-title-block { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.node-badge { display: inline-flex; padding: 3px 7px; border-radius: 5px; background: var(--cyan-muted); color: var(--cyan-bright); font-size: 9px; }
.node-badge.ready3d { background: rgba(119, 214, 154, 0.14); color: #bdf2cf; }
.node-badge.missing { background: rgba(255, 115, 115, 0.12); color: #ffabab; }
.node-badge.review { background: rgba(245, 185, 76, 0.13); color: #ffd488; }
.node-title-block h2 { margin: 12px 0 7px; overflow-wrap: anywhere; font-size: 18px; line-height: 1.3; }
.node-title-block p { margin: 0; color: var(--soft); font-size: 11px; line-height: 1.6; }
.node-metadata { display: grid; margin: 0; }
.node-metadata div { display: grid; grid-template-columns: 74px 1fr; gap: 8px; padding: 11px 0; border-bottom: 1px solid rgba(36, 57, 68, 0.7); font-size: 10px; }
.node-metadata dt { color: var(--dim); }
.node-metadata dd { margin: 0; overflow-wrap: anywhere; color: var(--soft); text-align: right; }
.relationship-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 15px; }
.relationship-stats div { padding: 13px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-1); text-align: center; }
.relationship-stats strong { display: block; color: var(--cyan-bright); font-size: 19px; }
.relationship-stats span { color: var(--dim); font-size: 9px; }
.missing-hint { margin: 10px 0 0; padding: 10px; border: 1px solid rgba(255, 115, 115, 0.28); border-radius: 7px; background: rgba(255, 115, 115, 0.08); color: #ffb0b0; font-size: 10px; line-height: 1.55; }

.import-drawer {
  min-height: 94px;
  flex: 0 0 94px;
  display: grid;
  grid-template-columns: minmax(230px, 0.8fr) minmax(300px, 1.5fr) auto;
  align-items: center;
  gap: 20px;
  padding: 13px 18px;
  border-top: 1px solid rgba(66, 211, 200, 0.35);
  background: #0d1b23;
  box-shadow: 0 -18px 38px rgba(0, 0, 0, 0.26);
  z-index: 12;
}
.import-drawer[hidden] { display: none; }
.import-summary div { display: flex; align-items: center; gap: 9px; }
.import-summary span { padding: 3px 6px; border-radius: 4px; background: var(--cyan-muted); color: var(--cyan-bright); font-size: 9px; }
.import-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.import-summary p { margin: 8px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); font-size: 10px; }
.progress-labels { display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--soft); font-size: 9px; }
.progress-track { height: 6px; overflow: hidden; border-radius: 999px; background: #071116; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--cyan-bright)); transition: width 180ms ease; }
.import-controls { display: flex; align-items: center; gap: 8px; }

.project-dialog {
  width: min(480px, calc(100vw - 40px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow);
}
.project-dialog::backdrop { background: rgba(0, 0, 0, 0.68); backdrop-filter: blur(4px); }
.project-dialog form { display: grid; }
.project-dialog header { display: flex; justify-content: space-between; padding: 20px 22px 15px; border-bottom: 1px solid var(--line); }
.project-dialog header span { color: var(--cyan); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; }
.project-dialog h2 { margin: 5px 0 0; font-size: 17px; }
.project-dialog header button { width: 28px; height: 28px; border: 0; background: transparent; color: var(--dim); font-size: 20px; cursor: pointer; }
.project-dialog label { display: grid; gap: 8px; padding: 20px 22px 8px; color: var(--soft); font-size: 10px; }
.project-dialog input { height: 40px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 7px; background: #08131a; color: var(--text); }
.project-dialog > form > p { margin: 0; padding: 6px 22px 18px; color: var(--dim); font-size: 10px; }
.project-dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 22px 18px; }

.toast-region { position: fixed; right: 16px; top: 80px; z-index: 100; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: 420px; padding: 11px 13px; border: 1px solid var(--line-strong); border-radius: 8px; background: #14232d; color: var(--text); box-shadow: var(--shadow); font-size: 11px; line-height: 1.5; }
.toast.success { border-color: rgba(119, 214, 154, 0.5); color: #b9f2cc; }
.toast.error { border-color: rgba(255, 115, 115, 0.55); color: #ffc1c1; }

@media (max-width: 1180px) {
  .project-topbar { grid-template-columns: 210px minmax(120px, 1fr) auto; }
  .project-layout { grid-template-columns: 210px minmax(420px, 1fr) 280px; }
  .graph-health { display: none; }
  .graph-summary { display: none; }
  .graph-search { flex-basis: 260px; min-width: 120px; }
}

@media (max-width: 960px) {
  .project-topbar { grid-template-columns: 190px 1fr auto; }
  .project-actions .secondary, .project-actions .text-link { display: none; }
  .project-layout { grid-template-columns: 190px minmax(430px, 1fr); }
  .drawing-inspector { display: none; }
}

@media (max-width: 760px) {
  .project-topbar {
    grid-template-columns: 170px 1fr;
    gap: 8px;
    padding: 0 10px;
  }
  .project-context, .project-rail { display: none; }
  .project-actions { justify-content: flex-end; }
  .project-actions .button.primary { padding-inline: 10px; }
  .project-layout { grid-template-columns: minmax(0, 1fr); }
  .graph-toolbar { gap: 7px; padding-inline: 8px; }
  .graph-search { flex: 1 1 auto; min-width: 0; }
  .graph-tools button:first-child, .graph-tools button:nth-child(3) { display: none; }
  .graph-legend { gap: 8px; max-width: calc(100% - 20px); overflow: hidden; }
  .import-drawer {
    min-height: 132px;
    flex-basis: 132px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px 14px;
    padding: 10px 12px;
  }
  .import-progress-block { grid-column: 1 / -1; grid-row: 2; }
  .import-controls { grid-column: 2; grid-row: 1; }
}
