/*
 * Chatleadr documentation.
 *
 * The palette is taken from Dashboard/tailwind.config.js rather than reinvented,
 * so the docs and the product look like the same company. Three families, and
 * each has one job:
 *
 *   ink      flat greys, near-zero chroma. Everything structural.
 *   brand    the purple ramp. Every interactive thing, and nothing else.
 *   accent   the lime. Used ONLY as a mark on dark grounds -- #d9e94a on white
 *            is roughly 1.6:1, so it can never carry text there.
 *
 * Both themes are built from the same tokens: only the token values change under
 * the media query and the data-theme overrides, never the component rules.
 */

:root {
  --ground: #ffffff;
  --surface: #fafafa;
  --surface-2: #f4f4f5;
  --rule: #e7e7e8;
  --rule-strong: #d4d4d6;

  --text: #2e2e30;
  --text-strong: #1c1c1e;
  --text-muted: #5b5b5e;
  --text-faint: #78787b;

  --link: #7042cc;
  --link-hover: #5a34ae;
  --mark: #7042cc;

  --code-bg: #f4f4f5;
  --code-text: #44379d;

  --topbar: #1e2430;
  --topbar-text: #f4f4f5;
  --topbar-muted: #a6a6a9;
  --accent: #d9e94a;

  --note: #f6f1ff;
  --note-rule: #dbbfff;
  --warn: #fdf8ed;
  --warn-rule: #f2d89b;
  --danger: #fdf2f2;
  --danger-rule: #f5c2c2;

  --radius: 10px;
  --sidebar-w: 17rem;
  --toc-w: 14rem;
  --topbar-h: 3.5rem;
  --measure: 68ch;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #131726;
    --surface: #1a1f2e;
    --surface-2: #212739;
    --rule: #2c3346;
    --rule-strong: #3a4257;

    --text: #e4e5e9;
    --text-strong: #ffffff;
    --text-muted: #a3a8b8;
    --text-faint: #838899;

    --link: #c4a0fa;
    --link-hover: #dbbfff;
    --mark: #d9e94a;

    --code-bg: #212739;
    --code-text: #dbbfff;

    --topbar: #0e1220;
    --topbar-text: #f4f4f5;
    --topbar-muted: #a3a8b8;

    --note: #1d1b30;
    --note-rule: #44379d;
    --warn: #2a2213;
    --warn-rule: #8e4c17;
    --danger: #2c1a1a;
    --danger-rule: #8a3232;
  }
}

/* The toggle must beat the media query in BOTH directions, so each theme is
   restated in full rather than relying on the cascade. */
:root[data-theme="light"] {
  --ground: #ffffff; --surface: #fafafa; --surface-2: #f4f4f5;
  --rule: #e7e7e8; --rule-strong: #d4d4d6;
  --text: #2e2e30; --text-strong: #1c1c1e; --text-muted: #5b5b5e; --text-faint: #78787b;
  --link: #7042cc; --link-hover: #5a34ae; --mark: #7042cc;
  --code-bg: #f4f4f5; --code-text: #44379d;
  --topbar: #1e2430; --topbar-text: #f4f4f5; --topbar-muted: #a6a6a9;
  --note: #f6f1ff; --note-rule: #dbbfff; --warn: #fdf8ed; --warn-rule: #f2d89b;
  --danger: #fdf2f2; --danger-rule: #f5c2c2;
}

