/*
 * apps/docs/public/styles.css
 * ---------------------------
 * Layer that sits on top of Vocs' generated CSS to match the warm-paper
 * aesthetic used by apps/web/src/pages/Home (the public landing). Vocs
 * `theme.variables.color` already handles the base palette; this file
 * covers the things vocs tokens cannot reach:
 *   - Web fonts (Inter for UI, Instrument Serif for headline accents,
 *     JetBrains Mono for code).
 *   - Body backdrop subtle grid / vignette so docs feel like the landing.
 *   - Scrollbar, focus ring, and a few component-level polish bits.
 *   - Scalar API-reference iframe gets the same warm tokens via the
 *     `data-scalar-theme` selector hooks `api-reference-client.tsx`
 *     applies at runtime.
 */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@400;500;600&display=swap");

:root {
  --dub-bg: #efe6d8;
  --dub-paper: #f7f0e3;
  --dub-ink: #1a130e;
  --dub-mute: #8a7c6a;
  --dub-line: rgba(26, 19, 14, 0.12);
  --dub-accent: #d97757;
  --dub-accent-soft: rgba(217, 119, 87, 0.14);
}

html.dark {
  --dub-bg: #0a0705;
  --dub-paper: #110d09;
  --dub-ink: #f3ebde;
  --dub-mute: #8a7c6a;
  --dub-line: rgba(243, 235, 222, 0.1);
  --dub-accent: #e58866;
  --dub-accent-soft: rgba(229, 136, 102, 0.16);
}

html,
body {
  background: var(--dub-bg);
  color: var(--dub-ink);
  font-feature-settings: "ss01", "cv11", "calt";
}

/* Subtle backdrop dot grid to echo the landing surface. Anchored to the
 * documentElement so Vocs' surface layers paint over it cleanly. */
html::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(
    circle at 1px 1px,
    var(--dub-line) 1px,
    transparent 0
  );
  background-size: 28px 28px;
  opacity: 0.5;
}

html.dark::before {
  opacity: 0.4;
}

/* Headline serif accent — drops in when an mdx body uses <em> inside an h1
 * (mirroring the "agents" italic emphasis on the landing). Vocs renders h1
 * as the page title automatically; this just gives it the same character. */
h1 em,
h2 em {
  font-family: "Instrument Serif", "Times New Roman", serif;
  font-style: italic;
  font-weight: 400;
  color: var(--dub-accent);
  letter-spacing: -0.01em;
}

/* Code blocks pick up JetBrains Mono via vocs fontFamily.mono, but inline
 * code in mdx still benefits from a soft warm-paper background. */
:not(pre) > code {
  background: var(--dub-accent-soft) !important;
  color: var(--dub-ink) !important;
  border: 1px solid var(--dub-line);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.92em;
}

/* Sidebar polish: emphasize current page with the warm accent rather than
 * the default flat blue. */
[data-active="true"],
[aria-current="page"] {
  color: var(--dub-accent) !important;
}

/* Custom scrollbar to match warm-paper, dialed back so it doesn't fight
 * with content. WebKit only — Firefox falls back to OS defaults. */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--dub-line);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--dub-accent-soft);
}

/* Focus rings — accessible + on-palette. */
:focus-visible {
  outline: 2px solid var(--dub-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ──────────────────────────────────────────────────────────────────
 * API Reference page (`pages/api-reference.tsx` + zh equivalent)
 *
 * The Scalar ApiReferenceReact component renders its own sidebar +
 * header + content layout. Stacking it inside the regular Vocs docs
 * frame produces two competing sidebars and wastes horizontal room.
 * We give the api-reference page a fixed full-bleed layer so Scalar
 * has the entire viewport to itself, then add a thin custom topbar
 * with a way back into the docs.
 * ─────────────────────────────────────────────────────────────────── */

.dub-docs-api-reference {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  background: var(--dub-bg);
  color: var(--dub-ink);
}

.dub-docs-api-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--dub-line);
  background: var(--dub-paper);
  font-size: 13px;
  flex-shrink: 0;
}

.dub-docs-api-header a {
  color: var(--dub-accent);
  text-decoration: none;
  font-weight: 500;
}

.dub-docs-api-header a:hover {
  color: var(--dub-ink);
}

/* Brand mark in the api-reference custom header. The full-bleed
 * layout bypasses Vocs' sidebar (where the configured logoUrl lives),
 * so we mount the same image here directly. Two variants swapped
 * by html.dark so the wordmark stays readable in both palettes. */
