/* ---- Reset & Variables ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Brand tokens shared with the IAM UI and daevix.com (www/).
   Dark-only, matching the IAM surfaces verbatim. */
:root {
  --bg: #0a0a0b;
  --fg: #e8e6e3;
  --muted: #18181b;
  --muted-fg: #9a9893;
  --border: #222225;
  --accent: #18181b;
  --accent-fg: #e8e6e3;
  --code-bg: #141416;
  --signal: #e34234;        /* primary accent: links, active nav, emphasis */
  --signal-tint: rgba(227, 66, 52, 0.12);
  --amber: #e8b339;         /* caution / attention, not danger */
  --amber-tint: rgba(232, 179, 57, 0.18);
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, 'SFMono-Regular', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */
.site-wrapper { display: flex; min-height: 100vh; }

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

/* ---- Top Bar ---- */
.top-bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 0.75rem 1.5rem;
}
.top-bar-left { display: flex; align-items: center; gap: 1rem; }
.top-bar-right { display: flex; align-items: center; gap: 0.5rem; }
.top-bar-title { font-size: 0.875rem; font-weight: 600; color: var(--muted-fg); }

.mobile-menu-btn {
  display: none; background: none; border: 1px solid var(--border);
  border-radius: 0.375rem; padding: 0.375rem; cursor: pointer; color: var(--fg);
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 16rem; flex-shrink: 0;
  overflow-y: auto; border-right: 1px solid var(--border);
  background: var(--bg); padding: 1.5rem 1rem;
}
.sidebar-overlay { display: none; }

.sidebar-header { margin-bottom: 1.5rem; }
.sidebar-brand { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; }
.sidebar-logo { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.01em; color: var(--fg); text-decoration: none; }
.sidebar-subtitle { font-size: 0.75rem; color: var(--muted-fg); margin-top: 0.35rem; }
.logo { width: 26px; height: 26px; display: block; flex: none; }

.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-section-title {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted-fg); margin-bottom: 0.5rem;
}
.sidebar-links { list-style: none; }
.sidebar-link {
  display: block; padding: 0.375rem 0.75rem; border-radius: 0.375rem;
  font-size: 0.875rem; color: var(--muted-fg); text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { color: var(--fg); background: var(--accent); }
.sidebar-link.active { color: var(--signal); background: var(--signal-tint); font-weight: 500; }

/* ---- Doc Layout ---- */
.doc-layout { display: flex; }
.doc-content { flex: 1; min-width: 0; padding: 2rem 1.5rem 4rem; }
@media (min-width: 1024px) { .doc-content { padding: 2rem 2rem 4rem; } }

.doc-header { margin-bottom: 2rem; }
.doc-section-label { font-size: 0.875rem; color: var(--muted-fg); margin-bottom: 0.25rem; }
.doc-title-row { display: flex; align-items: center; gap: 0.25rem; }
.doc-title-row h1 { font-size: 1.875rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.doc-description { margin-top: 0.5rem; font-size: 1.125rem; color: var(--muted-fg); }

/* ---- TOC Sidebar ---- */
.toc-sidebar { display: none; width: 16rem; flex-shrink: 0; }
@media (min-width: 1280px) { .toc-sidebar { display: block; } }
.toc-wrapper { position: sticky; top: 5rem; padding: 2rem 1rem 2rem 0; }
.toc-heading {
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted-fg); margin-bottom: 0.75rem;
}
.toc-wrapper nav#TableOfContents ul { list-style: none; }
.toc-wrapper nav#TableOfContents > ul > li > a {
  display: block; font-size: 0.875rem; color: var(--muted-fg); text-decoration: none;
  padding: 0.125rem 0; transition: color 0.15s;
}
.toc-wrapper nav#TableOfContents > ul > li > a:hover { color: var(--fg); }
.toc-wrapper nav#TableOfContents > ul > li > ul > li > a {
  display: block; font-size: 0.875rem; color: var(--muted-fg); text-decoration: none;
  padding: 0.125rem 0; padding-left: 1rem; transition: color 0.15s;
}
.toc-wrapper nav#TableOfContents > ul > li > ul > li > a:hover { color: var(--fg); }

