/* ============================================================
   Papyrus Script Map — full-page graph layout
   Respects Material theme dark/light mode via [data-md-color-scheme]
   ============================================================ */

/* Prevent page-level scrolling on the graph page */
html, body {
  overflow: hidden !important;
}

/* Hide MkDocs content wrapper padding on graph page */
.md-main__inner {
  margin: 0 !important;
  max-width: none !important;
}
.md-content {
  max-width: none !important;
  padding: 0 !important;
  margin: 0 !important;
}
.md-content__inner {
  margin: 0 !important;
  padding: 0 !important;
}
.md-sidebar {
  display: none !important;
}

/* ---- Root app container ---- */
#papyrus-graph-app {
  display: flex;
  height: calc(100vh - 96px);
  width: 100%;
  overflow: hidden;
  overscroll-behavior: contain;
  position: relative;
  font-family: var(--md-text-font-family, "Roboto", sans-serif);
}

/* ---- Color tokens ---- */
:root {
  --graph-bg: #fafafa;
  --graph-sidebar-bg: #ffffff;
  --graph-border: #e0e0e0;
  --graph-text: #333333;
  --graph-text-muted: #777777;
  --graph-accent: #4051b5;
  --graph-hover: #f0f2ff;
  --graph-selected: #e3e7ff;
  --graph-input-bg: #f5f5f5;
  --graph-input-border: #d0d0d0;
  --graph-loading-bg: rgba(250, 250, 250, 0.92);
  --graph-doc-bg: #ffffff;
  --graph-scrollbar: #c0c0c0;
  --graph-scrollbar-hover: #a0a0a0;
}

[data-md-color-scheme="slate"] {
  --graph-bg: #1e1e1e;
  --graph-sidebar-bg: #252525;
  --graph-border: #3a3a3a;
  --graph-text: #e0e0e0;
  --graph-text-muted: #999999;
  --graph-accent: #7b8dff;
  --graph-hover: #2a2d3e;
  --graph-selected: #333655;
  --graph-input-bg: #2c2c2c;
  --graph-input-border: #444444;
  --graph-loading-bg: rgba(30, 30, 30, 0.92);
  --graph-doc-bg: #252525;
  --graph-scrollbar: #555555;
  --graph-scrollbar-hover: #777777;
}

/* ---- Left sidebar ---- */
#graph-sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--graph-sidebar-bg);
  border-right: 1px solid var(--graph-border);
  display: flex;
  flex-direction: column;
  color: var(--graph-text);
  z-index: 10;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-header {
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--graph-border);
}

#graph-home {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  width: 36px;
  height: 36px;
  border: 1px solid var(--graph-border);
  border-radius: 6px;
  background: var(--graph-sidebar-bg);
  color: var(--graph-text);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

#graph-home:hover {
  background: var(--graph-hover);
  color: var(--graph-accent);
}

.sidebar-header h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

#graph-stats {
  font-size: 12px;
  color: var(--graph-text-muted);
}

.sidebar-search {
  padding: 12px 16px 8px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--graph-input-border);
  border-radius: 6px;
  background: var(--graph-input-bg);
  color: var(--graph-text);
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}

.sidebar-search input:focus {
  border-color: var(--graph-accent);
  box-shadow: 0 0 0 2px rgba(64, 81, 181, 0.15);
}

.sidebar-filters {
  padding: 4px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-filters select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--graph-input-border);
  border-radius: 4px;
  background: var(--graph-input-bg);
  color: var(--graph-text);
  font-size: 12px;
  cursor: pointer;
}

#script-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
}

#script-list::-webkit-scrollbar {
  width: 6px;
}
#script-list::-webkit-scrollbar-thumb {
  background: var(--graph-scrollbar);
  border-radius: 3px;
}
#script-list::-webkit-scrollbar-thumb:hover {
  background: var(--graph-scrollbar-hover);
}

.script-item {
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--graph-text);
  border-bottom: 1px solid transparent;
}

.script-item:hover {
  background: var(--graph-hover);
}

.script-item.selected {
  background: var(--graph-selected);
  font-weight: 600;
}

.script-item .script-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0.8;
}