.dub-docs-api-header__brand {
  display: inline-flex;
  align-items: center;
  height: 28px;
  flex-shrink: 0;
}

.dub-docs-api-header__logo {
  height: 22px;
  width: auto;
  display: block;
}

.dub-docs-api-header__logo--dark {
  display: none;
}

html.dark .dub-docs-api-header__logo--light {
  display: none;
}

html.dark .dub-docs-api-header__logo--dark {
  display: block;
}

.dub-docs-api-header__crumb {
  color: var(--dub-mute);
}

.dub-docs-api-header__crumb::before {
  content: "/";
  margin-right: 14px;
  color: var(--dub-line);
}

.dub-docs-api-header__title {
  font-family: "Instrument Serif", "Times New Roman", serif;
  font-style: italic;
  font-size: 18px;
  color: var(--dub-ink);
}

.dub-docs-api-header__spacer {
  flex: 1;
}

.dub-docs-api-header__lang {
  color: var(--dub-mute);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dub-docs-api-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.dub-docs-api-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dub-mute);
  font-size: 13px;
}

.dub-docs-api-loading::after {
  content: "Loading API reference…";
}

/* Each api-reference page sets `lang` on the .dub-docs-api-reference
 * wrapper (Vocs leaves <html lang="en"> alone across routes). Match on
 * that wrapper so the loading text follows the page's locale. */
.dub-docs-api-reference[lang="zh"] .dub-docs-api-loading::after {
  content: "加载 API 参考…";
}
.dub-docs-api-reference[lang="zh-TW"] .dub-docs-api-loading::after {
  content: "載入 API 參考…";
}
.dub-docs-api-reference[lang="ja"] .dub-docs-api-loading::after {
  content: "API リファレンスを読み込み中…";
}

/* Scalar reskinning: Scalar exposes `--scalar-*` CSS vars on the rendered
 * tree. We override the key ones with our warm-paper tokens so the embedded
 * playground sits inside the docs surface seamlessly. */
.dub-docs-api-reference {
  --scalar-background-1: var(--dub-bg);
  --scalar-background-2: var(--dub-paper);
  --scalar-background-3: var(--dub-paper);
  --scalar-color-1: var(--dub-ink);
  --scalar-color-2: var(--dub-mute);
  --scalar-color-3: var(--dub-mute);
  --scalar-color-accent: var(--dub-accent);
  --scalar-color-green: #4f8a4f;
  --scalar-color-red: #c0573b;
  --scalar-border-color: var(--dub-line);
  --scalar-font: Inter, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --scalar-font-code:
    "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;
}

.dub-docs-api-reference [class*="scalar"] code,
.dub-docs-api-reference [class*="scalar"] pre {
  font-family: "JetBrains Mono", ui-monospace, monospace !important;
}

/* ──────────────────────────────────────────────────────────────────
 * API Reference header — language + theme controls
 *
 * Mirrors the apps/web ChromeControls widget: a Globe icon with a
 * 4-locale dropdown, sitting next to a sun/moon theme toggle. Vocs
 * hides its own controls on the api-reference full-bleed surface,
 * so this is the only way the user reaches dark mode / a switch.
 * ─────────────────────────────────────────────────────────────── */

.dub-docs-api-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dub-docs-api-lang {
  position: relative;
  display: inline-flex;
}

.dub-docs-api-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 24px;
  width: 24px;
  padding: 0;
  border: 1px solid var(--dub-line);
  border-radius: 6px;
  background: transparent;
  color: var(--dub-ink);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.dub-docs-api-control:hover {
  color: var(--dub-accent);
  border-color: var(--dub-accent);
  background: var(--dub-accent-soft);
}

.dub-docs-api-control--wide {
  width: auto;
  padding: 0 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.dub-docs-api-control[aria-expanded="true"] {
  color: var(--dub-accent);
  border-color: var(--dub-accent);
  background: var(--dub-accent-soft);
}

.dub-docs-api-lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 156px;
  padding: 4px;
  border: 1px solid var(--dub-line);
  border-radius: 10px;
  background: var(--dub-paper);
  box-shadow: 0 8px 28px -10px rgba(26, 19, 14, 0.2);
  /* Scalar's playground uses z-tooltip = 99999 for some of its
   * floating UI. The dropdown lives in the same stacking context
   * (our fixed api-reference container) so we have to outrank it. */
  z-index: 100001;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: dub-docs-lang-in 140ms cubic-bezier(0.16, 1, 0.3, 1);
}

html.dark .dub-docs-api-lang-menu {
  box-shadow: 0 8px 28px -8px rgba(0, 0, 0, 0.6);
}

