:root {
  --navy: #172554;
  --blue: #1d4ed8;
  --blue-soft: #eff6ff;
  --orange: #f59e0b;
  --purple: #7c3aed;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe3ec;
  --paper: #ffffff;
  --background: #f8fafc;
  --high: #ef4444;
  --rise: #f59e0b;
  --mid: #22a06b;
  --low: #2563eb;
  --cold: #bfdbfe;
  --missing: #f1f5f9;
}

* { box-sizing: border-box; }

.content {
  width: calc(100% - 20px);
  max-width: none;
  padding-top: 12px;
}

.demand-map-app {
  min-height: 100vh;
  padding: 12px;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(59,130,246,.08), transparent 24%),
    radial-gradient(circle at 92% 4%, rgba(245,158,11,.06), transparent 20%),
    var(--background);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: none;
  margin: 0 auto 18px;
}

.page-header h1 {
  margin: 0 0 6px;
  color: #111b3f;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(30px, 3.4vw, 50px);
  font-weight: 570;
  letter-spacing: -.04em;
}

.page-header p { margin: 0; color: var(--muted); font-size: 14px; }

.source-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.source-stats span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.8);
  color: #526174;
  font-size: 10px;
}

.principle-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: none;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: #fff;
}

.principle-strip div { padding: 11px 15px; border-right: 1px solid var(--line); }
.principle-strip div:last-child { border: 0; }
.principle-strip strong { display: block; color: #1e3a8a; font-size: 11px; }
.principle-strip small { display: block; margin-top: 3px; color: var(--muted); font-size: 8px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(680px, 1fr) minmax(360px, 480px);
  max-width: none;
  height: min(76vh, 900px);
  min-height: 700px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0 0 16px 16px;
  background: #fff;
  box-shadow: 0 20px 55px rgba(15,23,42,.07);
}

.map-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border-right: 1px solid var(--line);
}

.map-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(330px, 1fr) 220px auto;
  align-items: center;
  gap: 14px;
  padding: 15px 16px 11px;
  border-bottom: 1px solid #e8edf2;
}

.map-toolbar h2, .demand-panel-head h2 { margin: 0 0 3px; font-size: 15px; }
.map-toolbar p, .demand-panel-head p { margin: 0; color: var(--muted); font-size: 9px; }

