/* cmux Documentation Theme — cohesive with the desktop app
   ---------------------------------------------------------
   Goals
   - Honor the app's color tokens and typography
   - Improve readability (spacing, line-length, contrast)
   - Sharpen components (sidebar, code, tables, kbd, details)
   - Keep mdBook structure intact; override with CSS variables only
*/

:root {
  /* Core tokens mirrored from src/styles/colors.tsx */
  --color-background: hsl(0deg 2.51% 10.04%);
  --color-background-secondary: hsl(0deg 0% 0%);
  --color-border: hsl(240 2% 25%);
  --color-text: hsl(0 0% 83%);
  --color-text-secondary: hsl(0 0% 42%);

  /* Brand/Mode accents */
  --color-plan-mode: hsl(210 70% 40%);
  --color-plan-mode-hover: color-mix(in srgb, var(--color-plan-mode), white 20%);
  --color-exec-mode: hsl(268.56 94.04% 55.19%);
  --color-edit-mode: hsl(120 50% 35%);
  --color-interrupted: hsl(38 92% 50%);

  /* Docs-specific tokens */
  --color-code: hsl(214.52deg 100% 71.11%);
  --link-color: var(--color-plan-mode);
  --link-hover: var(--color-plan-mode-hover);
  --content-max-width: 78ch;
  --radius-lg: 10px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --shadow-1: 0 1px 1px hsl(0 0% 0% / 0.25);
  --shadow-2: 0 2px 10px hsl(0 0% 0% / 0.35);

  /* Typography tokens (fallbacks match src/styles/fonts.tsx) */
  --font-primary:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  --font-monospace:
    "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "Courier New", monospace, "Apple Color Emoji",
    "Segoe UI Emoji", "Segoe UI Symbol";

  /* mdBook variable overrides */
  --bg: var(--color-background) !important;
  --fg: var(--color-text) !important;
  --sidebar-bg: var(--color-background-secondary) !important;
  --sidebar-fg: var(--color-text) !important;
  --icons: var(--color-text-secondary) !important;
  --table-alternate-bg: var(--color-background-secondary) !important;
  --line-height: 1.6;
}

/* Base layout and typography */
html,
body {
  background: var(--color-background) !important;
  color: var(--color-text) !important;
  font-family: var(--font-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.content .page,
.content {
  line-height: var(--line-height);
  background: var(--color-background) !important;
}

.content .chapter {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 2rem 2.25rem;
  line-height: var(--line-height);
  letter-spacing: 0.01em;
}

/* Headings */
h2,
h3 {
  margin-block-start: 1em;
}
h4,
h5 {
  margin-block-start: 1em;
}
.content .chapter h1,
.content .chapter h2,
.content .chapter h3,
.content .chapter h4,
.content .chapter h5,
.content .chapter h6 {
  color: var(--color-text);
  border-bottom-color: var(--color-border) !important;
}

.content .chapter h1 {
  font-size: 2rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
  margin-top: 0.5rem;
}
.content .chapter h2 {
  font-size: 1.55rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--color-border);
  margin-top: 2.2rem;
}
.content .chapter h3 {
  font-size: 1.25rem;
  margin-top: 1.8rem;
  color: color-mix(in srgb, var(--color-text), white 5%);
}

/* Heading anchors */
.header .anchor {
  color: var(--color-text-secondary) !important;
}
.header .anchor:focus-visible {
  outline: 2px solid var(--color-plan-mode);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Links */
a {
  color: var(--link-color) !important;
  text-underline-offset: 2px;
  text-decoration-thickness: 0.08em;
}
a:hover {
  color: var(--link-hover) !important;
  text-decoration: none;
}
a:focus-visible {
  outline: 2px solid var(--color-plan-mode);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg) !important;
  border-right: 1px solid var(--color-border) !important;
}
.sidebar .part-title {
  color: color-mix(in srgb, var(--color-text), white 20%) !important;
  font-weight: 700;
}
.sidebar .chapter li.chapter-item a {
  color: var(--color-text) !important;
}
.sidebar .chapter li.chapter-item a.active {
  color: var(--color-plan-mode) !important;
  background: transparent !important;
}
.sidebar .chapter li.chapter-item a:hover {
  color: var(--link-hover) !important;
  background: color-mix(in srgb, var(--color-background-secondary), white 8%);
}
.sidebar-resize-handle {
  background: var(--color-background-secondary) !important;
}

/* Menu bar */
#menu-bar {
  background: var(--color-background-secondary) !important;
  border-bottom: 1px solid var(--color-border) !important;
}
.icon-button {
  color: var(--color-text-secondary) !important;
}
.icon-button:hover {
  color: var(--color-text) !important;
}
#theme-toggle,
.theme-popup {
  display: none !important;
}

