/* ═══════════════════════════════════════════════════════════════
   Family Tree Dashboard — Styles
   ═══════════════════════════════════════════════════════════════ */

/* ── Dark mode (default) — lighter, more breathable ─────── */
:root {
  --bg: #1c1d2e;
  --surface: #272840;
  --surface-hover: #32345a;
  --border: #3e4068;
  --text: #eaeaf2;
  --text-muted: #9898b4;
  --accent: #7585ff;
  --accent-hover: #95a2ff;
  --male: #5a9ee6;
  --female: #e05a98;
  --union: #f5a623;
  --event-birth: #4cd964;
  --event-career: #7585ff;
  --event-education: #f5a623;
  --event-custom: #b066e0;
  --event-marriage: #ff6b8a;
  --radius: 10px;
  --panel-width: 380px;
  --node-text: #fff;
  --node-text-dim: rgba(255,255,255,0.65);
  --node-text-faint: rgba(255,255,255,0.40);
  --node-male-bg: #243050;
  --node-female-bg: #3a2040;
  color-scheme: dark;
}

/* ── Light mode ─────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f2f3f7;
  --surface: #ffffff;
  --surface-hover: #e8e9f0;
  --border: #d4d5e0;
  --text: #1c1d2e;
  --text-muted: #6a6b82;
  --accent: #5060e8;
  --accent-hover: #3d4ed0;
  --male: #3a78c2;
  --female: #c23a78;
  --union: #d48c14;
  --event-birth: #2ea84d;
  --event-career: #5060e8;
  --event-education: #d48c14;
  --event-custom: #9040c0;
  --event-marriage: #e04060;
  --node-text: #1c1d2e;
  --node-text-dim: rgba(28,29,46,0.65);
  --node-text-faint: rgba(28,29,46,0.45);
  --node-male-bg: #dce6f5;
  --node-female-bg: #f5dce8;
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 10;
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

nav {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius);
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--text);
}

/* ── Views ──────────────────────────────────────────────────── */

main {
  height: calc(100vh - 65px);
  position: relative;
}

.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ── Tree View ──────────────────────────────────────────────── */

.tree-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#tree-svg {
  width: 100%;
  height: 100%;
}

/* D3 tree styling */
.node-group { cursor: pointer; }

.node-rect {
  rx: 8;
  ry: 8;
  stroke-width: 2;
  transition: filter 0.15s ease;
}
.node-group:hover .node-rect { filter: brightness(1.2); }
.node-group.selected .node-rect {
  stroke-width: 3;
  filter: brightness(1.3) drop-shadow(0 0 8px rgba(108, 124, 255, 0.4));
}

.node-name {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  fill: var(--node-text);
  pointer-events: none;
}

.node-dates {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  fill: var(--node-text-dim);
  pointer-events: none;
}

.node-place {
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  fill: var(--node-text-faint);
  pointer-events: none;
  font-style: italic;
}

.link {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}

.union-link {
  fill: none;
  stroke: var(--union);
  stroke-width: 2;
  stroke-dasharray: 6,4;
  opacity: 0.6;
}

/* ── Person Panel ───────────────────────────────────────────── */

