/* ==========================================================================
   Local Falcon API Guides — Shared Stylesheet
   Design: "Stripe docs density" — clean, modern, tight
   Theme: Dark by default (matches Scalar deepSpace), light mode toggle
   ========================================================================== */

/* ---------- Custom Properties (Dark Mode Default) ---------- */
:root,
[data-theme="dark"] {
  --bg: #0f1117;
  --bg-surface: #1a1b23;
  --bg-surface-hover: #22232e;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --text-heading: #fafafa;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --code-bg: #1a1b23;
  --code-border: #27272a;
  --border: #27272a;
  --border-subtle: #1e1e24;
  --table-row-alt: rgba(255, 255, 255, 0.02);
  --table-header-bg: rgba(255, 255, 255, 0.05);
  --warning-bg: rgba(234, 179, 8, 0.08);
  --warning-border: #ca8a04;
  --warning-text: #fbbf24;
  --tip-bg: rgba(59, 130, 246, 0.08);
  --tip-border: #3b82f6;
  --tip-text: #93c5fd;
  --next-steps-bg: #1a1b23;
  --next-steps-border: #27272a;
  --nav-active-bg: rgba(59, 130, 246, 0.1);
  --nav-active-text: #60a5fa;
  --nav-hover-bg: rgba(255, 255, 255, 0.04);
  --copy-btn-bg: rgba(255, 255, 255, 0.08);
  --copy-btn-hover-bg: rgba(255, 255, 255, 0.14);
  --scrollbar-thumb: #3f3f46;
  --scrollbar-track: transparent;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-surface: #f4f4f5;
  --bg-surface-hover: #e4e4e7;
  --text: #18181b;
  --text-muted: #71717a;
  --text-heading: #09090b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --code-bg: #f4f4f5;
  --code-border: #e4e4e7;
  --border: #e4e4e7;
  --border-subtle: #f4f4f5;
  --table-row-alt: rgba(0, 0, 0, 0.02);
  --table-header-bg: rgba(0, 0, 0, 0.04);
  --warning-bg: rgba(234, 179, 8, 0.08);
  --warning-border: #ca8a04;
  --warning-text: #92400e;
  --tip-bg: rgba(59, 130, 246, 0.06);
  --tip-border: #2563eb;
  --tip-text: #1e40af;
  --next-steps-bg: #f8fafc;
  --next-steps-border: #e2e8f0;
  --nav-active-bg: rgba(37, 99, 235, 0.08);
  --nav-active-text: #2563eb;
  --nav-hover-bg: rgba(0, 0, 0, 0.03);
  --copy-btn-bg: rgba(0, 0, 0, 0.06);
  --copy-btn-hover-bg: rgba(0, 0, 0, 0.1);
  --scrollbar-thumb: #d4d4d8;
  --scrollbar-track: transparent;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* ---------- Layout ---------- */
.page-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar Navigation ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;
  overflow-y: auto;
  padding: 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: block;
  line-height: 0;
}

.sidebar-logo img {
  width: 160px;
  height: auto;
}

.sidebar-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.sidebar-back:hover {
  color: var(--accent);
}

.sidebar-back svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
  overflow-y: auto;
}

.sidebar-nav-label {
  padding: 0 20px;
  margin-bottom: 8px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar-nav ul {
  list-style: none;
}

.sidebar-nav a {
  display: block;
  padding: 6px 20px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: var(--nav-hover-bg);
}

.sidebar-nav a.active {
  color: var(--nav-active-text);
  background: var(--nav-active-bg);
  border-left-color: var(--accent);
  font-weight: 500;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* Theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--copy-btn-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  width: 100%;
  justify-content: center;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--copy-btn-hover-bg);
}

.theme-toggle svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Show sun in dark mode, moon in light mode */
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }

/* ---------- Main Content ---------- */
main {
  flex: 1;
  margin-left: 240px;
  min-width: 0;
}

main > article {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 32px 80px;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-heading);
  line-height: 1.3;
}

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 1.0625rem;
  color: var(--text-muted);
  margin-bottom: 32px;
  line-height: 1.6;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
}

h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

p {
  margin-bottom: 1rem;
}

/* ---------- Links ---------- */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ---------- Lists ---------- */
ul, ol {
  margin-bottom: 1rem;
  padding-left: 24px;
}

li {
  margin-bottom: 4px;
}

li > ul, li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

