:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #657083;
  --line: #d8dde8;
  --accent: #256f8f;
  --accent-2: #8f5f21;
  --warning: #b33a2b;
  --candidate: #7a5ea8;
  --gedcom: #2c7a59;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 340px;
  height: 100vh;
  overflow: hidden;
}
.app-shell.controls-hidden { grid-template-columns: 0 minmax(420px, 1fr) 340px; }
.app-shell.details-hidden { grid-template-columns: 300px minmax(420px, 1fr) 0; }
.app-shell.controls-hidden.details-hidden { grid-template-columns: 0 minmax(420px, 1fr) 0; }

.sidebar, .details-panel {
  background: var(--panel);
  border-color: var(--line);
  overflow: auto;
  padding: 18px;
}
.sidebar { border-right: 1px solid var(--line); }
.details-panel { border-left: 1px solid var(--line); }
.app-shell.controls-hidden .sidebar,
.app-shell.details-hidden .details-panel {
  border: 0;
  overflow: hidden;
  padding: 0;
  visibility: hidden;
}

.brand h1, .details-panel h2 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: 0;
}
.brand p, .details-panel p { color: var(--muted); }

.control-section {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

label { display: block; color: var(--ink); font-weight: 600; }
.search-label { margin-bottom: 6px; }
input[type="search"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
}
.switches label {
  display: flex;
  gap: 9px;
  align-items: center;
  margin: 8px 0;
  color: var(--muted);
  font-weight: 500;
}
input[type="range"] { width: 100%; }
button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  height: 34px;
  padding: 0 12px;
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }

.search-results { margin-top: 8px; display: grid; gap: 4px; }
.search-results button { width: 100%; text-align: left; height: auto; min-height: 32px; }