.badge-engine { background: #e8eaf6; color: #3949ab; }
.badge-dlc01 { background: #e8f5e9; color: #2e7d32; }
.badge-dlc02 { background: #fff3e0; color: #e65100; }
.badge-dlc03 { background: #e3f2fd; color: #1565c0; }
.badge-dlc04 { background: #fce4ec; color: #c62828; }
.badge-dlc05 { background: #f3e5f5; color: #7b1fa2; }
.badge-dlc06 { background: #e0f7fa; color: #00838f; }
.badge-creation { background: #fff8e1; color: #f57f17; }

[data-md-color-scheme="slate"] .badge-engine { background: #283593; color: #c5cae9; }
[data-md-color-scheme="slate"] .badge-dlc01 { background: #1b5e20; color: #c8e6c9; }
[data-md-color-scheme="slate"] .badge-dlc02 { background: #bf360c; color: #ffccbc; }
[data-md-color-scheme="slate"] .badge-dlc03 { background: #0d47a1; color: #bbdefb; }
[data-md-color-scheme="slate"] .badge-dlc04 { background: #b71c1c; color: #ffcdd2; }
[data-md-color-scheme="slate"] .badge-dlc05 { background: #4a148c; color: #e1bee7; }
[data-md-color-scheme="slate"] .badge-dlc06 { background: #006064; color: #b2ebf2; }
[data-md-color-scheme="slate"] .badge-creation { background: #f57f17; color: #fff8e1; }

/* ---- Graph container ---- */
#graph-container {
  flex: 1;
  position: relative;
  background: var(--graph-bg);
  overflow: hidden;
}

#graph-canvas {
  width: 100%;
  height: 100%;
}

/* ---- Graph controls overlay ---- */
#graph-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

#graph-controls button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--graph-border);
  border-radius: 6px;
  background: var(--graph-sidebar-bg);
  color: var(--graph-text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

#graph-controls button:hover {
  background: var(--graph-hover);
}

#graph-controls button.active {
  background: var(--graph-accent);
  color: #fff;
  border-color: var(--graph-accent);
}

/* ---- Legend ---- */
#graph-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: var(--graph-sidebar-bg);
  border: 1px solid var(--graph-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  z-index: 5;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  color: var(--graph-text);
}

#graph-legend .legend-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

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

/* ---- Loading overlay ---- */
#graph-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--graph-loading-bg);
  z-index: 20;
  font-size: 14px;
  color: var(--graph-text-muted);
}

#graph-loading.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--graph-border);
  border-top-color: var(--graph-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Document viewer (right panel) ---- */
#doc-viewer {
  width: 420px;
  min-width: 420px;
  background: var(--graph-doc-bg);
  border-left: 1px solid var(--graph-border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  color: var(--graph-text);
}

#doc-viewer.hidden {
  display: none;
}

.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--graph-border);
  min-height: 20px;
}

.doc-breadcrumb {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.doc-breadcrumb .doc-link {
  color: var(--graph-accent);
  text-decoration: none;
  cursor: pointer;
  border-bottom: none;
}

.doc-breadcrumb .doc-link:hover {
  text-decoration: underline;
}

.doc-breadcrumb .separator {
  color: var(--graph-text-muted);
  font-size: 11px;
}

#doc-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--graph-text-muted);
  padding: 0 4px;
  line-height: 1;
}

#doc-close:hover {
  color: var(--graph-text);
}

#doc-content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.7;
}

#doc-content::-webkit-scrollbar {
  width: 6px;
}
#doc-content::-webkit-scrollbar-thumb {
  background: var(--graph-scrollbar);
  border-radius: 3px;
}

#doc-content h1 {
  font-size: 22px;
  margin: 0 0 12px;
  font-weight: 700;
  border-bottom: 1px solid var(--graph-border);
  padding-bottom: 8px;
}

#doc-content h2 {
  font-size: 16px;
  margin: 20px 0 8px;
  font-weight: 600;
  color: var(--graph-accent);
}

#doc-content p {
  margin: 8px 0;
}

#doc-content ul {
  padding-left: 20px;
}

#doc-content li {
  margin-bottom: 4px;
}

#doc-content code {
  background: var(--graph-input-bg);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 13px;
}

#doc-content a {
  color: var(--graph-accent);
  text-decoration: none;
}

#doc-content a:hover {
  text-decoration: underline;
}

.doc-link {
  color: var(--graph-accent);
  cursor: pointer;
  border-bottom: 1px dotted var(--graph-accent);
  text-decoration: none;
}

.doc-link:hover {
  text-decoration: underline;
}

#doc-content strong {
  font-weight: 600;
}

#doc-content blockquote {
  border-left: 3px solid var(--graph-accent);
  margin: 12px 0;
  padding: 4px 12px;
  color: var(--graph-text-muted);
  background: var(--graph-input-bg);
  border-radius: 0 4px 4px 0;
}

#doc-content em {
  color: var(--graph-text-muted);
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  #graph-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    box-shadow: 4px 0 12px rgba(0,0,0,0.15);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  #graph-sidebar.open {
    transform: translateX(0);
  }
  #sidebar-toggle {
    display: flex !important;
  }
}

@media (max-width: 900px) {
  #doc-viewer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: auto;
    min-width: auto;
    height: 50%;
    border-left: none;
    border-top: 1px solid var(--graph-border);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
  }
}

/* Sidebar toggle button (visible on small screens) */
#sidebar-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 25;
  width: 36px;
  height: 36px;
  border: 1px solid var(--graph-border);
  border-radius: 6px;
  background: var(--graph-sidebar-bg);
  color: var(--graph-text);
  font-size: 20px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* ---- Tooltip ---- */
#graph-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--graph-sidebar-bg);
  border: 1px solid var(--graph-border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--graph-text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 50;
  max-width: 300px;
  white-space: nowrap;
}

#graph-tooltip .tooltip-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

#graph-tooltip .tooltip-meta {
  color: var(--graph-text-muted);
}
