
:root {
  --bg-color: #f5f5f5;
  --sidebar-bg: #fff;
  --content-bg: #fff;
  --text-color: #333;
  --text-muted: #6c757d;
  --link-color: #3b6ea5;
  --link-hover: #254b73;
  --border-color: #e0e0e0;
  --code-bg: #f8f8f8;
  --code-border: #e1e4e8;
  --highlight-bg: #fff8dc;
  --include-bg: rgba(0, 0, 0, 0.04);
  --sidebar-width: 280px;
  --header-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1a1a1a;
    --sidebar-bg: #242424;
    --content-bg: #242424;
    --text-color: #e0e0e0;
    --text-muted: #888;
    --link-color: #6ba4d8;
    --link-hover: #8ec2f0;
    --border-color: #404040;
    --code-bg: #2d2d2d;
    --code-border: #404040;
    --highlight-bg: #3d3d00;
    --include-bg: rgba(255, 255, 255, 0.03);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-color);
  background: var(--bg-color);
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
}

.header-brand {
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--text-color);
  text-decoration: none;
}

.header-brand:hover {
  color: var(--link-color);
}

/* Search */
.search-container {
  flex: 1;
  max-width: 400px;
  margin: 0 40px;
}

.search-wrapper {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  font-size: 14px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-color);
  color: var(--text-color);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--link-color);
  box-shadow: 0 0 0 3px rgba(59, 110, 165, 0.15);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-shortcut {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  font-size: 11px;
  font-family: monospace;
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-muted);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 400px;
  overflow-y: auto;
  background: var(--content-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: none;
}

.search-results.active {
  display: block;
}

.search-result {
  display: block;
  padding: 10px 14px;
  color: var(--text-color);
  text-decoration: none;
  border-bottom: 1px solid var(--border-color);
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover,
.search-result:focus {
  background: var(--highlight-bg);
  outline: none;
}

.search-result .entry-name {
  font-weight: 500;
}

.search-result .entry-kind {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-left: 8px;
}

.search-no-result {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
}

.search-busy::after {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--link-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
}

@keyframes spin {
  to { transform: translateY(-50%) rotate(360deg); }
}

/* Layout */
.layout {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
}

.sidebar-nav {
  padding: 0 12px;
}

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-link {
  display: block;
  padding: 6px 12px;
  color: var(--text-color);
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
  transition: background-color 0.15s;
}

.sidebar-link:hover {
  background: var(--bg-color);
}

.sidebar-link.active {
  background: var(--link-color);
  color: #fff;
}

.sidebar-group {
  margin-left: 0;
}

.sidebar-group-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-color);
  border-radius: 4px;
  user-select: none;
}

.sidebar-group-header:hover {
  background: var(--bg-color);
}

.sidebar-toggle {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  transition: transform 0.2s;
}

.sidebar-toggle-spacer {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 12px;
  margin-right: 6px;
  flex-shrink: 0;
}

.sidebar-leaf {
  display: flex;
  align-items: center;
}

/* Package selector */
.package-selector {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 8px;
}

.package-selector select {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--content-bg);
  color: var(--text-color);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.package-selector select:hover {
  border-color: var(--link-color);
}

.package-selector select:focus {
  outline: none;
  border-color: var(--link-color);
  box-shadow: 0 0 0 3px rgba(59, 110, 165, 0.15);
}

.sidebar-group.collapsed .sidebar-toggle {
  transform: rotate(-90deg);
}

.sidebar-group.collapsed .sidebar-children {
  display: none;
}

.sidebar-children {
  margin-left: 12px;
  border-left: 1px solid var(--border-color);
  padding-left: 8px;
}

/* Sidebar entry type indicators */
.sidebar-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-kind-package {
  background: #8b5cf6;
  color: white;
}

.sidebar-kind-module {
  background: #f59e0b;
  color: white;
}

.sidebar-kind-page {
  background: #10b981;
  color: white;
}

.sidebar-group-header .sidebar-kind {
  margin-left: 0;
}

.sidebar-link .sidebar-kind {
  margin-left: 0;
}

.sidebar-link.active .sidebar-kind {
  background: rgba(255, 255, 255, 0.3);
}

/* Main Content */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 40px 60px;
  max-width: calc(100% - var(--sidebar-width));
  background: var(--content-bg);
  min-height: calc(100vh - var(--header-height));
}

