/* Buvlor Ads SDK docs — styles.css v2
 * Implements docs/research/design_guide_v2.md (Vercel-aligned).
 * All values from Geist design system. Shared token set with sales page.
 */

/* ============================================================
   DESIGN TOKENS (shared with sales page)
   ============================================================ */
:root {
  /* ============ COLOR ============ */
  --color-bg: #FFFFFF;
  --color-bg-subtle: #FAFAFA;
  --color-bg-elevated: #FFFFFF;
  --color-bg-overlay: rgba(255, 255, 255, 0.72);
  --color-bg-dark: #0A0A0A;
  --color-bg-dark-elevated: #171717;

  --color-surface-1: #FAFAFA;
  --color-surface-2: #F2F2F2;
  --color-surface-3: #EBEBEB;

  --color-text-primary: #171717;
  --color-text-secondary: #666666;
  --color-text-tertiary: #8F8F8F;
  --color-text-quaternary: #A1A1A1;
  --color-text-emphasis: #0A0A0A;
  --color-text-on-dark: #EDEDED;
  --color-text-on-dark-secondary: #A1A1A1;
  --color-text-on-dark-tertiary: #7A7A7A;

  --color-border: #EBEBEB;
  --color-border-strong: #E0E0E0;
  --color-border-dark: #262626;

  --color-link: #0070F3;
  --color-link-hover: #0761D1;
  --color-link-soft: #E5F0FF;

  --color-success: #3CCB7F;
  --color-success-bg: #E6F9EE;
  --color-success-text: #1F8049;
  --color-warning: #F5A623;
  --color-warning-bg: #FFF4DC;
  --color-warning-text: #A56500;
  --color-error: #E5484D;
  --color-error-bg: #FFE5E5;
  --color-error-text: #B5363A;

  --code-keyword: #FF7B72;
  --code-string: #A5D6FF;
  --code-function: #D2A8FF;
  --code-comment: #7A7A7A;
  --code-number: #79C0FF;
  --code-default: #EDEDED;

  /* ============ TYPOGRAPHY ============ */
  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Pretendard',
               'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --font-mono: 'Geist Mono', 'SF Mono', Menlo, Consolas,
               'Liberation Mono', monospace;

  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 32px;
  --text-4xl: 48px;
  --text-5xl: 64px;

  --leading-tight: 1.05;
  --leading-snug: 1.2;
  --leading-base: 1.4;
  --leading-normal: 1.5;
  --leading-relaxed: 1.6;
  --leading-loose: 1.65;

  --tracking-tightest: -0.04em;
  --tracking-tighter: -0.03em;
  --tracking-tight: -0.025em;
  --tracking-snug: -0.02em;
  --tracking-base: -0.005em;
  --tracking-none: 0;
  --tracking-wide: 0.04em;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* ============ SPACING (4px grid) ============ */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;

  /* ============ LAYOUT ============ */
  --header-height: 64px;
  --sidebar-width: 256px;
  --toc-width: 220px;
  --content-max-width: 880px;
  --docs-total-max-width: 1400px;
  --sales-max-width: 1100px;

  /* ============ RADIUS ============ */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* ============ SHADOW ============ */
  --shadow-none: none;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);

  /* ============ TRANSITION ============ */
  --transition-fast: 100ms ease-out;
  --transition-base: 150ms ease-out;
  --transition-slow: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ============ Z-INDEX ============ */
  --z-base: 0;
  --z-sticky: 100;
  --z-header: 200;
  --z-drawer: 300;
  --z-modal: 400;
  --z-toast: 500;
}

/* Dark mode tokens — Phase 2 (toggle not implemented, tokens pre-defined) */
[data-theme="dark"] {
  --color-bg: #000000;
  --color-bg-subtle: #0A0A0A;
  --color-bg-elevated: #0A0A0A;
  --color-bg-overlay: rgba(0, 0, 0, 0.72);

  --color-surface-1: #0A0A0A;
  --color-surface-2: #171717;
  --color-surface-3: #262626;

  --color-text-primary: #EDEDED;
  --color-text-secondary: #A1A1A1;
  --color-text-tertiary: #7A7A7A;
  --color-text-quaternary: #5A5A5A;
  --color-text-emphasis: #FFFFFF;

  --color-border: #262626;
  --color-border-strong: #333333;

  --color-link: #3291FF;
  --color-link-hover: #52A8FF;
  --color-link-soft: #002B4A;

  --color-success-bg: #002F1A;
  --color-success-text: #5BCC8B;
  --color-warning-bg: #2F2200;
  --color-warning-text: #F5C56B;
  --color-error-bg: #2F0808;
  --color-error-text: #FF6669;
}

/* ============================================================
   RESET / BASE
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* Ensure [hidden] always wins — display: grid/flex on [data-cards] etc.
 * would otherwise override the UA stylesheet's [hidden] { display: none }
 * causing both EN and KO variants to render simultaneously. */