/* ---- Prose (Content Styling) ---- */
.prose { max-width: none; font-size: 1rem; line-height: 1.75; }
.prose h1 { font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; margin-top: 2.5rem; margin-bottom: 1rem; }
.prose h2 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; margin-top: 2rem; margin-bottom: 0.75rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.25rem; font-weight: 600; margin-top: 1.5rem; margin-bottom: 0.5rem; }
.prose h4 { font-size: 1.125rem; font-weight: 600; margin-top: 1.25rem; margin-bottom: 0.5rem; }
.prose p { margin-bottom: 1rem; }
.prose a { color: var(--signal); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.prose a:hover { opacity: 0.8; }
.prose strong { font-weight: 600; }
.prose mark { background: var(--amber-tint); color: var(--fg); padding: 0.05em 0.25em; border-radius: 0.2rem; }
.prose ul, .prose ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.prose li { margin-bottom: 0.25rem; }
.prose li > ul, .prose li > ol { margin-top: 0.25rem; margin-bottom: 0; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.prose blockquote {
  border-left: 3px solid var(--border); padding-left: 1rem;
  color: var(--muted-fg); margin-bottom: 1rem; font-style: italic;
}

/* Code */
.prose code {
  font-family: var(--font-mono);
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 0.25rem;
  padding: 0.08rem 0.3rem; font-size: 0.8125em; font-weight: 400;
}
.prose pre { margin-bottom: 1rem; border-radius: 0.5rem; border: 1px solid var(--border); overflow-x: auto; }
.prose pre code { font-family: var(--font-mono); background: transparent; border: none; padding: 0; border-radius: 0; font-size: 0.8125rem; }

/* Chroma syntax highlighting */
.prose .highlight pre { margin: 0; padding: 1rem; }

/* Tables */
.prose table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.875rem; }
.prose th { text-align: left; font-weight: 600; padding: 0.5rem 0.75rem; border-bottom: 2px solid var(--border); }
.prose td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.prose tr:last-child td { border-bottom: none; }

/* ---- Markdown Actions Dropdown ---- */
.md-actions { position: relative; display: inline-block; }
.md-actions-btn {
  background: none; border: none; cursor: pointer;
  padding: 0.25rem; border-radius: 0.375rem; color: var(--muted-fg);
  transition: background 0.15s, color 0.15s; display: inline-flex; align-items: center;
}
.md-actions-btn:hover { color: var(--fg); background: var(--accent); }
.md-actions-menu {
  display: none; position: absolute; left: 0; top: 100%; margin-top: 0.25rem;
  z-index: 50; min-width: 220px; border-radius: 0.5rem;
  border: 1px solid var(--border); background: var(--bg);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); padding: 0.25rem 0;
}
.md-actions-menu.open { display: block; }
.md-actions-item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.5rem 0.75rem; font-size: 0.875rem; color: var(--fg);
  background: none; border: none; cursor: pointer; text-decoration: none;
  transition: background 0.15s;
}
.md-actions-item:hover { background: var(--accent); }
.md-actions-item svg { color: var(--muted-fg); flex-shrink: 0; }

/* ---- Search ---- */
.search-btn {
  display: flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--border); border-radius: 0.375rem;
  padding: 0.375rem 0.75rem; font-size: 0.875rem; color: var(--muted-fg);
  background: none; cursor: pointer; transition: background 0.15s;
}
.search-btn:hover { background: var(--accent); }
.search-btn-text { display: none; }
.search-btn-kbd {
  display: none; align-items: center; gap: 2px;
  border: 1px solid var(--border); border-radius: 0.25rem;
  padding: 0.125rem 0.375rem; font-size: 0.625rem; font-family: var(--font-mono);
}
@media (min-width: 640px) { .search-btn-text, .search-btn-kbd { display: inline-flex; } }

.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 50;
  align-items: flex-start; justify-content: center; padding-top: 20vh;
  background: rgb(0 0 0 / 0.5);
}
.search-overlay.open { display: flex; }
.search-dialog {
  width: 100%; max-width: 32rem; border-radius: 0.5rem;
  border: 1px solid var(--border); background: var(--bg);
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}
.search-input-row {
  display: flex; align-items: center; gap: 0.75rem;
  border-bottom: 1px solid var(--border); padding: 0 1rem;
  color: var(--muted-fg);
}
.search-input-row input {
  flex: 1; background: transparent; border: none; outline: none;
  padding: 0.75rem 0; font-size: 0.875rem; color: var(--fg);
}
.search-input-row input::placeholder { color: var(--muted-fg); }
.search-results { max-height: 20rem; overflow-y: auto; padding: 0.5rem; }
.search-results:empty { display: none; }
.search-result {
  display: block; width: 100%; padding: 0.5rem 0.75rem; border-radius: 0.375rem;
  text-align: left; text-decoration: none; color: var(--fg);
  transition: background 0.15s; cursor: pointer; border: none; background: none;
}
.search-result:hover { background: var(--accent); }
.search-result-section { font-size: 0.75rem; color: var(--muted-fg); }
.search-result-title { font-size: 0.875rem; font-weight: 500; }
.search-result-desc { font-size: 0.75rem; color: var(--muted-fg); }
.search-no-results { padding: 1.5rem; text-align: center; font-size: 0.875rem; color: var(--muted-fg); }

/* ---- Mobile ---- */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.2s;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgb(0 0 0 / 0.5);
  }
  .mobile-menu-btn { display: inline-flex; }
}

/* ---- Chroma (Syntax Highlighting) - dark ---- */
.highlight { background: var(--code-bg); }
.chroma { background: var(--code-bg); }
.chroma .ln { color: var(--muted-fg); margin-right: 0.5rem; }
.chroma .k, .chroma .kc, .chroma .kd, .chroma .kn, .chroma .kp, .chroma .kr { color: #ff7b72; }
.chroma .nc, .chroma .nf, .chroma .nb { color: #d2a8ff; }
.chroma .s, .chroma .s1, .chroma .s2, .chroma .sa, .chroma .sb, .chroma .sc, .chroma .se, .chroma .sh, .chroma .si, .chroma .sx { color: #a5d6ff; }
.chroma .mi, .chroma .mf, .chroma .mh, .chroma .mo { color: #79c0ff; }
.chroma .c, .chroma .c1, .chroma .ch, .chroma .cm, .chroma .cp, .chroma .cpf, .chroma .cs { color: #8b949e; font-style: italic; }
.chroma .o, .chroma .ow { color: #ff7b72; }
.chroma .p { color: var(--fg); }
.chroma .na { color: #79c0ff; }
.chroma .nt { color: #7ee787; }