.heat-legend { display: flex; flex-wrap: wrap; gap: 7px; color: #526174; font-size: 8px; }
.heat-legend span { display: inline-flex; align-items: center; gap: 3px; }
.heat-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; }
.heat-high { background: var(--high); }
.heat-rise { background: var(--rise); }
.heat-mid { background: var(--mid); }
.heat-low { background: var(--low); }
.heat-cold { background: var(--cold); border: 1px solid #bfdbfe; }
.heat-missing { background: var(--missing); border: 1px solid #d8e0e8; }

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #94a3b8;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font-size: 10px;
}

.global-button {
  height: 31px;
  padding: 0 10px;
  border: 1px solid #93c5fd;
  border-radius: 7px;
  background: var(--blue-soft);
  color: #1d4ed8;
  font-size: 9px;
  cursor: pointer;
}
.global-button:disabled { cursor: not-allowed; opacity: .42; }
.view-actions { display: flex; gap: 5px; }

.depth-axis {
  display: grid;
  min-height: 24px;
  padding: 6px 12px 4px;
  color: #94a3b8;
  background: #fbfdff;
  border-bottom: 1px solid #edf1f5;
  font-size: 7px;
  text-align: center;
}
.depth-axis button {
  min-width: 0;
  padding: 2px 3px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #94a3b8;
  font: inherit;
  cursor: pointer;
}
.depth-axis button:hover { background: #eff6ff; color: #1d4ed8; }
.depth-axis button.active { background: #dbeafe; color: #1d4ed8; font-weight: 750; }

.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  overflow-x: auto;
  padding: 5px 12px;
  border-bottom: 1px solid #edf1f5;
  background: #fff;
}
.breadcrumb-bar button {
  flex: 0 0 auto;
  padding: 4px 6px;
  border: 0;
  border-radius: 5px;
  background: #f1f5f9;
  color: #526174;
  font-size: 8px;
  cursor: pointer;
}
.breadcrumb-bar button.current { background: #ede9fe; color: #6d28d9; font-weight: 750; }
.breadcrumb-bar i { color: #94a3b8; font-size: 8px; font-style: normal; }

.icicle-viewport {
  position: relative;
  min-height: 0;
  margin: 12px;
  overflow: auto;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  scrollbar-gutter: stable;
}

.icicle-wrap {
  position: relative;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background: #f8fafc;
}

#icicle-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.icicle-wrap.dragging #icicle-canvas { cursor: grabbing; }
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }

.map-tooltip {
  position: absolute;
  z-index: 8;
  display: none;
  width: 235px;
  padding: 9px 10px;
  border: 1px solid #c4b5fd;
  border-radius: 8px;
  background: rgba(255,255,255,.97);
  color: #334155;
  box-shadow: 0 9px 24px rgba(15,23,42,.14);
  font-size: 8px;
  line-height: 1.55;
  pointer-events: none;
}

.map-tooltip strong { display: block; color: #5b21b6; font-size: 10px; }
.map-tooltip span { display: block; color: #64748b; }

.map-guide {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 5;
  width: 190px;
  padding: 9px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: rgba(255,255,255,.94);
  color: #526174;
  box-shadow: 0 7px 18px rgba(15,23,42,.07);
  pointer-events: none;
}

.map-guide strong { display: block; margin-bottom: 3px; color: #1d4ed8; font-size: 9px; }
.map-guide span { display: block; font-size: 7px; line-height: 1.5; }

.zoom-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 6;
  display: flex;
  gap: 4px;
}
.zoom-controls button {
  min-width: 31px;
  height: 29px;
  padding: 0 7px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  background: rgba(255,255,255,.95);
  color: #1d4ed8;
  font-size: 9px;
  cursor: pointer;
}

.map-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 0 12px 12px;
}

.map-summary div {
  padding: 8px 9px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 8px;
  line-height: 1.5;
}

.demand-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: #fbfdff;
}

.demand-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 15px 11px;
  border-bottom: 1px solid #e8edf2;
}

.demand-panel-head > strong {
  color: #1d4ed8;
  font-family: Georgia, serif;
  font-size: 22px;
  font-weight: 560;
}

.demand-filters { display: flex; gap: 5px; overflow-x: auto; padding: 10px 14px 7px; }
.demand-filters button {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 8px;
  cursor: pointer;
}
.demand-filters button.active { border-color: var(--blue); background: var(--blue); color: #fff; }

.demand-attachments {
  display: none;
  max-height: 210px;
  overflow: auto;
  margin: 2px 13px 8px;
  padding: 9px;
  border: 1px solid #c4b5fd;
  border-radius: 9px;
  background: #faf8ff;
}
.demand-attachments.visible { display: block; }
.demand-attachments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}
.demand-attachments-head strong { color: #5b21b6; font-size: 9px; }
.demand-attachments-head span { color: #7c3aed; font-size: 7px; }
.attachment-button {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 5px;
  padding: 7px;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  background: #fff;
  color: #475569;
  text-align: left;
  cursor: pointer;
}
.attachment-button:hover, .attachment-button.active { border-color: #8b5cf6; background: #f5f3ff; }
.attachment-button b {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ede9fe;
  color: #6d28d9;
  font-size: 7px;
}
.attachment-button span { min-width: 0; font-size: 7px; line-height: 1.5; }
.attachment-button em { color: #7c3aed; font-size: 7px; font-style: normal; white-space: nowrap; }

.demand-list { overflow: auto; padding: 3px 13px 16px; }
.demand-card {
  margin-bottom: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--orange);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.demand-card:hover, .demand-card.selected { border-color: #93c5fd; box-shadow: 0 7px 18px rgba(15,23,42,.06); }
.demand-card.selected { border-left-color: var(--purple); }
.demand-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.demand-card h3 { margin: 0; font-size: 11px; line-height: 1.4; }
.granularity {
  flex: 0 0 auto;
  padding: 3px 5px;
  border-radius: 4px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 7px;
  font-weight: 750;
}

.score-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.score-row span { padding: 3px 5px; border-radius: 4px; background: #eff6ff; color: #1e40af; font-size: 7px; }
.score-row .path-count { background: #f3e8ff; color: #6b21a8; }
.score-row .missing-data { background: #f1f5f9; color: #64748b; }
.card-reason { margin: 7px 0 0; color: #64748b; font-size: 8px; line-height: 1.55; }
.card-reason strong { color: #334155; }

.empty-state, .explanation-empty { padding: 30px 18px; color: var(--muted); font-size: 11px; line-height: 1.7; }

.explanation-panel {
  display: grid;
  grid-template-columns: minmax(230px, .72fr) minmax(360px, 1fr) minmax(360px, 1fr);
  gap: 12px;
  max-width: none;
  margin: 14px auto 0;
}

.explanation-panel > article {
  min-width: 0;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.explanation-panel > article.fact-card { border-top: 3px solid var(--orange); }
.explanation-panel > article.model-card { border-top: 3px solid var(--purple); }
.explanation-panel > article.path-context-card {
  grid-column: 1 / -1;
  border-top: 3px solid #2563eb;
}
.explanation-panel h2 { margin: 0 0 4px; font-size: 14px; }
.explanation-panel h3 { margin: 0 0 8px; color: var(--muted); font-size: 9px; font-weight: 500; }
.explanation-panel p { margin: 0; color: #526174; font-size: 9px; line-height: 1.7; }
.explanation-panel .demand-title { color: #1e3a8a; font-size: 20px; font-family: Georgia, "Noto Serif SC", serif; }

.attachment-list { display: grid; gap: 5px; margin-top: 9px; }
.attachment-list span { padding: 6px 7px; border-radius: 6px; background: #f8fafc; color: #526174; font-size: 8px; line-height: 1.45; }
.raw-reason { margin-top: 8px !important; padding-top: 8px; border-top: 1px dashed var(--line); color: #7c3aed !important; }

.path-node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.path-node-grid button {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
  padding: 9px;
  border: 1px solid #dbeafe;
  border-radius: 9px;
  background: #f8fbff;
  color: #334155;
  text-align: left;
  cursor: pointer;
}
.path-node-grid button:hover,
.path-node-grid button.active {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 6px 16px rgba(37,99,235,.08);
}
.path-node-grid b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 8px;
}
.path-node-grid span { min-width: 0; }
.path-node-grid strong,
.path-node-grid small,
.path-node-grid em { display: block; }
.path-node-grid strong { overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.path-node-grid small { margin-top: 3px; color: #64748b; font-size: 7px; line-height: 1.5; }
.path-node-grid em {
  grid-column: 2;
  color: #2563eb;
  font-size: 7px;
  font-style: normal;
}

@media (max-width: 1200px) {
  .workspace { grid-template-columns: minmax(600px, 1fr) minmax(340px, 410px); }
  .map-toolbar { grid-template-columns: 1fr auto; }
  .heat-legend { grid-column: 1 / -1; grid-row: 2; }
  .search-box { grid-column: 1; grid-row: 3; }
  .global-button { grid-column: 2; grid-row: 3; }
  .view-actions { grid-column: 2; grid-row: 3; }
}

@media (max-width: 900px) {
  .demand-map-app { padding: 16px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .source-stats { justify-content: flex-start; }
  .principle-strip { grid-template-columns: 1fr 1fr; }
  .workspace { display: block; height: auto; }
  .map-panel { height: 730px; border-right: 0; border-bottom: 1px solid var(--line); }
  .demand-panel { height: 700px; }
  .explanation-panel { grid-template-columns: 1fr; }
  .map-guide { display: none; }
  .zoom-controls { right: 7px; bottom: 7px; }
}