/* Search */
#searchbar {
  background: var(--color-background-secondary) !important;
  border: 1px solid var(--color-border) !important;
  color: var(--color-text) !important;
  border-radius: var(--radius-sm);
}
#searchbar:focus {
  border-color: var(--color-plan-mode) !important;
  outline: none;
  box-shadow: 0 0 0 3px hsl(from var(--color-plan-mode) h s l / 0.15);
}

/* Paragraph rhythm */
.content .chapter p {
  margin: 0.9rem 0;
}

/* Lists */
.content .chapter ul,
.content .chapter ol {
  padding-left: 1.4rem;
  margin: 0.75rem 0;
}
.content .chapter li {
  margin: 0.35rem 0;
}
.content .chapter li::marker {
  color: var(--color-text-secondary);
}

.content ul {
  margin-block-start: 0;
  line-height: 1.6;
}

.content p {
  line-height: var(--line-height);
}

/* Remove margin between p and following list */
p:has(+ ul),
p:has(+ ol) {
  margin-block-end: 0.5em;
}

/* Inline code */
:not(pre) > code {
  background: var(--color-background-secondary) !important;
  color: var(--color-code) !important;
  padding: 2px 6px;
  font-family: var(--font-monospace);
  font-size: 0.92em;
}

/* Code blocks */
pre {
  background: var(--color-background-secondary) !important;
  border: 1px solid var(--color-border) !important;
  box-shadow: var(--shadow-1);
  overflow: auto;
  margin: 1rem 0;
}
pre > code {
  background: transparent !important;
  color: var(--color-code) !important;
  display: block;
  padding: 0.9rem 1rem;
  font-family: var(--font-monospace);
}

/* Code blocks inside lists */
.content .chapter li > pre,
.content .chapter li > div > pre {
  margin: 0.75rem 0 0.9rem;
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.1em 0;
  background: var(--color-background-secondary) !important;
  border-radius: var(--radius-md);
}
table thead {
  background: color-mix(in srgb, var(--color-background-secondary), white 8%);
  border-bottom: 2px solid var(--color-border) !important;
}
table th,
table td {
  padding: 0.75em 1em;
  border: 1px solid var(--color-border) !important;
  text-align: left !important;
  color: var(--color-text) !important;
}
table th {
  font-weight: 700;
  font-size: 1.05em;
  color: color-mix(in srgb, var(--color-text), white 10%) !important;
}
table tbody tr:hover {
  background: color-mix(in srgb, var(--color-background-secondary), white 2%) !important;
}
table code {
  background: var(--color-background) !important;
  color: var(--color-code) !important;
  font-family: var(--font-monospace);
  font-size: 0.9em;
}

/* Blockquotes (callout style) */
blockquote {
  border: 1px solid var(--color-border) !important;
  border-left: 4px solid var(--color-plan-mode) !important;
  background: color-mix(in srgb, var(--color-background-secondary), white 1.5%) !important;
  padding: 0.5rem 0.6rem;
  margin: 1.2rem 0;
  color: color-mix(in srgb, var(--color-text), white 6%) !important;
}
blockquote strong {
  color: var(--color-plan-mode) !important;
}

/* kbd (for keybinds page) */
kbd {
  display: inline-block;
  padding: 0.15em 0.45em;
  font-family: var(--font-monospace);
  font-size: 0.9em;
  line-height: 1.2;
  color: color-mix(in srgb, var(--color-text), white 5%);
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 -1px 0 hsl(0 0% 0% / 0.25);
}

/* Details/Summary */
details {
  background: color-mix(in srgb, var(--color-background-secondary), white 1%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}
details > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
details > summary::-webkit-details-marker {
  display: none;
}
details > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.5rem;
  color: var(--color-text-secondary);
  transition: transform 0.2s ease;
}
details[open] > summary::before {
  transform: rotate(90deg);
}

/* Navigation buttons */
.nav-chapters {
  color: var(--color-text-secondary) !important;
}
.nav-chapters:hover {
  color: var(--color-text) !important;
  background: color-mix(in srgb, var(--color-background-secondary), white 2%) !important;
}

/* Selection */
::selection {
  background: hsl(from var(--color-plan-mode) h s l / 0.25);
  color: white;
}

/* Fix mermaid blocks background to blend in */
.mermaid {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

/* Images */
.content .chapter img {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}

/* Small utilities */
.hr-dim {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1.5rem 0;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* Add logo before menu title */
.menu-title::before {
  content: "";
  display: inline-block;
  width: 32px;
  height: 32px;
  margin-right: 8px;
  vertical-align: middle;
  background-image: url("../img/logo.webp");
  background-size: contain;
  background-repeat: no-repeat;
}
