/* Smooth scrolling for anchor links */
html {
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  scroll-padding-top: 5rem;
}

/* Sticky footer: push footer to bottom on short pages */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Reserve space for dynamically injected nav/footer to prevent layout shift */
#nav-placeholder {
  min-height: 64px;
}
#footer-placeholder {
  min-height: 480px;
}
@media (min-width: 640px) {
  #footer-placeholder {
    min-height: 295px;
  }
}

/* Prevent flash of unstyled Alpine components */
[x-cloak] {
  display: none !important;
}

/* Custom scrollbar (Webkit) */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background-color: #d1d5db;
  border-radius: 4px;
}
.dark ::-webkit-scrollbar-thumb {
  background-color: #374151;
}

/* Table of Contents */
.toc {
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 0;
}
.dark .toc {
  border-color: #334155;
}
.toc details {
  padding: 0;
}
.toc summary.toc-toggle {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.75rem 1.25rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #1e293b;
  user-select: none;
}
.dark .toc summary.toc-toggle {
  color: #e2e8f0;
}
.toc summary.toc-toggle::-webkit-details-marker {
  display: none;
}
.toc summary.toc-toggle::before {
  content: '';
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.toc details[open] > summary.toc-toggle::before {
  transform: rotate(45deg);
}
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0 1.25rem 0.75rem 1.75rem;
  counter-reset: toc-h2;
}
.toc-list > li {
  counter-increment: toc-h2;
}
.toc-list > li > a::before {
  content: counter(toc-h2) ". ";
  color: #94a3b8;
}
.toc-list a {
  display: block;
  padding: 0.25rem 0;
  font-size: 0.875rem;
  color: #475569;
  text-decoration: none;
  transition: color 0.15s;
}
.dark .toc-list a {
  color: #94a3b8;
}
.toc-list a:hover {
  color: #2563eb;
}
.dark .toc-list a:hover {
  color: #60a5fa;
}
.toc-list ol {
  list-style: none;
  padding-left: 1.25rem;
  margin: 0;
}
.toc-list ol a {
  font-size: 0.8125rem;
}

/* Desktop sidebar TOC layout */
.toc-layout {
  position: relative;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
}
.toc-sidebar-column {
  display: none;
}
.toc-sidebar {
  display: none;
}

@media (min-width: 1900px) {
  .toc-sidebar-column {
    display: block;
    position: absolute;
    right: calc(100% + 2rem);
    top: 0;
    bottom: 0;
    width: 16rem;
  }
  .toc-inline {
    display: none;
  }
  .toc-sidebar {
    display: block;
    position: sticky;
    top: 5rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    border: none;
    border-radius: 0;
    padding: 0 1.5rem 0 0;
    border-right: 1px solid #e2e8f0;
  }
  .dark .toc-sidebar {
    border-right-color: #334155;
  }
  .toc-sidebar .toc-list {
    padding: 0 0 0 0;
  }
  .toc-sidebar-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin: 0 0 0.75rem 0;
  }
  .toc-sidebar-title {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin: 0;
    padding: 0;
  }
  .toc-expand-all {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.15s;
    white-space: nowrap;
  }
  .toc-expand-all:hover {
    color: #2563eb;
  }
  .dark .toc-expand-all:hover {
    color: #60a5fa;
  }
  .toc-sidebar .toc-list > li > a::before {
    content: none;
  }
  .toc-sidebar .toc-list a {
    font-size: 0.875rem;
    padding: 0.2rem 0;
  }
  .toc-sidebar .toc-list ol {
    overflow: hidden;
    max-height: 50em;
    transition: max-height 0.3s ease;
  }
  .toc-sidebar .toc-list ol.toc-collapsed {
    max-height: 0;
  }
  .toc-section-toggle {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    padding: 0.2rem 0;
    font-size: 0.875rem;
    color: #475569;
    text-decoration: none;
    cursor: pointer;
    text-align: left;
    transition: color 0.15s;
  }
  .dark .toc-section-toggle {
    color: #94a3b8;
  }
  .toc-section-toggle:hover {
    color: #2563eb;
  }
  .dark .toc-section-toggle:hover {
    color: #60a5fa;
  }
  .toc-chevron {
    flex-shrink: 0;
    display: inline-block;
    width: 0.4em;
    height: 0.4em;
    margin-top: 0.45em;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.2s;
    margin-left: 0.5em;
  }
  .toc-expanded .toc-chevron {
    transform: rotate(45deg);
  }
}