[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  letter-spacing: var(--tracking-base);
  color: var(--color-text-primary);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}
/* Vercel: no underline on body links — color alone is sufficient;
 * hover adds underline as WCAG supplement. */
a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

button { font-family: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-text-primary);
  color: #FFFFFF;
  padding: 8px var(--space-3);
  border-radius: var(--radius-sm);
  z-index: var(--z-toast);
  font-size: var(--text-sm);
}
.skip-link:focus { left: var(--space-3); top: var(--space-3); }

/* ============================================================
   HEADER — Vercel sticky backdrop-blur
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--color-bg-overlay);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--color-border);
}
.site-header-inner {
  max-width: var(--docs-total-max-width);
  margin: 0 auto;
  padding: 0 var(--space-6);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-primary);
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--color-text-primary); }

.brand-logo {
  display: inline-block;
  flex-shrink: 0;
  border-radius: 7px;
  overflow: hidden;
}
/* Footer logo mark — now an inline SVG; CSS only handles layout */
.brand-mark {
  display: inline-block;
  flex-shrink: 0;
}
.brand-mark-sm {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

.brand-name {
  font-size: 15px;
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  letter-spacing: var(--tracking-base);
}

/* Nav */
.site-nav { display: flex; align-items: center; gap: var(--space-4); }

.mobile-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.hamburger-bar {
  display: block;
  width: 16px;
  height: 1px;
  background: var(--color-text-primary);
  border-radius: 1px;
}

/* Lang segment */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  gap: 2px;
}
.lang-opt {
  padding: 3px 10px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border: 0;
  background: transparent;
  border-radius: var(--radius-full);
  color: var(--color-text-tertiary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.lang-opt:hover { color: var(--color-text-primary); }
.lang-opt[aria-current="true"] {
  background: var(--color-bg);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   LAYOUT — 2-column docs (content | TOC)
   SIDEBAR_ENABLED=false: sidebar column omitted. Set flag to true and change
   grid-template-columns back to include var(--sidebar-width) to re-enable.
   ============================================================ */
.layout {
  max-width: var(--docs-total-max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-width);
  align-items: start;
}

/* ============================================================
   SIDEBAR (left)
   ============================================================ */
.sidebar {
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  background: var(--color-bg-subtle);
  border-right: 1px solid var(--color-border);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.sidebar-inner {
  padding: var(--space-6) var(--space-4) var(--space-16) var(--space-6);
}

/* Group label — Vercel: sentence case, weight 500, NOT uppercase */
.sidebar-group-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
  margin-top: var(--space-6);
}
.sidebar-group:first-child .sidebar-group-label { margin-top: 0; }

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Nav item — Vercel: active = background surface-2 + weight 500, NO left bar */
.nav-link {
  display: block;
  padding: 6px var(--space-3);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  margin-left: calc(var(--space-3) * -1);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.nav-link:hover {
  color: var(--color-text-primary);
  background-color: var(--color-surface-2);
  text-decoration: none;
}
.nav-link.is-active {
  color: var(--color-text-primary);
  font-weight: var(--weight-medium);
  background-color: var(--color-surface-2);
}

/* ============================================================
   CONTENT (center)
   ============================================================ */
.content {
  padding: var(--space-12) var(--space-8) var(--space-24);
  min-width: 0;
  max-width: var(--content-max-width);
}

/* Docs hero (white bg, Vercel-style — no dark navy) */
.docs-hero {
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-12);
  border-bottom: 1px solid var(--color-border);
}
.docs-hero-title {
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-emphasis);
  margin-bottom: var(--space-3);
}
.docs-hero-sub {
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--color-text-secondary);
  max-width: 600px;
}

/* ============================================================
   DOC BODY TYPOGRAPHY
   ============================================================ */
.doc h1 {
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-emphasis);
  margin-bottom: var(--space-4);
  scroll-margin-top: calc(var(--header-height) + var(--space-5));
}
.doc h2 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  letter-spacing: var(--tracking-snug);
  color: var(--color-text-emphasis);
  margin-top: 56px;
  margin-bottom: var(--space-3);
  scroll-margin-top: calc(var(--header-height) + var(--space-5));
}
.doc h3 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-base);
  letter-spacing: -0.015em;
  color: var(--color-text-emphasis);
  margin-top: var(--space-8);
  margin-bottom: var(--space-2);
  scroll-margin-top: calc(var(--header-height) + var(--space-5));
}
.doc h4 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text-emphasis);
  margin-top: var(--space-6);
  margin-bottom: var(--space-1);
}

.doc p {
  margin-bottom: var(--space-4);
  color: var(--color-text-primary);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
}
.doc strong { font-weight: var(--weight-semibold); }
/* Links in doc content: no underline default, underline on hover (Vercel) */
.doc a { color: var(--color-link); text-decoration: none; }
.doc a:hover { color: var(--color-link-hover); text-decoration: underline; }

