/* ── CSS Custom Properties ──────────────────────────────────── */

:root,
[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --sidebar-bg: #f8f9fa;
  --sidebar-hover: #e9ecef;
  --border: #dee2e6;
  --link: #0066cc;
  --link-hover: #004499;
  --code-bg: #f1f3f5;
  --code-border: #dee2e6;
  --card-bg: #ffffff;
  --card-shadow: rgba(0, 0, 0, 0.08);
  --badge-done: #28a745;
  --badge-in-progress: #007bff;
  --badge-backlog: #6c757d;
  --badge-blocked: #dc3545;
  --badge-testing: #6f42c1;
  --badge-high: #dc3545;
  --badge-medium: #fd7e14;
  --badge-low: #28a745;
  --method-get: #28a745;
  --method-post: #007bff;
  --method-put: #fd7e14;
  --method-delete: #dc3545;
  --method-patch: #6f42c1;
  --callout-bg: #fff8e1;
  --callout-border: #ff9800;
  --accent: #0066cc;
  --accent-light: #e7f1ff;
  --input-bg: #ffffff;
  --input-border: #ced4da;
  --error-bg: #f8d7da;
  --error-text: #721c24;
  --scrollbar-thumb: #ced4da;
  --scrollbar-track: transparent;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --text: #e0e0e0;
  --text-muted: #9e9e9e;
  --sidebar-bg: #16213e;
  --sidebar-hover: #1a2744;
  --border: #2d3748;
  --link: #64b5f6;
  --link-hover: #90caf9;
  --code-bg: #2d2d44;
  --code-border: #3d3d5c;
  --card-bg: #16213e;
  --card-shadow: rgba(0, 0, 0, 0.3);
  --badge-done: #4caf50;
  --badge-in-progress: #42a5f5;
  --badge-backlog: #78909c;
  --badge-blocked: #ef5350;
  --badge-testing: #ab47bc;
  --badge-high: #ef5350;
  --badge-medium: #ff9800;
  --badge-low: #66bb6a;
  --method-get: #66bb6a;
  --method-post: #42a5f5;
  --method-put: #ffa726;
  --method-delete: #ef5350;
  --method-patch: #ab47bc;
  --callout-bg: #332b00;
  --callout-border: #ff9800;
  --accent: #64b5f6;
  --accent-light: #1a2744;
  --input-bg: #2d2d44;
  --input-border: #3d3d5c;
  --error-bg: #5c1a1a;
  --error-text: #f8d7da;
  --scrollbar-thumb: #3d3d5c;
  --scrollbar-track: transparent;
}

/* ── Reset & Base ──────────────────────────────────────────── */

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

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

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
  width: 270px;
  min-width: 270px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}
.sidebar::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text) !important;
  text-decoration: none !important;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 1rem;
  color: var(--text);
}

[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

.sidebar-search {
  padding: 0.8rem 1rem;
  position: relative;
}

.sidebar-search input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.sidebar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 1rem;
  right: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--card-shadow);
  display: none;
  z-index: 200;
  max-height: 400px;
  overflow-y: auto;
}

.search-dropdown.visible {
  display: block;
}

.search-dropdown-item {
  padding: 0.7rem 1rem;
  display: block;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

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

.search-dropdown-item:hover,
.search-dropdown-item.selected {
  background: var(--sidebar-hover);
}

.search-dropdown-item .result-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.search-dropdown-item .result-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0;
  overflow-y: auto;
}

/* Tree */
.tree-section {
  margin-bottom: 2px;
}

.tree-section > summary {
  list-style: none;
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  user-select: none;
}

.tree-section > summary::-webkit-details-marker {
  display: none;
}

.tree-section > summary::before {
  content: '▸';
  margin-right: 6px;
  display: inline-block;
  transition: transform 0.15s;
}

.tree-section[open] > summary::before {
  transform: rotate(90deg);
}

.tree-section > summary:hover {
  background: var(--sidebar-hover);
}

