:root {
  color-scheme: light dark;
  --fg: #1a1f1a;
  --bg: #ffffff;
  --sidebar-bg: #f2f8f0;
  --muted: #62705f;
  --border: #d9e3d4;
  --accent: #237a3d;
  --accent-bg: rgba(35, 122, 61, 0.1);
  --accent2: #f2b705;
  --accent2-bg: rgba(242, 183, 5, 0.16);
  --accent2-fg: #7a5b00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e8ede6;
    --bg: #161f18;
    --sidebar-bg: #1c2a20;
    --muted: #9db39a;
    --border: #2f4536;
    --accent: #5fcf82;
    --accent-bg: rgba(95, 207, 130, 0.15);
    --accent2: #ffce3a;
    --accent2-bg: rgba(255, 206, 58, 0.16);
    --accent2-fg: #ffe28a;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}

.app {
  display: flex;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 240px;
  flex-shrink: 0;
  height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0.75rem;
  overflow: hidden;
}

.app-title {
  font-size: 1.05rem;
  margin: 0 0.5rem 1.25rem;
}

.nav-group-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 1.25rem 0.5rem 0.35rem;
}

.nav-group-label:first-of-type {
  margin-top: 0;
}

.nav-item {
  display: block;
  padding: 0.45rem 0.5rem;
  margin: 0.1rem 0;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav-item:not(.nav-top) {
  padding-left: 1.15rem;
  font-size: 0.85rem;
}

.nav-item:hover {
  background: var(--accent-bg);
}

.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.content {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 2.5rem 3rem;
  overflow-x: hidden;
  overflow-y: auto;
}

.panel {
  display: none;
  width: 90%;
  max-width: 1200px;
  margin: 0 auto;
}

.panel.active {
  display: block;
}

h1 {
  font-size: 1.6rem;
  margin-bottom: 0.25rem;
}

h2 {
  font-size: 1.25rem;
  margin-top: 2rem;
}

h3 {
  font-size: 1.05rem;
  margin-top: 1.5rem;
}

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

a:hover {
  text-decoration: none;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.95rem;
}

table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  vertical-align: top;
}

.section-nav {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 0;
  margin-bottom: 0.75rem;
  background: var(--bg);
}

.section-nav-link {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--sidebar-bg);
  color: var(--fg);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
}

.section-nav-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.category-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem 2rem 2.25rem;
  margin: 0 0 2.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 24px rgba(0, 0, 0, 0.05);
  scroll-margin-top: 4rem;
}

@media (prefers-color-scheme: dark) {
  .category-block {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 24px rgba(0, 0, 0, 0.3);
  }
}

.category-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 1.5rem;
}

.category-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
}

.category-icon svg {
  width: 28px;
  height: 28px;
}

.category-title-group {
  flex: 1;
}

.category-eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.2rem;
}

.category-name {
  font-size: 1.5rem;
  margin: 0;
}

.category-brief {
  text-align: right;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.4;
}

.category-brief span {
  display: block;
}

.category-brief strong {
  color: var(--fg);
}

.meta-strip {
  display: flex;
  gap: 2rem;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1rem;
  margin-bottom: 1.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.meta-strip .meta-item {
  flex: 1;
}

.meta-strip strong {
  color: var(--fg);
}

.section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--accent);
  border-left: 3px solid var(--accent);
  padding-left: 0.6rem;
  margin: 2rem 0 0.75rem;
}

.category-block > .section-label:first-of-type {
  margin-top: 0;
}

.callout {
  background: var(--accent2-bg);
  border: 1px solid var(--accent2);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin: 1.75rem 0;
}

.callout-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--accent2-fg);
  margin: 0 0 0.6rem;
}

.callout p {
  margin: 0.6rem 0;
}

.callout p:first-of-type {
  margin-top: 0;
}

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

.sources-panel {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid var(--border);
  scroll-margin-top: 4rem;
}

.sources-panel h1 {
  margin-bottom: 1.5rem;
}

.source-group-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--accent);
  border-left: 3px solid var(--accent);
  padding-left: 0.6rem;
  margin: 2rem 0 0.75rem;
}

.source-group-title:first-of-type {
  margin-top: 0;
}

.source-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.source-entry {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  scroll-margin-top: 1rem;
}

.source-entry:last-child {
  border-bottom: none;
}

.source-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.source-id {
  flex-shrink: 0;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent2-bg);
  color: var(--accent2-fg);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.source-text {
  flex: 1;
  color: var(--fg);
}

.source-link {
  flex-shrink: 0;
  font-size: 0.8rem;
  white-space: nowrap;
}

.citation {
  margin-left: 0.2em;
  vertical-align: super;
  line-height: 0;
}

.citation-ref {
  position: relative;
  display: inline-block;
  padding-top: 4px;
}

.citation-ref a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  text-decoration: none;
  line-height: 1;
}

.citation-ref a:hover {
  background: var(--accent);
  color: #fff;
}

.citation-popover {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  max-width: 70vw;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  padding: 0.65rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: left;
  color: var(--fg);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 10;
  pointer-events: none;
}

.citation-ref:hover .citation-popover,
.citation-ref:focus-within .citation-popover {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.citation-popover-id {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--accent2-bg);
  color: var(--accent2-fg);
  font-size: 0.68rem;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 0.35rem;
}

.citation-popover-text {
  display: block;
  color: var(--muted);
}

.citation-popover-link {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
}

/* User avatar widget injected at the bottom of the sidebar by auth.js */
.smg-user-widget {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: auto;
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.smg-user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  min-width: 0;
}

.smg-user-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.smg-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--accent2);
  color: var(--accent2-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  user-select: none;
  overflow: hidden;
}

.smg-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.smg-signout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.6;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.smg-signout-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 640px) {
  html, body {
    overflow: auto;
    height: auto;
  }

  .app {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    width: auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .smg-user-widget {
    margin-top: 1rem;
  }

  .content {
    height: auto;
    overflow: visible;
    padding: 1.5rem;
  }
}
