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

/* ── Theme tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #21262d;
  --border:    #30363d;
  --border2:   #21262d;
  --text:      #c9d1d9;
  --text2:     #8b949e;
  --text3:     #6e7681;
  --text-h:    #e6edf3;
  --link:      #58a6ff;
  --accent:    #1f6feb;
  --accent-h:  #388bfd;
  --graph-bg:  #0d1117;
}

:root.light {
  --bg:        #ffffff;
  --bg2:       #f6f8fa;
  --bg3:       #eaeef2;
  --border:    #d0d7de;
  --border2:   #eaeef2;
  --text:      #24292f;
  --text2:     #57606a;
  --text3:     #6e7781;
  --text-h:    #1f2328;
  --link:      #0969da;
  --accent:    #0969da;
  --accent-h:  #0550ae;
  --graph-bg:  #f6f8fa;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  overflow: hidden;
}

#graph-container { width: 100vw; height: 100vh; width: 100dvw; height: 100dvh; }

/* Toolbar */
#toolbar {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 8px;
  z-index: 100;
}
.toolbar-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
}
.toolbar-btn:hover { background: var(--bg3); }
.toolbar-btn.active { background: var(--accent); border-color: var(--accent-h); color: #fff; }

.toolbar-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 2px 4px;
}

/* Time-arrow toggle — distinct from color-mode buttons */
.toolbar-toggle {
  border-style: dashed;
}
.toolbar-toggle.active {
  background: #0d3360;
  border-color: #3b82f6;
  border-style: solid;
  color: #93c5fd;
}
:root.light .toolbar-toggle.active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

/* Theme toggle button (bottom-right) */
#theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  line-height: 1;
}
#theme-toggle:hover {
  background: var(--bg3);
  box-shadow: 0 3px 12px rgba(0,0,0,0.45);
}

/* Search bar */
#search-bar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
}
#search-wrapper {
  position: relative;
}
#search-input {
  width: 220px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, width 0.2s;
}
#search-input::placeholder { color: var(--text3); }
#search-input:focus {
  border-color: var(--accent-h);
  width: 280px;
}
#search-results {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 280px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  list-style: none;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#search-results.hidden { display: none; }
#search-results li {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
#search-results li:not(:last-child) { border-bottom: 1px solid var(--border2); }
#search-results li:hover { background: var(--bg3); }

/* Admin badge */
#admin-badge {
  position: fixed;
  top: 56px;
  right: 16px;
  background: #1a3a2a;
  border: 1px solid #2ea043;
  color: #3fb950;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  display: none;
  z-index: 100;
}
:root.light #admin-badge {
  background: #dafbe1;
  border-color: #2da44e;
  color: #1a7f37;
}

/* Side panel */
#side-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 360px;
  height: 100vh;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  transition: right 0.25s ease;
  z-index: 200;
  display: flex;
  flex-direction: column;
}
#side-panel.open { right: 0; }

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border2);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.panel-header h2 { font-size: 15px; font-weight: 600; color: var(--text-h); line-height: 1.3; }
.panel-close {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}
.panel-close:hover { color: var(--text); }