.panel {
  width: var(--panel-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  position: relative;
  transition: transform 0.2s ease;
}

.panel.hidden { display: none; }

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.close-btn:hover { background: var(--surface-hover); color: var(--text); }

.panel-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.panel-gender {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 16px;
}
.panel-gender.male { background: rgba(74, 144, 217, 0.2); color: var(--male); }
.panel-gender.female { background: rgba(217, 74, 140, 0.2); color: var(--female); }

.panel-section { margin-top: 20px; }
.panel-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.panel-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.panel-row .label { color: var(--text-muted); }

.panel-notes {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
  padding: 10px;
  background: var(--bg);
  border-radius: var(--radius);
  margin-top: 4px;
}

.panel-family-list {
  list-style: none;
  padding: 0;
}
.panel-family-list li {
  padding: 6px 10px;
  margin: 3px 0;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}
.panel-family-list li:hover { background: var(--surface-hover); }

.panel-event {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.panel-event:last-child { border-bottom: none; }
.panel-event-date {
  color: var(--accent);
  font-weight: 500;
  min-width: 60px;
  flex-shrink: 0;
}
.panel-event-desc { color: var(--text-muted); line-height: 1.4; }

/* ── Timeline View ──────────────────────────────────────────── */

.timeline-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 24px;
  overflow-y: auto;
  height: 100%;
  width: 100%;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.timeline-header h2 {
  font-size: 24px;
  font-weight: 700;
}

.timeline-header select, #rel-person-a, #rel-person-b {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}

.timeline-entry {
  display: flex;
  gap: 20px;
  padding: 16px 0;
  border-left: 2px solid var(--border);
  margin-left: 40px;
  padding-left: 24px;
  position: relative;
}

.timeline-entry::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 22px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

.timeline-entry[data-type="birth"]::before { background: var(--event-birth); }
.timeline-entry[data-type="career"]::before { background: var(--event-career); }
.timeline-entry[data-type="education"]::before { background: var(--event-education); }
.timeline-entry[data-type="custom"]::before { background: var(--event-custom); }
.timeline-entry[data-type="marriage"]::before { background: var(--event-marriage); }

.timeline-year {
  position: absolute;
  left: -80px;
  top: 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  width: 50px;
  text-align: right;
}

.timeline-content h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.timeline-content p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.timeline-place {
  font-size: 12px;
  color: var(--accent);
  opacity: 0.7;
  margin-top: 4px;
  display: flex;
  align-items: center;
}

/* ── Relationships View ─────────────────────────────────────── */

.relationships-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 60px 24px;
  text-align: center;
  width: 100%;
}

.relationships-container h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

.rel-selectors {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
  margin-bottom: 32px;
}

.rel-selectors select {
  min-width: 200px;
}

.rel-arrow {
  font-size: 24px;
  color: var(--text-muted);
}

.rel-result {
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.rel-result.hidden { display: none; }

.rel-label {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  text-transform: capitalize;
}

.rel-desc {
  font-size: 15px;
  color: var(--text-muted);
}

/* ── Map View ───────────────────────────────────────────────── */

.map-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

#map {
  flex: 1;
  z-index: 1;
}

.map-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 16px;
  z-index: 2;
  flex-shrink: 0;
}

.map-filter select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  min-width: 160px;
}

.map-slider {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 500px;
}

.map-play-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.map-play-btn:hover { border-color: var(--accent); color: var(--accent); }
.map-play-btn.playing { background: var(--accent); color: white; border-color: var(--accent); }

.slider-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}

#map-time-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
#map-time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
}
#map-time-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
}

.map-legend {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4) !important;
}
.leaflet-popup-tip { background: var(--surface) !important; }
.leaflet-popup-content { font-family: 'Inter', sans-serif !important; font-size: 13px !important; }
.leaflet-popup-content h4 { font-size: 14px; font-weight: 600; margin: 0 0 8px 0; }
.leaflet-popup-content .popup-event {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.5;
}
.leaflet-popup-content .popup-event:last-child { border-bottom: none; }
.leaflet-popup-content .popup-year { color: var(--accent); font-weight: 500; }
.leaflet-popup-content .popup-person { color: var(--text); }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

/* ── Theme Toggle ──────────────────────────────────────────── */

.theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 16px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Migration arc flow animation ──────────────────────────── */

.arc-flowing {
  animation: dash-flow 1.2s linear infinite;
}

@keyframes dash-flow {
  to { stroke-dashoffset: -20; }
}

/* ── Leaflet light mode ────────────────────────────────────── */

[data-theme="light"] .leaflet-popup-content-wrapper {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12) !important;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  header { flex-direction: column; gap: 12px; }
  .panel { width: 100%; position: absolute; right: 0; top: 0; height: 100%; z-index: 5; }
  .rel-selectors { flex-direction: column; }
  .map-controls { flex-direction: column; gap: 10px; padding: 10px 16px; }
  .map-slider { max-width: 100%; width: 100%; }
  .map-legend { flex-wrap: wrap; justify-content: center; }
}
