/* docs tab - markdown viewer/editor with table of contents */

/* docs tab layout - fill viewport below header+tabs */
#tab-docs {
  flex-direction: column;
  height: calc(100vh - 108px);
  overflow: hidden;
  padding-bottom: 0;
}

#tab-docs.active {
  display: flex;
}

/* toolbar */
.docs-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  flex-wrap: wrap;
  flex-shrink: 0;
  z-index: 10;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.03) 100%
  );
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 16px;
}

[data-theme="light"] .docs-toolbar {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.85) 0%,
    rgba(255, 255, 255, 0.7) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.docs-toolbar .select {
  width: auto;
  min-width: 160px;
}

.docs-toolbar-spacer {
  flex: 1;
}

.docs-mode-toggle {
  display: flex;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
}

.docs-mode-toggle button {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.docs-mode-toggle button:not(:last-child) {
  border-right: 1px solid var(--border);
}

.docs-mode-toggle button.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.docs-mode-toggle button:hover:not(.active) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.docs-mode-toggle button svg {
  width: 14px;
  height: 14px;
}

.docs-save-btn {
  opacity: 0.5;
  pointer-events: none;
  transition: all var(--transition-fast);
}

.docs-save-btn.has-changes {
  opacity: 1;
  pointer-events: auto;
}

/* layout container */
.docs-layout {
  display: flex;
  gap: 20px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* table of contents sidebar */
.docs-toc {
  width: 220px;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

[data-theme="light"] .docs-toc {
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.docs-toc::-webkit-scrollbar {
  width: 4px;
}

.docs-toc::-webkit-scrollbar-track {
  background: transparent;
}

.docs-toc::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
}

[data-theme="light"] .docs-toc::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
}

.docs-toc h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.docs-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.docs-toc-list li {
  margin-bottom: 2px;
}

.docs-toc-list a {
  display: block;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.docs-toc-list a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.docs-toc-list a.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.docs-toc-list .toc-h2 {
  padding-left: 16px;
}

.docs-toc-list .toc-h3 {
  padding-left: 28px;
  font-size: 11px;
}

/* content area */
.docs-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

[data-theme="light"] .docs-content {
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.docs-content::-webkit-scrollbar {
  width: 6px;
}

.docs-content::-webkit-scrollbar-track {
  background: transparent;
}

.docs-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

[data-theme="light"] .docs-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
}

/* rendered markdown view */
.docs-rendered {
  padding: 24px 28px;
  line-height: 1.7;
}

.docs-rendered h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 32px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.docs-rendered h1:first-child {
  margin-top: 0;
}

.docs-rendered h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 28px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.docs-rendered h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 24px 0 10px;
  color: var(--text-primary);
}

.docs-rendered h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text-primary);
}

.docs-rendered p {
  margin: 0 0 16px;
  color: var(--text-secondary);
}

.docs-rendered a {
  color: var(--accent);
  text-decoration: none;
}

.docs-rendered a:hover {
  text-decoration: underline;
}

.docs-rendered strong {
  color: var(--text-primary);
  font-weight: 600;
}

.docs-rendered ul,
.docs-rendered ol {
  margin: 0 0 16px;
  padding-left: 24px;
  color: var(--text-secondary);
}

.docs-rendered li {
  margin-bottom: 4px;
}

.docs-rendered blockquote {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.docs-rendered blockquote p:last-child {
  margin-bottom: 0;
}

.docs-rendered hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* inline code */
.docs-rendered code {
  padding: 2px 6px;
  font-size: 13px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--accent);
}

/* code blocks */
.docs-rendered pre {
  margin: 0 0 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.docs-rendered pre code {
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

/* tables */
.docs-rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 13px;
}

.docs-rendered th,
.docs-rendered td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.docs-rendered th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-primary);
}

.docs-rendered td {
  color: var(--text-secondary);
}

/* task list checkboxes */
.docs-rendered .task-list-item {
  list-style: none;
  margin-left: -24px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.docs-rendered .task-list-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  min-width: 16px;
  border: 2px solid var(--border-hover);
  border-radius: 4px;
  margin-top: 3px;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.docs-rendered .task-list-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.docs-rendered .task-list-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.docs-rendered .task-list-item input[type="checkbox"]:hover {
  border-color: var(--accent);
}

/* images */
.docs-rendered img {
  max-width: 100%;
  border-radius: var(--radius-md);
}

/* editor */
.docs-editor {
  width: 100%;
  height: 100%;
  padding: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  line-height: 1.6;
  resize: none;
  outline: none;
  tab-size: 2;
}

.docs-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

[data-theme="light"] .docs-editor {
  background: rgba(0, 0, 0, 0.03);
}

/* split pane */
.docs-split {
  display: flex;
  gap: 16px;
  height: 100%;
}

.docs-split .docs-editor {
  flex: 1;
  height: 100%;
}

.docs-split .docs-preview {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

[data-theme="light"] .docs-split .docs-preview {
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.docs-split .docs-preview::-webkit-scrollbar {
  width: 4px;
}

.docs-split .docs-preview::-webkit-scrollbar-track {
  background: transparent;
}

.docs-split .docs-preview::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
}

[data-theme="light"] .docs-split .docs-preview::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
}

/* empty state */
.docs-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--text-muted);
  text-align: center;
}

.docs-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.docs-empty p {
  font-size: 14px;
  max-width: 320px;
}

/* loading spinner */
.docs-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
}

.docs-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* responsive */
@media (max-width: 900px) {
  .docs-toc {
    display: none;
  }

  .docs-split {
    flex-direction: column;
  }

  .docs-split .docs-editor,
  .docs-split .docs-preview {
    height: 45vh;
  }
}

@media (max-width: 600px) {
  .docs-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .docs-toolbar .select {
    width: 100%;
  }

  .docs-toolbar-spacer {
    display: none;
  }

  .docs-rendered {
    padding: 16px;
  }
}

/* light theme overrides */
[data-theme="light"] .docs-toc-list a:hover {
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .docs-toc-list a.active {
  background: rgba(16, 185, 129, 0.1);
  color: var(--accent);
}

[data-theme="light"] .docs-rendered code {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .docs-rendered pre {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .docs-rendered blockquote {
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .docs-rendered th {
  background: rgba(0, 0, 0, 0.03);
}
