/* =========================================================================
   Cranial Osteopathy Graph — Stylesheet
   Clean medical illustration style, dark theme
   ========================================================================= */

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0f1a;
  --bg-surface: #111827;
  --bg-elevated: #1e293b;
  --bg-overlay: rgba(10, 15, 26, 0.92);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: #1e293b;
  --border-light: #334155;
  --accent: #2dd4bf;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --header-h: 52px;
  --side-w: 220px;
  --info-h: 280px;
  --transition: 0.2s ease;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------------------
   Loading
   --------------------------------------------------------------------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}
#loading.hidden {
  opacity: 0;
  pointer-events: none;
}
.loading-content {
  text-align: center;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}
.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* Search */
.search-wrapper {
  position: relative;
  width: 280px;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}
#search-input {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
#search-input:focus {
  border-color: var(--accent);
}
#search-input::placeholder {
  color: var(--text-dim);
}

/* Search results dropdown */
.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
}
.search-result-item:hover,
.search-result-item.active {
  background: var(--bg-surface);
}
.search-result-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.search-result-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
}
.search-result-category {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------------------------------------------------------------------------
   Main Layout — split screen
   --------------------------------------------------------------------------- */
#main {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

#three-container {
  flex: 1;
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

#graph-container {
  flex: 1;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------------------
   3D Tooltip
   --------------------------------------------------------------------------- */
.tooltip-3d {
  position: fixed;
  pointer-events: none;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 150;
}
.tooltip-3d.visible {
  opacity: 1;
}

/* ---------------------------------------------------------------------------
   Info Panel (bottom slide-up)
   --------------------------------------------------------------------------- */
.info-panel {
  position: fixed;
  bottom: 0;
  left: 50%;
  right: var(--side-w);
  max-height: 45vh;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  border-left: 1px solid var(--border-light);
  border-top-left-radius: var(--radius-lg);
  padding: 20px 24px 24px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 90;
  overflow-y: auto;
}
.info-panel.visible {
  transform: translateY(0);
}
.info-panel-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.info-panel-close:hover {
  color: var(--text);
}
.info-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.info-panel-name {
  font-size: 18px;
  font-weight: 600;
}
.info-panel-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--bg);
}
.info-panel-latin {
  font-style: italic;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.info-panel-description {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.info-panel-related {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.related-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.related-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.related-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.related-chip {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition), border-color var(--transition);
}
.related-chip:hover {
  background: var(--bg-elevated);
  border-color: var(--text-dim);
}

/* ---------------------------------------------------------------------------
   Side Panel (stories + mechanisms)
   --------------------------------------------------------------------------- */
.side-panel {
  position: fixed;
  top: var(--header-h);
  right: 0;
  width: var(--side-w);
  bottom: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.side-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.story-list,
.mechanism-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Story buttons */
.story-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: border-color var(--transition), background var(--transition);
}
.story-btn:hover {
  border-color: var(--accent);
  background: rgba(45, 212, 191, 0.06);
}
.story-btn.active {
  border-color: var(--accent);
  background: rgba(45, 212, 191, 0.1);
}
.story-btn-title {
  font-size: 13px;
  font-weight: 500;
}
.story-btn-desc {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* Mechanism buttons */
.mechanism-btn {
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: border-color var(--transition), background var(--transition);
}
.mechanism-btn:hover {
  border-color: #34d399;
  background: rgba(52, 211, 153, 0.06);
}
.mechanism-btn.active {
  border-color: #34d399;
  background: rgba(52, 211, 153, 0.1);
}

/* ---------------------------------------------------------------------------
   Entry Modal
   --------------------------------------------------------------------------- */
.entry-modal {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.entry-modal.visible {
  opacity: 1;
  pointer-events: auto;
}
.entry-modal-content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  max-width: 480px;
  width: 90%;
  text-align: center;
}
.entry-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.entry-modal-close:hover { color: var(--text); }
.entry-modal-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.03em;
}
.entry-modal-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
  line-height: 1.5;
}
.entry-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.entry-action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: border-color var(--transition), background var(--transition);
}
.entry-action-btn:hover {
  border-color: var(--accent);
  background: rgba(45, 212, 191, 0.06);
}
.entry-action-btn svg {
  color: var(--accent);
}
.entry-action-btn span {
  font-size: 14px;
  font-weight: 600;
}
.entry-action-btn small {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* ---------------------------------------------------------------------------
   Graph overrides (SVG inside #graph-container)
   --------------------------------------------------------------------------- */
#graph-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------------------------------------------------------------------------
   Scrollbar styling
   --------------------------------------------------------------------------- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ---------------------------------------------------------------------------
   Layer Panel (bottom-left overlay on 3D view)
   --------------------------------------------------------------------------- */
.layer-panel {
  position: fixed;
  bottom: 16px;
  left: 16px;
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  z-index: 85;
  min-width: 160px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.layer-panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: opacity var(--transition);
  opacity: 0.85;
  cursor: pointer;
}

.layer-toggle.active {
  opacity: 1;
  cursor: pointer;
}

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

.layer-name {
  flex: 1;
}

/* Hide the native checkbox, replace with toggle switch */
.layer-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 28px;
  height: 16px;
  background: var(--border-light);
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
  cursor: inherit;
  transition: background var(--transition);
}

.layer-toggle input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}

.layer-toggle input[type="checkbox"]:checked {
  background: var(--accent);
}

.layer-toggle input[type="checkbox"]:checked::after {
  transform: translateX(12px);
  background: var(--bg);
}

/* ---------------------------------------------------------------------------
   Mobile — stacked layout
   --------------------------------------------------------------------------- */
@media (max-width: 768px) {
  :root {
    --header-h: 48px;
    --side-w: 0px;
  }

  #main {
    flex-direction: column;
  }

  #three-container {
    flex: none;
    height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #graph-container {
    flex: 1;
  }

  .header-title {
    font-size: 13px;
  }

  .search-wrapper {
    width: 180px;
  }

  /* Side panel as bottom sheet overlay */
  .side-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    border-left: none;
    border-top: 1px solid var(--border-light);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 85;
  }
  .side-panel.open {
    transform: translateY(0);
  }

  /* Info panel: full width on mobile */
  .info-panel {
    left: 0;
    right: 0;
    max-height: 40vh;
    padding: 16px;
    border-left: none;
    border-top-left-radius: 0;
  }

  .entry-modal-actions {
    flex-direction: column;
  }
}

/* Adjust main for side panel on desktop */
@media (min-width: 769px) {
  #main {
    right: var(--side-w);
  }
}