/* Breadcrumbs */
.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 12px 0;
  margin-bottom: 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-color);
}

.breadcrumb-item {
  color: var(--link-color);
  text-decoration: none;
}

.breadcrumb-item:hover {
  text-decoration: underline;
}

.breadcrumb-separator {
  color: var(--text-muted);
  margin: 0 4px;
}

.breadcrumb-current {
  color: var(--text-color);
  font-weight: 500;
}

/* Content Styles */
.content {
  max-width: 900px;
}

.content h1 {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border-color);
}

.content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.content h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

.content h4, .content h5, .content h6 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 8px;
}

.content p {
  margin-bottom: 16px;
}

.content a {
  color: var(--link-color);
  text-decoration: none;
}

.content a:hover {
  text-decoration: underline;
}

.content code {
  font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--code-border);
}

.content pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
  margin-bottom: 16px;
}

.content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.content ul, .content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.content li {
  margin-bottom: 4px;
}

.content blockquote {
  border-left: 4px solid var(--link-color);
  margin: 16px 0;
  padding: 8px 16px;
  background: var(--code-bg);
  color: var(--text-muted);
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.content th, .content td {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.content th {
  background: var(--code-bg);
  font-weight: 600;
}

/* odoc-specific styles */
.odoc-spec {
  margin: 16px 0;
  padding: 12px 16px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  border-left: 3px solid var(--link-color);
}

/* Remove individual code styling inside spec blocks - the container provides the background */
.odoc-spec code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

.spec {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.9rem;
}

.spec-doc {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 0.95rem;
}

/* Hide OCaml comment delimiters in documentation */
.comment-delim {
  display: none;
}

/* Remove list numbers from variant/record definitions */
.odoc-spec ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.odoc-spec li {
  margin: 4px 0;
}

/* Inline documentation for variants/fields */
.def-doc {
  display: inline;
  margin-left: 8px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 0.9rem;
}

.def-doc p {
  display: inline;
  margin: 0;
}

/* Include blocks - grouped items from module includes */
.odoc-include {
  margin: 16px 0;
  margin-left: 12px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--text-muted);
  border-radius: 6px;
  background: var(--include-bg);
}

.odoc-include > details {
  margin: 0;
}

.odoc-include > details > summary {
  padding: 8px 0;
  cursor: pointer;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.9rem;
  list-style: none;
}

.odoc-include > details > summary::-webkit-details-marker {
  display: none;
}

.odoc-include > details > summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s;
  font-size: 0.7em;
  color: var(--text-muted);
}

.odoc-include > details[open] > summary::before {
  transform: rotate(90deg);
}

.anchor {
  color: var(--text-muted);
  text-decoration: none;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

h1:hover .anchor, h2:hover .anchor, h3:hover .anchor,
h4:hover .anchor, h5:hover .anchor, h6:hover .anchor,
.spec:hover .anchor {
  opacity: 1;
}

.anchor:hover {
  color: var(--link-color);
}

/* Highlight target element from URL hash */
:target {
  background-color: var(--highlight-bg);
  border-radius: 4px;
}

.hash-highlight {
  background-color: var(--highlight-bg);
  border-radius: 4px;
  animation: highlight-fade 2s ease-out;
}

@keyframes highlight-fade {
  0% { background-color: var(--highlight-bg); }
  100% { background-color: transparent; }
}

/* Table of Contents (in-page) */
.page-toc {
  position: fixed;
  right: 20px;
  top: calc(var(--header-height) + 24px);
  width: 220px;
  max-height: calc(100vh - var(--header-height) - 48px);
  overflow-y: auto;
  font-size: 13px;
  padding: 12px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.page-toc-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.page-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.page-toc li {
  margin: 4px 0;
}

.page-toc a {
  color: var(--text-muted);
  text-decoration: none;
  display: block;
  padding: 2px 0;
  transition: color 0.15s;
}

.page-toc a:hover {
  color: var(--link-color);
}

.page-toc ul ul {
  margin-left: 12px;
}

@media (max-width: 1400px) {
  .page-toc {
    display: none;
  }
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }

  .sidebar.open {
    transform: translateX(0);
    width: 280px;
  }

  .main {
    margin-left: 0;
    max-width: 100%;
    padding: 16px 20px;
  }

  .menu-toggle {
    display: block;
  }
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-color);
}