:root[data-theme="dark"] {
  --ground: #131726; --surface: #1a1f2e; --surface-2: #212739;
  --rule: #2c3346; --rule-strong: #3a4257;
  --text: #e4e5e9; --text-strong: #ffffff; --text-muted: #a3a8b8; --text-faint: #838899;
  --link: #c4a0fa; --link-hover: #dbbfff; --mark: #d9e94a;
  --code-bg: #212739; --code-text: #dbbfff;
  --topbar: #0e1220; --topbar-text: #f4f4f5; --topbar-muted: #a3a8b8;
  --note: #1d1b30; --note-rule: #44379d; --warn: #2a2213; --warn-rule: #8e4c17;
  --danger: #2c1a1a; --danger-rule: #8a3232;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 1rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent); text-underline-offset: 2px; }
a:hover { color: var(--link-hover); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 3px; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--ground); padding: 0.75rem 1rem; border: 1px solid var(--rule);
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  background: var(--topbar);
  color: var(--topbar-text);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.topbar-inner {
  height: 100%; margin: 0 auto; max-width: 90rem;
  padding: 0 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}

.brand { display: flex; align-items: center; gap: 0.6rem; color: inherit; text-decoration: none; font-weight: 700; }
.brand-mark {
  width: 1.4rem; height: 1.4rem; border-radius: 6px;
  background: linear-gradient(140deg, var(--accent), #dbbfff);
  flex: none;
}
.brand-name { letter-spacing: -0.02em; }
.brand-sub {
  margin-left: 0.4rem; font-weight: 500; font-size: 0.8rem;
  color: var(--accent); letter-spacing: 0.06em; text-transform: uppercase;
}

.areas { display: flex; gap: 1.25rem; margin-right: auto; font-size: 0.9rem; }
.areas a { color: var(--topbar-muted); text-decoration: none; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.areas a:hover { color: var(--topbar-text); }
.areas a.current { color: var(--topbar-text); border-bottom-color: var(--accent); }

.topbar-actions { display: flex; align-items: center; gap: 0.6rem; }

.icon-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.18);
  color: var(--topbar-text); border-radius: 8px;
  width: 2rem; height: 2rem; line-height: 1; cursor: pointer; font-size: 0.95rem;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); }
.nav-btn { display: none; }

.cta {
  background: var(--accent); color: #1e2430; text-decoration: none;
  font-weight: 700; font-size: 0.85rem;
  padding: 0.42rem 0.85rem; border-radius: 8px; white-space: nowrap;
}
.cta:hover { background: #eaf37f; color: #1e2430; }

:root[data-theme="dark"] .only-dark, .only-light { display: inline; }
:root[data-theme="dark"] .only-light, .only-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .only-light { display: none; }
  :root:not([data-theme]) .only-dark { display: inline; }
}

/* ------------------------------------------------------------------- shell */

.shell {
  margin: 0 auto; max-width: 90rem; padding: 0 1.25rem;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 2.5rem; align-items: start;
}

.sidebar {
  position: sticky; top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 2rem 0.5rem 3rem 0;
  font-size: 0.9rem;
}

.nav-section + .nav-section { margin-top: 1.6rem; }
.nav-title {
  margin: 0 0 0.5rem; font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-faint);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.sidebar li a {
  display: block; padding: 0.28rem 0.7rem; margin-left: -0.7rem;
  color: var(--text-muted); text-decoration: none; border-radius: 6px;
  border-left: 2px solid transparent;
}
.sidebar li a:hover { color: var(--text-strong); background: var(--surface-2); }
.sidebar li a.current {
  color: var(--link); font-weight: 600;
  border-left-color: var(--link); background: var(--surface-2);
}

main {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: 3rem; padding: 2rem 0 5rem; align-items: start;
}

/* -------------------------------------------------------------------- prose */

.prose { min-width: 0; max-width: var(--measure); }

.page-head { margin-bottom: 2rem; }

.kind { display: flex; align-items: baseline; gap: 0.6rem; margin: 0 0 0.75rem; }
.kind-label {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--link); border: 1px solid color-mix(in srgb, var(--link) 35%, transparent);
  padding: 0.12rem 0.5rem; border-radius: 999px;
}
.kind-hint { font-size: 0.8rem; color: var(--text-faint); }

.prose h1 {
  margin: 0 0 0.6rem; font-size: clamp(2rem, 1.4rem + 2vw, 2.6rem);
  line-height: 1.15; letter-spacing: -0.025em; color: var(--text-strong);
  text-wrap: balance;
}
.lede { margin: 0; font-size: 1.12rem; line-height: 1.6; color: var(--text-muted); text-wrap: pretty; }

.prose h2 {
  margin: 3rem 0 1rem; padding-top: 1.5rem; border-top: 1px solid var(--rule);
  font-size: 1.45rem; letter-spacing: -0.02em; color: var(--text-strong); text-wrap: balance;
}
.prose h3 { margin: 2.2rem 0 0.6rem; font-size: 1.1rem; color: var(--text-strong); text-wrap: balance; }
.prose h4 { margin: 1.8rem 0 0.5rem; font-size: 0.95rem; color: var(--text-strong); }