/* Blog post hero banner */
.blog-hero {
  border-radius: 1rem;
  padding: 3rem 2rem;
  text-align: center;
  margin-bottom: 2rem;
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 50%, #94a3b8 100%);
}
.dark .blog-hero {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

/* Blog card hero thumbnail (overrides .blog-hero defaults for card context) */
.blog-hero-card {
  border-radius: 0;
  margin-bottom: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.blog-hero-card img {
  max-width: calc(100% - 2rem);
  max-height: 60px;
  width: auto;
  height: auto;
  object-fit: contain;
}
@media (min-width: 640px) {
  .blog-hero-card img {
    max-height: 100px;
  }
}

/* Make tables horizontally scrollable on mobile */
.prose .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prose .table-wrap table {
  display: table;
  min-width: 100%;
}
.prose table {
  font-size: 0.8rem;
}

/* Inline code styling for blog prose */
.prose :not(pre) > code {
  background-color: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  padding: 0.125rem 0.375rem;
  font-weight: 500;
}
.prose :not(pre) > code::before,
.prose :not(pre) > code::after {
  content: none;
}
.dark .prose :not(pre) > code {
  background-color: #1e293b;
  border-color: #334155;
}

/* Mermaid diagrams: reset code block styling */
pre.mermaid {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  display: flex;
  justify-content: center;
}
pre.mermaid .code-copy-btn {
  display: none;
}

/* Code block text color for light mode */
.prose pre code {
  color: #1e293b;
}
.dark .prose pre code {
  color: #e2e8f0;
}

/* Code block copy button */
.code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.375rem;
  border-radius: 0.375rem;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.5s;
}
pre:hover .code-copy-btn,
.code-copy-btn:focus-visible {
  opacity: 1;
}
.code-copy-btn:hover {
  background: #e2e8f0;
  color: #334155;
}
.dark .code-copy-btn {
  border-color: #374151;
  background: #1f2937;
  color: #9ca3af;
}
.dark .code-copy-btn:hover {
  background: #374151;
  color: #e5e7eb;
}

/* Allow tooltip to overflow above code blocks */
.prose pre {
  overflow: visible;
}
.prose pre code {
  overflow-x: auto;
  display: block;
}

/* Code copy "Copied!" tooltip */
.code-copy-tooltip {
  position: absolute;
  top: -2rem;
  right: 0;
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  background: #f1f5f9;
  color: #64748b;
  animation: copy-fade 1.5s ease-out forwards;
}
.dark .code-copy-tooltip {
  background: #1e293b;
  color: #94a3af;
}
@keyframes copy-fade {
  0%, 33% { opacity: 1; }
  100% { opacity: 0; }
}

/* Heading anchor links */
.heading-anchor {
  color: inherit;
  text-decoration: none;
  position: relative;
  cursor: pointer;
}
.heading-anchor-icon {
  width: 0.65em;
  height: 0.65em;
  display: inline-block;
  vertical-align: baseline;
  margin-left: 0.35em;
  color: #94a3b8;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}
.heading-anchor:hover .heading-anchor-icon,
.heading-anchor:focus-visible .heading-anchor-icon {
  opacity: 1;
}
.heading-anchor:hover .heading-anchor-icon {
  color: #2563eb;
}
.dark .heading-anchor:hover .heading-anchor-icon {
  color: #60a5fa;
}
.heading-anchor-tooltip {
  position: absolute;
  top: -1.75rem;
  right: 0;
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  background: #f1f5f9;
  color: #64748b;
  animation: copy-fade 1.5s ease-out forwards;
}
.dark .heading-anchor-tooltip {
  background: #1e293b;
  color: #94a3af;
}

/* Focus visible outline for accessibility */
:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