.tree-global {
  color: var(--text) !important;
  font-size: 0.9rem !important;
}

.tree-domain a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.tree-pages,
.tree-sections {
  list-style: none;
  padding: 0 0 0.3rem 0;
}

.tree-pages li,
.tree-sections li {
  padding: 0;
}

.tree-pages a,
.tree-sections a {
  display: block;
  padding: 0.3rem 1.2rem 0.3rem 2.4rem;
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.tree-pages a:hover,
.tree-sections a:hover {
  background: var(--sidebar-hover);
}

.tree-pages a.active,
.tree-sections a.active {
  background: var(--accent-light);
  border-left-color: var(--accent);
  font-weight: 600;
  color: var(--accent);
}

/* Subsection (expandable section under domain) */
.tree-subsection {
  border: none;
}

.tree-subsection > summary {
  display: block;
  padding: 0.3rem 1.2rem 0.3rem 2rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  list-style: none;
}

.tree-subsection > summary::-webkit-details-marker {
  display: none;
}

.tree-subsection > summary::before {
  content: '\25B6';
  display: inline-block;
  width: 1rem;
  font-size: 0.6rem;
  transition: transform 0.15s;
}

.tree-subsection[open] > summary::before {
  transform: rotate(90deg);
}

.tree-subsection > summary:hover {
  background: var(--sidebar-hover);
}

.tree-subsection .tree-pages {
  padding-left: 0.8rem;
}

.tree-subsection .tree-pages a {
  padding-left: 3rem;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.count {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
}

/* ── Main Content ──────────────────────────────────────────── */

.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
}

.breadcrumbs {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.breadcrumb-link {
  color: var(--link);
}

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

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

.content {
  flex: 1;
  padding: 2rem;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

/* ── Content Typography ────────────────────────────────────── */

.content h1 { font-size: 1.8rem; margin: 0 0 1rem 0; font-weight: 700; }
.content h2 { font-size: 1.4rem; margin: 2rem 0 0.8rem 0; font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.content h3 { font-size: 1.15rem; margin: 1.5rem 0 0.6rem 0; font-weight: 600; }
.content h4 { font-size: 1rem; margin: 1.2rem 0 0.5rem 0; font-weight: 600; }

.content p { margin: 0 0 1rem 0; }

.content ul, .content ol {
  margin: 0 0 1rem 1.5rem;
}

.content li {
  margin-bottom: 0.3rem;
}

.content code {
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
}

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

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

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.5rem 0;
  font-size: 0.9rem;
}

.content th, .content td {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  text-align: left;
}

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

.content tr:nth-child(even) {
  background: var(--bg-secondary);
}

.content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}

.content blockquote {
  background: var(--callout-bg);
  border-left: 4px solid var(--callout-border);
  padding: 1rem 1.2rem;
  margin: 1rem 0;
  border-radius: 0 6px 6px 0;
}

.content blockquote strong {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.content blockquote p {
  margin-bottom: 0.5rem;
}

.content blockquote p:last-child {
  margin-bottom: 0;
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* Task items */
.task-item {
  list-style: none;
  margin-left: -1.5rem;
  padding-left: 0;
}

.task-item.done {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* ── Badges ────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  color: white;
  margin-right: 4px;
}

.badge-done, .badge-approved { background: var(--badge-done); }
.badge-in_progress, .badge-in-progress { background: var(--badge-in-progress); }
.badge-backlog { background: var(--badge-backlog); }
.badge-blocked { background: var(--badge-blocked); }
.badge-testing, .badge-waiting_review { background: var(--badge-testing); }
.badge-high { background: var(--badge-high); }
.badge-medium { background: var(--badge-medium); }
.badge-low { background: var(--badge-low); }
.badge-domain { background: var(--accent); }
.badge-type { background: var(--text-muted); }

/* Method badges */
.method-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: monospace;
  color: white;
  margin-right: 6px;
  vertical-align: middle;
}

.method-get { background: var(--method-get); }
.method-post { background: var(--method-post); }
.method-put { background: var(--method-put); }
.method-delete { background: var(--method-delete); }
.method-patch { background: var(--method-patch); }

/* ── Login Page ────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-secondary);
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 20px var(--card-shadow);
  text-align: center;
}

.login-card h1 {
  margin-bottom: 0.3rem;
  font-size: 1.6rem;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.login-error {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.login-card input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.login-card button {
  width: 100%;
  padding: 0.7rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:hover {
  opacity: 0.9;
}

/* ── Landing Page ──────────────────────────────────────────── */

.landing {
  max-width: 960px;
}

.landing-header {
  margin-bottom: 1.5rem;
}

.landing-header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.landing-header p {
  color: var(--text-muted);
  font-size: 1rem;
}

.landing-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.landing-link {
  padding: 0.4rem 1rem;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent) !important;
  text-decoration: none !important;
}

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

.domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.domain-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem 1.5rem;
  text-decoration: none !important;
  color: var(--text) !important;
  transition: box-shadow 0.15s, transform 0.15s;
  display: block;
}

.domain-card:hover {
  box-shadow: 0 4px 16px var(--card-shadow);
  transform: translateY(-2px);
}

.domain-card h3 {
  font-size: 1.1rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.domain-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
  line-height: 1.4;
}

.domain-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.stat-badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
}