.prose p { margin: 0 0 1.1rem; text-wrap: pretty; }
.prose ul, .prose ol { margin: 0 0 1.2rem; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 0.4rem; }
.prose li { padding-left: 0.2rem; }
.prose li::marker { color: var(--text-faint); }

.prose strong { color: var(--text-strong); font-weight: 650; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

.anchor {
  margin-left: 0.4rem; color: var(--text-faint); text-decoration: none;
  opacity: 0; font-weight: 400;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

/* --------------------------------------------------------------------- code */

code {
  font-family: var(--mono); font-size: 0.875em;
  background: var(--code-bg); color: var(--code-text);
  padding: 0.12em 0.36em; border-radius: 4px;
  overflow-wrap: break-word;
}

.code-block {
  position: relative; margin: 0 0 1.4rem;
  background: var(--surface-2); border: 1px solid var(--rule);
  border-radius: var(--radius); overflow: hidden;
}
.code-lang {
  position: absolute; top: 0; right: 0;
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint); padding: 0.4rem 0.7rem;
}
.code-block pre { margin: 0; padding: 1rem 1.1rem; overflow-x: auto; }
.code-block code {
  background: none; color: var(--text); padding: 0;
  font-size: 0.855rem; line-height: 1.65; white-space: pre;
}

/* ------------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; margin: 0 0 1.5rem; border: 1px solid var(--rule); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { background: var(--surface-2); font-size: 0.75rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

/* ----------------------------------------------------------------- callouts */

.callout {
  margin: 0 0 1.4rem; padding: 1rem 1.1rem;
  border: 1px solid var(--rule); border-left-width: 3px;
  border-radius: var(--radius); background: var(--surface);
}
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-weight: 700; color: var(--text-strong); margin: 0 0 0.4rem; }
.callout-note, .callout-tip { background: var(--note); border-left-color: var(--note-rule); }
.callout-warning { background: var(--warn); border-left-color: var(--warn-rule); }
.callout-danger { background: var(--danger); border-left-color: var(--danger-rule); }

blockquote {
  margin: 0 0 1.4rem; padding-left: 1.1rem;
  border-left: 3px solid var(--rule-strong); color: var(--text-muted);
}
blockquote > :last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------------- toc */

.toc { position: sticky; top: calc(var(--topbar-h) + 2rem); font-size: 0.82rem; }
.toc-title {
  margin: 0 0 0.6rem; font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-faint);
}
.toc ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.15rem;
  border-left: 1px solid var(--rule); }
.toc a { display: block; padding: 0.2rem 0 0.2rem 0.8rem; margin-left: -1px;
  color: var(--text-muted); text-decoration: none; border-left: 1px solid transparent; }
.toc a:hover { color: var(--text-strong); }
.toc a.current { color: var(--link); border-left-color: var(--link); }
.toc-h3 a { padding-left: 1.6rem; font-size: 0.95em; }

/* -------------------------------------------------------------------- pager */

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 4rem; }
.pager a {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.9rem 1.1rem; border: 1px solid var(--rule); border-radius: var(--radius);
  text-decoration: none; color: var(--text-strong); font-weight: 600;
}
.pager a:hover { border-color: var(--link); }
.pager a span { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.pager-next { text-align: right; }

/* --------------------------------------------------------------- index grid */

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; margin: 0 0 2rem; }
.card {
  display: block; padding: 1.1rem 1.2rem; text-decoration: none;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface);
}
.card:hover { border-color: var(--link); }
.card h3 { margin: 0 0 0.3rem; font-size: 1rem; color: var(--text-strong); }
.card p { margin: 0; font-size: 0.88rem; color: var(--text-muted); line-height: 1.5; }

/* ------------------------------------------------------------------- footer */

.foot { border-top: 1px solid var(--rule); background: var(--surface); }
.foot-inner {
  max-width: 90rem; margin: 0 auto; padding: 2rem 1.25rem;
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between;
  font-size: 0.85rem; color: var(--text-muted);
}
.foot p { margin: 0; }
.foot-links { display: flex; gap: 1.25rem; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 900px) {
  .nav-btn { display: block; }
  .areas { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .sidebar {
    display: none; position: static; max-height: none;
    padding: 1.25rem 0; border-bottom: 1px solid var(--rule);
  }
  body.nav-open .sidebar { display: block; }
  .pager { grid-template-columns: 1fr; }
}
