:root {
  --bg: #ffffff; --fg: #111827; --muted: #6b7280; --border: #e5e7eb;
  --accent: #2563eb; /* primary blue */
  --accent-weak: #eff6ff;
  --callout-info-bg: #eef2ff; --callout-info-border: #c7d2fe;
  --callout-warn-bg: #fff7ed; --callout-warn-border: #fed7aa;
  --callout-tip-bg:  #ecfdf5; --callout-tip-border:  #a7f3d0;
  --status-final-bg: #16a34a; --status-final-fg: #ffffff;
  --status-draft-bg: #d97706; --status-draft-fg: #ffffff;
  --status-stub-bg: #dc2626; --status-stub-fg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f1a; --fg: #e5e7eb; --muted: #9ca3af; --border: #1f2937;
    --accent: #60a5fa; --accent-weak: #0b1220;
    --callout-info-bg:#111827; --callout-info-border:#374151;
    --callout-warn-bg:#1f2937; --callout-warn-border:#4b5563;
    --callout-tip-bg: #0f1f16; --callout-tip-border: #1f4732;
    --status-final-bg: #166534; --status-final-fg: #ecfdf5;
    --status-draft-bg: #92400e; --status-draft-fg: #fff7ed;
    --status-stub-bg: #991b1b; --status-stub-fg: #fee2e2;
  }
}

html[data-theme='light'] {
  --bg: #ffffff; --fg: #111827; --muted: #6b7280; --border: #e5e7eb;
  --accent: #2563eb; --accent-weak: #eff6ff;
  --callout-info-bg: #eef2ff; --callout-info-border: #c7d2fe;
  --callout-warn-bg: #fff7ed; --callout-warn-border: #fed7aa;
  --callout-tip-bg:  #ecfdf5; --callout-tip-border:  #a7f3d0;
  --status-final-bg: #16a34a; --status-final-fg: #ffffff;
  --status-draft-bg: #d97706; --status-draft-fg: #ffffff;
  --status-stub-bg: #dc2626; --status-stub-fg: #ffffff;
}

html[data-theme='dark'] {
  --bg: #0b0f1a; --fg: #e5e7eb; --muted: #9ca3af; --border: #1f2937;
  --accent: #60a5fa; --accent-weak: #0b1220;
  --callout-info-bg:#111827; --callout-info-border:#374151;
  --callout-warn-bg:#1f2937; --callout-warn-border:#4b5563;
  --callout-tip-bg: #0f1f16; --callout-tip-border: #1f4732;
  --status-final-bg: #166534; --status-final-fg: #ecfdf5;
  --status-draft-bg: #92400e; --status-draft-fg: #fff7ed;
  --status-stub-bg: #991b1b; --status-stub-fg: #fee2e2;
}

.status, .status-chip {
  display: inline-block;
  margin-left: 0.5em;
  padding: 0.15em 0.6em;
  border-radius: 1em;
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid currentColor;
}
.status.final, .status-final { background: var(--status-final-bg); color: var(--status-final-fg); }
.status.draft, .status-draft { background: var(--status-draft-bg); color: var(--status-draft-fg); }
.status.stub, .status-stub { background: var(--status-stub-bg); color: var(--status-stub-fg); }

html { box-sizing: border-box; }
*, *:before, *:after { box-sizing: inherit; }
body {
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem;
  z-index: 100;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 0;
}

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

.nav-toggle {
  background: none;
  border: 0;
  font-size: 1.25rem;
  cursor: pointer;
  display: none;
}

.search { position: relative; flex: 1; margin: 0 1rem; }
.search input { width: 100%; padding: 0.25rem 0.5rem; }
.search-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg); border: 1px solid var(--border); max-height: 300px; overflow: auto; z-index: 1000; }
.search-results a { display: block; padding: 0.25rem 0.5rem; border-bottom: 1px solid var(--border); text-decoration: none; }
.search-results a:hover { background: var(--accent-weak); }
.search-results a:last-child { border-bottom: 0; }
.sr-title { font-weight: 600; }
.sr-path { font-size: 0.75rem; color: var(--muted); }