/* ---------- Inline Code ---------- */
code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
  padding: 2px 6px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
}

/* ---------- Code Blocks ---------- */
pre {
  position: relative;
  margin-bottom: 1rem;
  padding: 16px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

pre code {
  display: block;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

/* Copy button (positioned via CSS, inserted via JS) */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--copy-btn-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: var(--copy-btn-hover-bg);
  color: var(--text);
}

.code-copy-btn.copied {
  color: #22c55e;
}

.code-copy-btn svg {
  width: 16px;
  height: 16px;
}

/* Code block with label (language tag) */
pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  left: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  pointer-events: none;
}

pre[data-lang] code {
  padding-top: 20px;
}

/* ---------- Tables ---------- */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin-bottom: 1rem;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  line-height: 1.5;
}

thead th {
  text-align: left;
  font-weight: 600;
  padding: 8px 12px;
  background: var(--table-header-bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

tbody tr:hover {
  background: var(--nav-hover-bg);
}

/* ---------- Horizontal Rule ---------- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* ---------- Blockquote ---------- */
blockquote {
  margin: 0 0 1rem;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--tip-bg);
  color: var(--text);
  border-radius: 0 6px 6px 0;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* ---------- Next Steps Section ---------- */
.next-steps {
  margin-top: 48px;
  padding: 24px;
  background: var(--next-steps-bg);
  border: 1px solid var(--next-steps-border);
  border-radius: 8px;
}

.next-steps h2 {
  margin-top: 0;
  padding-bottom: 0;
  border-bottom: none;
  font-size: 1.25rem;
}

.next-steps ul {
  margin-bottom: 0;
}

.next-steps li {
  margin-bottom: 8px;
}

.next-steps li:last-child {
  margin-bottom: 0;
}

/* ---------- Utility: Fieldmask Recipe ---------- */
.fieldmask-recipe {
  position: relative;
  margin-bottom: 1rem;
}

.fieldmask-recipe-label {
  display: inline-block;
  padding: 4px 10px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}

.fieldmask-recipe pre {
  border-top-left-radius: 0;
  margin-bottom: 0;
}

/* ---------- Utility: Warning Box ---------- */
.warning-box {
  margin-bottom: 1rem;
  padding: 14px 16px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 6px;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.warning-box::before {
  content: "Warning";
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--warning-text);
  margin-bottom: 4px;
}

.warning-box p:last-child {
  margin-bottom: 0;
}

/* ---------- Utility: Tip Box ---------- */
.tip-box {
  margin-bottom: 1rem;
  padding: 14px 16px;
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  border-radius: 6px;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.tip-box::before {
  content: "Tip";
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tip-text);
  margin-bottom: 4px;
}

.tip-box p:last-child {
  margin-bottom: 0;
}

/* ---------- Utility: Step ---------- */
.step {
  counter-increment: step-counter;
  position: relative;
  padding-left: 48px;
  margin-bottom: 24px;
}

.step::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 2px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--nav-active-bg);
  border: 1px solid var(--accent);
  border-radius: 50%;
}

.steps {
  counter-reset: step-counter;
}

.step h3 {
  margin-top: 0;
}

/* ---------- Mobile Hamburger ---------- */
.nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.nav-toggle svg {
  width: 20px;
  height: 20px;
}

.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

/* ---------- Responsive: Mobile (<768px) ---------- */
@media (max-width: 767px) {
  .nav-toggle {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .nav-overlay.open {
    display: block;
  }

  main {
    margin-left: 0;
  }

  main > article {
    padding: 64px 16px 48px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
    margin-top: 32px;
  }

  h3 {
    font-size: 1.125rem;
    margin-top: 24px;
  }

  pre {
    font-size: 0.8125rem;
    padding: 12px;
    border-radius: 4px;
  }

  .step {
    padding-left: 40px;
  }

  .step::before {
    width: 28px;
    height: 28px;
    font-size: 0.8125rem;
  }
}

/* ---------- Print ---------- */
@media print {
  .sidebar,
  .nav-toggle,
  .nav-overlay,
  .theme-toggle,
  .code-copy-btn {
    display: none !important;
  }

  main {
    margin-left: 0;
  }

  main > article {
    max-width: 100%;
    padding: 0;
  }

  body {
    color: #000;
    background: #fff;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  pre, code {
    border: 1px solid #ccc;
    background: #f5f5f5;
  }
}