.panel-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border2);
}
.panel-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  margin-bottom: 6px;
}
.role-badge {
  display: inline-block;
  background: #2d1b00;
  border: 1px solid #9e6a03;
  color: #e3b341;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  margin: 2px 2px 2px 0;
}
:root.light .role-badge {
  background: #fff8c5;
  border-color: #d4a72c;
  color: #7d4e00;
}
.connection-link {
  display: block;
  color: var(--link);
  text-decoration: none;
  font-size: 13px;
  padding: 3px 0;
  cursor: pointer;
}
.connection-link:hover { text-decoration: underline; }
.annotation-item {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.annotation-item a { color: var(--link); }
.annotation-img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 4px;
  margin-top: 6px;
  border: 1px solid var(--border);
}
.annotation-img-caption {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

/* Edit mode inputs */
.edit-field { margin-bottom: 10px; }
.edit-field label { display: block; font-size: 11px; color: var(--text2); margin-bottom: 3px; }
.edit-field input, .edit-field textarea, .edit-field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 13px;
}
.edit-field input:focus, .edit-field textarea:focus {
  outline: none;
  border-color: var(--accent-h);
}
.btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #da3633; color: #fff; }
.btn-danger:hover { background: #f85149; }

/* Admin page */
.admin-body { overflow: auto; background: var(--bg); min-height: 100vh; }
.admin-nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 0;
  height: 48px;
}
.admin-nav a {
  color: var(--text2);
  text-decoration: none;
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 2px solid transparent;
}
.admin-nav a.active, .admin-nav a:hover { color: var(--text); }
.admin-nav a.active { border-bottom-color: var(--accent-h); }
.admin-nav .brand { color: var(--text-h); font-weight: 600; margin-right: 16px; font-size: 15px; }
.admin-content { max-width: 900px; margin: 0 auto; padding: 24px 20px; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { text-align: left; padding: 8px 12px; color: var(--text2); font-size: 12px;
  border-bottom: 1px solid var(--border2); }
.admin-table td { padding: 8px 12px; border-bottom: 1px solid var(--border2); font-size: 13px; }
.admin-table tr:hover td { background: var(--bg2); }
.search-box {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.page-title { font-size: 20px; font-weight: 600; color: var(--text-h); margin-bottom: 20px; }

/* ForceGraph3D tooltip */
:root.light .scene-tooltip {
  color: #1f2328 !important;
  background: rgba(246,248,250,0.92) !important;
  text-shadow: none !important;
}

/* Info modal */
#info-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#info-modal-overlay.hidden { display: none; }
#info-modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.info-modal-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border2);
}
.info-modal-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-h);
  margin-bottom: 4px;
}
.info-modal-header p {
  font-size: 13px;
  color: var(--text2);
}
.info-modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  flex: 1;
}
.info-section h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  margin-bottom: 8px;
}
.info-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.info-section ul li {
  font-size: 13px;
  color: var(--text);
  padding-left: 14px;
  position: relative;
}
.info-section ul li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: var(--accent-h);
}
.info-section p {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.info-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.info-dont-show {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  user-select: none;
}
.info-dont-show input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }

/* Info help button (bottom-left) */
#info-help-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 300;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
#info-help-btn:hover {
  background: var(--bg3);
  color: var(--text);
  box-shadow: 0 3px 12px rgba(0,0,0,0.45);
}

/* Burger menu — portrait phone only */
#burger-btn {
  display: none;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  z-index: 101;
}
#toolbar-menu {
  display: contents; /* default: inline with the toolbar */
}

@media (max-width: 600px) and (orientation: portrait) {
  #burger-btn { display: block; }
  #toolbar-menu {
    display: none;
    position: fixed;
    top: 52px;
    left: 16px;
    flex-direction: column;
    gap: 6px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    z-index: 200;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  }
  #toolbar-menu.open { display: flex; }
  #toolbar-menu .toolbar-divider { display: none; }
}

/* Timeline bars in side panel */
.timeline-wrap { padding: 12px 16px; border-bottom: 1px solid var(--border2); }
.timeline-axis { position: relative; height: 20px; margin-bottom: 4px; }
.timeline-axis-label { font-size: 10px; color: var(--text3); position: absolute; }
.timeline-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; min-height: 20px; }
.timeline-bar-name { font-size: 11px; color: var(--text2); width: 110px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-bar-track { flex: 1; position: relative; height: 12px; background: var(--bg); border-radius: 2px; }
.timeline-bar-fill { position: absolute; height: 100%; border-radius: 2px; background: var(--accent); }
.timeline-bar-fill.estimated { background: repeating-linear-gradient(90deg, var(--accent) 0, var(--accent) 4px, transparent 4px, transparent 8px); border: 1px dashed var(--accent-h); }
.timeline-bar-fill.focal { background: #facc15; }
.timeline-estimated-label { font-size: 10px; color: #6366f1; margin-left: 4px; }