@keyframes dub-docs-lang-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dub-docs-api-lang-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 10px;
  border: 0;
  background: transparent;
  border-radius: 6px;
  color: var(--dub-ink);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition:
    background 120ms ease,
    color 120ms ease;
}

.dub-docs-api-lang-item:hover,
.dub-docs-api-lang-item:focus-visible {
  background: var(--dub-accent-soft);
  color: var(--dub-accent);
  outline: 0;
}

.dub-docs-api-lang-item[aria-checked="true"] {
  color: var(--dub-accent);
  font-weight: 600;
}

/* ──────────────────────────────────────────────────────────────────
 * Scalar sidebar palette — give it a tiny bit of contrast against the
 * main content area, otherwise the warm cream blends into itself and
 * the sidebar items look like they're floating. We push Scalar's
 * background-2 (sidebar) onto our `backgroundDark` cream so the
 * sidebar/main split has visible structure. Method badges stay on
 * Scalar's stock greens / oranges — those are semantically meaningful
 * (HTTP method colour) and overriding them would just confuse readers
 * who already know GET=green/blue, POST=orange, DELETE=red.
 * ─────────────────────────────────────────────────────────────── */

.dub-docs-api-reference {
  --scalar-background-2: #e6d8c2; /* sidebar bg — deeper cream */
  --scalar-color-1: var(--dub-ink); /* primary text */
  --scalar-color-2: #3a2c20; /* secondary text */
  --scalar-color-3: #6a5b48; /* tertiary / muted */
  --scalar-sidebar-background-1: #e6d8c2;
  --scalar-sidebar-item-active-background: var(--dub-accent-soft);
  --scalar-sidebar-color-active: var(--dub-accent);
  --scalar-sidebar-border-color: var(--dub-line);
}

html.dark .dub-docs-api-reference {
  --scalar-background-2: #050201;
  --scalar-color-1: var(--dub-ink);
  --scalar-color-2: #d4c8b4;
  --scalar-color-3: #a89880;
  --scalar-sidebar-background-1: #050201;
  --scalar-sidebar-item-active-background: rgba(229, 136, 102, 0.16);
  --scalar-sidebar-color-active: var(--dub-accent);
  --scalar-sidebar-border-color: var(--dub-line);
}

/* ──────────────────────────────────────────────────────────────────
 * Sidebar-extras (injected by /sidebar-extras.js)
 *
 * Sits at the very bottom of Vocs' left sidebar, sibling of the GitHub
 * socials icon. Matches the Vocs sidebar's compact tone so it doesn't
 * look bolted-on.
 * ─────────────────────────────────────────────────────────────── */

.dub-sidebar-extras {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 11px;
}

.dub-sidebar-extras__theme,
.dub-sidebar-extras__lang {
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid var(--dub-line);
  border-radius: 6px;
  background: transparent;
  color: var(--dub-ink);
  cursor: pointer;
  transition:
    color 120ms,
    border-color 120ms,
    background 120ms;
}

.dub-sidebar-extras__theme {
  width: 26px;
  padding: 0;
}

.dub-sidebar-extras__lang {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.dub-sidebar-extras__theme:hover,
.dub-sidebar-extras__lang:hover,
.dub-sidebar-extras__lang[aria-expanded="true"] {
  color: var(--dub-accent);
  border-color: var(--dub-accent);
  background: var(--dub-accent-soft);
}

.dub-sidebar-extras__lang-wrapper {
  position: relative;
}

.dub-sidebar-extras__menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 148px;
  padding: 4px;
  border: 1px solid var(--dub-line);
  border-radius: 10px;
  background: var(--dub-paper);
  box-shadow: 0 8px 28px -10px rgba(26, 19, 14, 0.2);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

html.dark .dub-sidebar-extras__menu {
  box-shadow: 0 8px 28px -8px rgba(0, 0, 0, 0.6);
}

.dub-sidebar-extras__menu[hidden] {
  display: none;
}

.dub-sidebar-extras__menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  border-radius: 6px;
  color: var(--dub-ink);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition:
    background 120ms,
    color 120ms;
}

.dub-sidebar-extras__menu-item:hover,
.dub-sidebar-extras__menu-item:focus-visible {
  background: var(--dub-accent-soft);
  color: var(--dub-accent);
  outline: 0;
}

.dub-sidebar-extras__menu-item[aria-checked="true"] {
  color: var(--dub-accent);
  font-weight: 600;
}

.dub-sidebar-extras__menu-check {
  display: inline-flex;
  align-items: center;
  width: 12px;
}