.legend h2 { font-size: 15px; margin: 0 0 10px; }
.legend div { display: flex; align-items: center; gap: 9px; margin: 8px 0; color: var(--muted); }
.legend-line { width: 42px; height: 0; border-top: 3px solid #555; display: inline-block; }
.legend-line.high { border-color: #1f5c75; }
.legend-line.medium { border-color: #7d93a0; }
.legend-line.low { border-color: #9c8d65; border-top-style: dashed; }
.legend-line.weak { border-color: var(--warning); border-top-style: dotted; opacity: .65; }

.graph-wrap { position: relative; min-width: 0; }
#graph { width: 100%; height: 100%; display: block; background: #fbfcfe; }
.toolbar {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.toolbar button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef7fb;
}
.empty-state {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
}

.edge { stroke-width: 2.4; cursor: pointer; fill: none; }
.edge.parent_child { marker-end: none; }
.edge.confidence-high { stroke: #173f52; stroke-width: 4; opacity: .98; }
.edge.confidence-medium { stroke: #5f7f90; stroke-width: 3; opacity: .9; }
.edge.confidence-low { stroke: #a27626; stroke-width: 2.8; stroke-dasharray: 9 5; opacity: .78; }
.edge.confidence-weak { stroke: var(--warning); stroke-width: 2.5; stroke-dasharray: 2 6; opacity: .48; }
.edge.highlight-weak { stroke: #d01919; stroke-width: 4; filter: drop-shadow(0 0 5px rgba(208, 25, 25, .45)); opacity: .95; }
.edge.selected { stroke: #111827; stroke-width: 5; opacity: 1; }
.edge.spouse { stroke-width: 2.2; stroke-linecap: round; }
.spouse-companion { fill: none; pointer-events: none; stroke-width: 2.2; stroke-linecap: round; opacity: .98; }
.spouse-companion.confidence-high { stroke: #173f52; }
.spouse-companion.confidence-medium { stroke: #5f7f90; }
.spouse-companion.confidence-low { stroke: #a27626; stroke-dasharray: 9 5; opacity: .78; }
.spouse-companion.confidence-weak { stroke: var(--warning); stroke-dasharray: 2 6; opacity: .48; }
.spouse-companion.highlight-weak { stroke: #d01919; stroke-width: 2.8; filter: drop-shadow(0 0 5px rgba(208, 25, 25, .45)); opacity: .95; }
.spouse-companion.selected { stroke: #111827; stroke-width: 2.8; opacity: 1; }

.time-scale {
  pointer-events: none;
}
.time-scale-axis {
  stroke: #6b7280;
  stroke-width: 2;
}
.time-scale-tick line {
  stroke: #6b7280;
  stroke-width: 1.5;
}
.time-scale text {
  fill: #4b5563;
  paint-order: stroke;
  stroke: #fbfcfe;
  stroke-width: 4px;
  font-weight: 700;
}
.time-scale-title {
  font-size: 13px;
  fill: #243447;
}
.time-scale-years {
  font-size: 12px;
}
.time-scale-year {
  font-size: 10px;
  fill: #6b7280;
}

.person-node { cursor: pointer; }
.person-node rect {
  fill: #ffffff;
  stroke: #4d6475;
  stroke-width: 2;
  rx: 7;
  ry: 7;
}
.person-node text {
  fill: var(--ink);
  paint-order: stroke;
  stroke: #fbfcfe;
  stroke-width: 4px;
  pointer-events: none;
}
.person-node .node-name { font-size: 12px; font-weight: 700; }
.person-node .node-life { fill: var(--ink); font-size: 11px; font-weight: 600; }
.person-node .node-place { fill: var(--muted); font-size: 10px; font-weight: 500; }
.person-node .node-confidence-badge { fill: #344154; font-size: 9px; font-weight: 800; stroke-width: 3px; }
.person-node.confidence-high rect { stroke-width: 3; }
.person-node.confidence-medium rect { stroke-width: 2; }
.person-node.confidence-low rect { stroke: #a27626; stroke-dasharray: 8 4; opacity: .82; }
.person-node.confidence-weak rect { stroke: var(--warning); stroke-dasharray: 2 5; opacity: .68; }
.person-node.status-candidate_harvested rect,
.person-node.status-candidate rect { fill: #faf7ff; stroke: var(--candidate); stroke-dasharray: 4 3; }
.person-node.status-accepted_gedcom rect { fill: #ffffff; }
.person-node.status-candidate_harvested.confidence-high rect,
.person-node.status-candidate.confidence-high rect { stroke: var(--candidate); }
.person-node.frontier rect { fill: #fff4cf; stroke-width: 3; }
.person-node.selected rect, .person-node.search-focused rect { stroke: #111827; stroke-width: 4; }
.person-node.collapsed rect { fill: #e9edf3; }
.person-node.missing-person { opacity: .38; }
.person-node.missing-person rect { fill: #f3f5f8; stroke: #b8c0cc; stroke-dasharray: 6 5; stroke-width: 1.5; }
.person-node.missing-person text { display: none; }
.family-node {
  pointer-events: none;
}
.family-node rect {
  fill: #f8fafc;
  stroke: #8b98aa;
  stroke-width: 1.4;
  stroke-dasharray: 5 4;
  rx: 6;
  ry: 6;
  opacity: .88;
}
.family-node text {
  fill: #405064;
  font-size: 10px;
  font-weight: 600;
  paint-order: stroke;
  stroke: #f8fafc;
  stroke-width: 3px;
}
.debug-layer { pointer-events: none; }
.debug-box {
  fill: none;
  stroke: #00a3a3;
  stroke-width: 1;
  stroke-dasharray: 5 4;
}
.debug-anchor {
  stroke: #ffffff;
  stroke-width: 1.5;
}
.debug-anchor.start { fill: #0f766e; }
.debug-anchor.end { fill: #b91c1c; }
.debug-mode .family-node {
  opacity: .9;
  fill: #f59e0b;
}

.details-panel dl {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 8px 12px;
  margin: 14px 0;
}
.details-panel dt { color: var(--muted); font-weight: 700; }
.details-panel dd { margin: 0; min-width: 0; }
.details-panel h3 { margin: 18px 0 8px; font-size: 15px; }
.muted { color: var(--muted); }
.relation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.relation-item {
  border-left: 4px solid #5f7f90;
  background: #f8fafc;
  border-radius: 6px;
  padding: 8px 9px;
  display: grid;
  gap: 3px;
}
.relation-item.confidence-high { border-left-color: #173f52; }
.relation-item.confidence-medium { border-left-color: #5f7f90; }
.relation-item.confidence-low { border-left-color: #a27626; }
.relation-item.confidence-weak { border-left-color: var(--warning); background: #fff7f5; }
.relation-item button {
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-align: left;
  font-weight: 700;
}
.relation-item span, .relation-item small {
  color: var(--muted);
  font-size: 12px;
}
.source-pill {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
  color: var(--accent);
  text-decoration: none;
  background: #f8fafc;
}

@media (max-width: 980px) {
  .app-shell,
  .app-shell.controls-hidden,
  .app-shell.details-hidden,
  .app-shell.controls-hidden.details-hidden {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh auto;
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }
  .app-shell.controls-hidden { grid-template-rows: 0 60vh auto; }
  .app-shell.details-hidden { grid-template-rows: auto 60vh 0; }
  .app-shell.controls-hidden.details-hidden { grid-template-rows: 0 60vh 0; }
  .sidebar, .details-panel { border: 0; border-bottom: 1px solid var(--line); }
  .toolbar { position: sticky; top: 10px; margin: 10px; }
  #graph { height: 60vh; }
}