.doc ul, .doc ol {
  margin-bottom: var(--space-4);
  padding-left: var(--space-6);
}
.doc li {
  margin-bottom: var(--space-2);
  color: var(--color-text-primary);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
}

.doc hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: var(--space-10) 0;
}

/* Blockquote as callout (Note style) */
.doc blockquote {
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-5);
  border-left: 4px solid var(--color-link);
  background: var(--color-link-soft);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.doc blockquote p { margin-bottom: 0; font-size: var(--text-base); line-height: var(--leading-relaxed); }

/* ============================================================
   INLINE CODE
   ============================================================ */
/* 14px Geist Mono, #F2F2F2 bg, 2px 6px padding, radius 4px */
.doc :not(pre) > code {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  background: var(--color-surface-2);
  color: var(--color-text-primary);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}
/* Link containing inline code */
.doc a > code { color: var(--color-link); }

/* ============================================================
   CODE BLOCKS — Vercel dark (#0A0A0A)
   ============================================================ */
.code-block {
  margin: var(--space-4) 0 var(--space-6);
  border-radius: var(--radius-md);
  background: var(--color-bg-dark);
  border: 1px solid var(--color-border-dark);
  overflow: hidden;
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  height: 40px;
  background: var(--color-bg-dark-elevated);
  border-bottom: 1px solid var(--color-border-dark);
}
.code-block-lang {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-on-dark-secondary);
}
.code-block pre {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-loose);
  color: var(--code-default);
  -webkit-overflow-scrolling: touch;
}
.code-block code { font-family: inherit; }

/* Copy button — Vercel inline "Copy" → "Copied" pattern, NO toast */
.copy-btn {
  padding: 4px 10px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--color-text-on-dark-secondary);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.copy-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-on-dark);
}
/* After click: "Copied" in green, inline, no toast */
.copy-btn.is-copied { color: var(--color-success); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
  margin: var(--space-4) 0 var(--space-6);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}
/* Vercel: no thead background, just border-bottom 2px for separation */
.doc thead { border-bottom: 2px solid var(--color-border-strong); }
.doc th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}
.doc td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-base);
  vertical-align: top;
}
.doc tr:last-child td { border-bottom: none; }
.doc td code { white-space: nowrap; }

/* ============================================================
   TOC (right)
   ============================================================ */
.toc {
  position: sticky;
  top: calc(var(--header-height) + var(--space-8));
  align-self: start;
  max-height: calc(100vh - var(--header-height) - var(--space-16));
  overflow-y: auto;
  padding: var(--space-8) 0 var(--space-8) var(--space-6);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.toc-inner { }

.toc-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
  margin-bottom: var(--space-3);
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}
/* TOC item — Vercel: active = weight 500 + color primary, NO left bar */
.toc-link {
  display: block;
  padding: 4px 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  color: var(--color-text-secondary);
  transition: color var(--transition-fast);
}
.toc-link:hover {
  color: var(--color-text-primary);
  text-decoration: none;
}
.toc-link.is-active {
  color: var(--color-text-primary);
  font-weight: var(--weight-medium);
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
}
.site-footer-inner {
  max-width: var(--docs-total-max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}
.site-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}
.site-footer-links {
  display: flex;
  gap: var(--space-6);
  margin-left: auto;
}
.footer-link {
  color: var(--color-text-secondary);
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: color var(--transition-fast);
}
.footer-link:hover { color: var(--color-text-primary); text-decoration: none; }

/* ============================================================
   SIDEBAR BACKDROP (mobile drawer)
   ============================================================ */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: calc(var(--z-drawer) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.sidebar-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   KOREAN LANGUAGE TWEAKS
   ============================================================ */
html[data-lang="ko"] .docs-hero-title { letter-spacing: -0.03em; }

/* ============================================================
   RESPONSIVE — BREAKPOINTS
   ============================================================ */

/* ≥ 1280px: 2-column full (content | TOC) */

/* 1024–1279px: content only (TOC hidden) */
@media (max-width: 1279px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .toc { display: none; }
}

/* 768–1023px: single column, full-width content */
@media (max-width: 1023px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .content {
    padding: var(--space-10) var(--space-6) var(--space-20);
    max-width: 100%;
  }
}

/* < 768px: mobile */
@media (max-width: 767px) {
  .site-header-inner { padding: 0 var(--space-4); }
  .content {
    padding: var(--space-8) var(--space-4) var(--space-16);
  }
  .docs-hero-title { font-size: 28px; }
  .doc h1 { font-size: 28px; }
  .doc h2 { font-size: var(--text-xl); margin-top: var(--space-10); }
  .doc h3 { font-size: var(--text-md); }
  .code-block pre { font-size: var(--text-xs); padding: var(--space-3) var(--space-4); }
  .brand-name { font-size: var(--text-sm); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