.page {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 32px;
  padding: 32px 24px;
}
  .sidebar {
    border-right: 1px solid var(--border);
    padding-right: 16px;
  }
  .nav-tree, .nav-subtree {
    list-style: none;
    margin: 0;
    padding-left: 1rem;
  }
  .nav-number {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
}

@media (max-width: 992px) {
  .page { grid-template-columns: 1fr; }
  .sidebar { display: none; border: none; padding: 0; }
  .nav-toggle { display: block; }
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.25;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}
h1, h2 { font-weight: 600; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }

p, ul, ol, table, pre, blockquote {
  margin: 1em 0;
}
ul, ol { padding-left: 1.5em; }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover, a:focus {
  color: #1e40af;
  text-decoration: underline;
}
a:focus-visible, button:focus-visible, .sidebar a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

nav.breadcrumbs {
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  color: var(--muted);
}
nav.breadcrumbs a { color: inherit; }

table {
  border-collapse: collapse;
  width: 100%;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.5em;
}
th {
  background: var(--accent-weak);
  text-align: left;
}

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
pre {
  overflow-x: auto;
  padding: 1em;
  background: var(--accent-weak);
}

blockquote {
  border-left: 4px solid var(--border);
  margin: 0;
  padding-left: 1em;
  color: var(--muted);
}

.callout { border-left: 4px solid; padding: 1em; }
.callout.info { background: var(--callout-info-bg); border-color: var(--callout-info-border); }
.callout.warn { background: var(--callout-warn-bg); border-color: var(--callout-warn-border); }
.callout.tip  { background: var(--callout-tip-bg);  border-color: var(--callout-tip-border); }

#comment-list, #comment-list ul { list-style: none; margin: 0; padding: 0; }
.comment-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); display: flex; gap: 0.5rem; }
.comment-item:last-child { border-bottom: 0; }
.comment-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
  overflow: hidden;
}
.comment-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.comment-content { flex: 1; display: flex; flex-direction: column; }
.comment-message { margin: 0; }
.comment-time {
  display: block;
  font-size: 0.8rem;
  color: var(--fg);
  opacity: 0.6;
  margin-top: 0.25rem;
}
.comment-actions { margin-top: 0.5rem; display: flex; gap: 0.5rem; }
.comment-form { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.comment-text {
  padding: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}
.comment-submit {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
.comment-submit:hover, .comment-submit:focus { background: #1e40af; }

.user-info { position: relative; margin-left: 1rem; }
.user-info img {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
  display: block;
}
.user-dropdown {
  position: absolute; right: 0; top: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.5rem;
  display: flex; flex-direction: column; gap: 0.25rem;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}
.user-dropdown[hidden] { display: none !important; }
.user-dropdown a, .user-dropdown button {
  background: none;
  border: 0;
  text-align: left;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0;
}
.user-dropdown a:hover, .user-dropdown button:hover {
  background: var(--accent-weak);
}

.login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 300px;
}
.login-logo {
  width: 120px;
}
.login-form input,
.login-form button {
  padding: 0.5rem;
}

/* Dashboard metrics */
.metrics-grid {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.metric-card {
  flex: 1 1 200px;
  border: 1px solid var(--border);
  background: var(--accent-weak);
  padding: 1rem;
  text-align: center;
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.metric-title {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0 0 0.25rem;
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 600;
}

.metric-label {
  color: var(--muted);
}

@media (max-width: 600px) {
  .metrics-grid {
    flex-direction: column;
  }
}

/* Table styles */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  background: var(--accent-weak);
}

.data-table tbody tr:nth-child(even) {
  background: var(--bg);
}

.data-table tbody tr:hover {
  background: var(--accent-weak);
}

/* Responsive layout helpers */
.responsive-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.hidden {
  display: none !important;
}

@media (max-width: 600px) {
  .data-table th,
  .data-table td {
    padding: 0.5rem 0.25rem;
  }
}