/* ── Domain Overview ───────────────────────────────────────── */

.domain-overview .domain-header {
  margin-bottom: 1.5rem;
}

.domain-overview .domain-header h1 {
  margin-bottom: 0.3rem;
}

.domain-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.domain-intro {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.section-block {
  margin-bottom: 1.5rem;
}

.section-block h3 {
  font-size: 1.1rem;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.section-count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
}

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

.page-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-list li:last-child {
  border-bottom: none;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem 0;
}

/* ── Page View ─────────────────────────────────────────────── */

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.page-title-row h1 {
  margin-bottom: 0;
}

.edit-btn {
  padding: 0.35rem 1rem;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}

.edit-btn:hover {
  background: var(--sidebar-hover);
}

.page-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.8rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}

.meta-source, .meta-owner, .meta-timeline, .meta-synced, .meta-updated, .meta-auth, .meta-db {
  color: var(--text-muted);
}

.meta-base-url code {
  font-size: 0.82rem;
}

.meta-subdomain {
  padding: 0.15rem 0.5rem;
  background: var(--accent-light);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--accent);
}

.meta-link {
  font-size: 0.8rem;
}

/* ── Annotation Panel ──────────────────────────────────────── */

.annotation-panel {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}

.annotation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.annotation-header h3 {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.annotation-edit-btn, .add-annotation-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
}

.annotation-edit-btn:hover, .add-annotation-btn:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.annotation-textarea {
  width: 100%;
  min-height: 200px;
  padding: 1rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-family: 'SF Mono', monospace;
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
}

.annotation-textarea:focus {
  border-color: var(--accent);
}

.annotation-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

/* ── Editor ────────────────────────────────────────────────── */

.editor-panel {
  margin-top: 1rem;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.editor-view-btns {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.view-btn {
  padding: 0.3rem 0.8rem;
  background: var(--bg);
  color: var(--text-muted);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
}
.view-btn:last-child { border-right: none; }
.view-btn.active {
  background: var(--accent);
  color: white;
}

.editor-container {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
  height: calc(100vh - 160px);
}

.editor-pane {
  flex: 1;
  display: flex;
  min-width: 0;
}

.editor-preview {
  flex: 1;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow-y: auto;
  min-width: 0;
}

/* Full preview mode */
.editor-container[data-view="preview"] .editor-pane { display: none; }
.editor-container[data-view="preview"] .editor-preview { flex: 1; }

.editor-textarea {
  width: 100%;
  height: 100%;
  padding: 1rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 0.85rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  box-sizing: border-box;
}

.editor-textarea:focus {
  border-color: var(--accent);
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn-save {
  padding: 0.4rem 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.btn-save:hover { opacity: 0.9; }

.btn-cancel {
  padding: 0.4rem 1.2rem;
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-cancel:hover { background: var(--sidebar-hover); }

/* ── Search Results ────────────────────────────────────────── */

.search-results {
  max-width: 700px;
}

.search-result {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

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

.result-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.result-meta {
  display: flex;
  gap: 0.3rem;
  margin: 0.3rem 0;
}

.result-snippet {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.result-snippet mark {
  background: #fff176;
  padding: 0 2px;
  border-radius: 2px;
}

[data-theme="dark"] .result-snippet mark {
  background: #5c5200;
  color: #fff;
}

/* ── 404 ───────────────────────────────────────────────────── */

.not-found {
  text-align: center;
  padding: 4rem 2rem;
}

.not-found h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.not-found p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ── Broken Wiki Links ─────────────────────────────────────── */

.broken-link {
  color: var(--badge-blocked);
  text-decoration: underline wavy;
  cursor: help;
}

/* ── Backlinks Section ────────────────────────────────────── */

.backlinks-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.backlinks-section h3 {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
  font-weight: 600;
}

.backlinks-section ul {
  list-style: none;
  padding: 0;
}

.backlinks-section li {
  padding: 0.3rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.backlinks-section .badge {
  font-size: 0.7rem;
}

/* ── Search Dropdown Enhancements ─────────────────────────── */

.search-dropdown-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: space-between;
}

.result-badges {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
}

.result-badges .badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
}

.search-dropdown-viewall {
  display: block;
  padding: 0.6rem 1rem;
  text-align: center;
  color: var(--accent) !important;
  font-size: 0.85rem;
  font-weight: 500;
  border-top: 1px solid var(--border);
  text-decoration: none !important;
}

.search-dropdown-viewall:hover {
  background: var(--sidebar-hover);
}

.search-dropdown-empty {
  padding: 0.7rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Feature Table ─────────────────────────────────────────── */

.feature-table {
  font-size: 0.88rem;
}

.feature-table th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.feature-table th:hover {
  background: var(--sidebar-hover);
}

.feature-table th::after {
  content: ' \25B8';
  color: var(--text-muted);
  font-size: 0.7rem;
}

.feature-table th.sort-asc::after { content: ' \25B4'; }
.feature-table th.sort-desc::after { content: ' \25BE'; }

/* ── Timeline Bar ──────────────────────────────────────────── */

.meta-timeline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.timeline-bar {
  display: inline-block;
  width: 80px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}

.timeline-fill {
  display: block;
  height: 100%;
  background: var(--badge-in-progress);
  border-radius: 3px;
  transition: width 0.3s;
}

.timeline-fill.overdue {
  background: var(--badge-high);
}

/* ── Section Header ────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.section-header h3 {
  margin-bottom: 0;
}

.create-page-btn {
  padding: 0.25rem 0.7rem;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
}

.create-page-btn:hover {
  background: var(--sidebar-hover);
}

/* ── Modal ─────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.modal-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.modal-card h3 {
  margin-bottom: 1.2rem;
}

.modal-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.modal-card input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 1rem;
  outline: none;
}

.modal-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ── Last Updated ─────────────────────────────────────────── */

.page-meta-date {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

/* ── Inline TOC ───────────────────────────────────────────── */

.toc-inline {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  margin-bottom: 1.5rem;
  background: var(--bg-secondary);
}

.toc-inline summary {
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
  user-select: none;
  list-style: none;
}

.toc-inline summary::-webkit-details-marker { display: none; }

.toc-inline summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.15s;
}

.toc-inline[open] summary::before {
  transform: rotate(90deg);
}

.toc-inline ul {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0 0;
}

.toc-inline li {
  padding: 0.2rem 0;
}

.toc-inline li a {
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
}

.toc-inline li a:hover {
  color: var(--accent);
  text-decoration: none;
}

.toc-inline .toc-sub {
  padding-left: 1.2rem;
}

.toc-inline .toc-sub a {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Right-sidebar TOC ────────────────────────────────────── */

.toc-sidebar {
  width: 220px;
  min-width: 220px;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 1.5rem 1rem 1.5rem 0;
  border-left: 1px solid var(--border);
  display: none;
}

.has-toc-sidebar .toc-sidebar {
  display: block;
}

.toc-nav h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 0.6rem 1rem;
  font-weight: 600;
}

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

.toc-nav li {
  padding: 0;
}

.toc-nav li a {
  display: block;
  padding: 0.25rem 0.8rem 0.25rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.toc-nav li a:hover {
  color: var(--text);
  text-decoration: none;
}

.toc-nav li.toc-sub a {
  padding-left: 1.8rem;
  font-size: 0.78rem;
}

.toc-nav li a.toc-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.toc-sidebar::-webkit-scrollbar {
  width: 4px;
}
.toc-sidebar::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 2px;
}

/* ── Scroll-to-top button ─────────────────────────────────── */

.scroll-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s, transform 0.25s;
  z-index: 90;
}

.scroll-top.visible {
  opacity: 1;
  visibility: visible;
}

.scroll-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* ── Loading States ───────────────────────────────────────── */

.btn-loading {
  opacity: 0.7;
  pointer-events: none;
  position: relative;
}

.btn-loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}

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

.save-success {
  background: var(--badge-done) !important;
  color: white !important;
  transition: background 0.3s;
}

.search-loading::after {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 1rem auto;
}

/* ── Search Highlighting ──────────────────────────────────── */

mark, .search-highlight {
  background: #fff176;
  padding: 0 2px;
  border-radius: 2px;
  color: inherit;
}

[data-theme="dark"] mark,
[data-theme="dark"] .search-highlight {
  background: #5c5200;
  color: #fff;
}

/* ── Print Styles ─────────────────────────────────────────── */

@media print {
  .sidebar,
  .topbar,
  .hamburger,
  .theme-toggle,
  .sidebar-search,
  .search-dropdown,
  .edit-btn,
  .editor-panel,
  .annotation-edit-btn,
  .add-annotation-btn,
  .create-page-btn,
  .scroll-top,
  .toc-sidebar,
  .toc-inline,
  .modal-overlay {
    display: none !important;
  }

  body {
    display: block;
    font-family: Georgia, 'Times New Roman', serif;
    color: #000;
    background: #fff;
    font-size: 12pt;
    line-height: 1.5;
  }

  .main-content {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .content {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  a[href] {
    color: #000;
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
  }

  a[href^="#"]::after,
  a[href^="javascript"]::after {
    content: none;
  }

  .page-meta {
    border: 1px solid #ccc;
    background: #f9f9f9;
  }

  pre, code {
    background: #f4f4f4 !important;
    border: 1px solid #ddd;
  }

  table, th, td {
    border: 1px solid #999;
  }

  pre, table, blockquote, img {
    page-break-inside: avoid;
  }

  h2, h3, h4 {
    page-break-after: avoid;
  }

  .badge {
    border: 1px solid #999;
    background: #eee !important;
    color: #333 !important;
  }
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 1200px) {
  .toc-sidebar {
    display: none !important;
  }
}

@media (min-width: 1201px) {
  .has-toc-sidebar .toc-inline {
    display: none;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    transition: left 0.25s ease;
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
  }

  .hamburger {
    display: block;
  }

  .content {
    padding: 1.5rem 1rem;
  }

  .editor-container {
    flex-direction: column;
  }

  .domain-grid {
    grid-template-columns: 1fr;
  }

  .landing-links {
    flex-direction: column;
  }

  .scroll-top {
    bottom: 1rem;
    right: 1rem;
  }
}
