/**
 * Public Documentation Styles
 * GitBook-inspired clean documentation theme
 */

/* =============================================================================
   CSS Variables & Theme
   ============================================================================= */

:root {
    /* GitBook-inspired Blue Primary */
    --hue-primary: 220;
    --hue-mono: 220;

    /* Light Theme */
    --background: 0 0% 100%;
    --foreground: 220 40% 10%;

    --muted: 220 20% 97%;
    --muted-foreground: 220 15% 46%;

    --card: 0 0% 100%;
    --card-foreground: var(--foreground);

    --border: 220 20% 92%;
    --input: 220 20% 92%;

    /* GitBook blue */
    --primary: 220 90% 53%;
    --primary-foreground: 0 0% 100%;

    /* Header blue - GitBook style */
    --header-bg: 220 76% 53%;

    --secondary: 220 20% 96%;
    --secondary-foreground: 220 30% 15%;

    --accent: 220 20% 96%;
    --accent-foreground: 220 30% 15%;

    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 98%;

    --ring: 220 90% 60%;

    /* Layout */
    --sidebar-width: 280px;
    --toc-width: 240px;
    --header-height: 64px;
    --content-max-width: 768px;
    --layout-max-width: 1440px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;

    /* Spacing & Radius */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.dark {
    --background: 220 20% 7%;
    --foreground: 220 10% 98%;

    --muted: 220 20% 12%;
    --muted-foreground: 220 10% 60%;

    --card: 220 20% 10%;
    --card-foreground: var(--foreground);

    --border: 220 20% 16%;
    --input: 220 20% 16%;

    --primary: 220 90% 65%;
    --primary-foreground: 220 40% 10%;

    --header-bg: 220 30% 12%;

    --secondary: 220 20% 14%;
    --secondary-foreground: var(--foreground);

    --accent: 220 20% 14%;
    --accent-foreground: var(--foreground);

    --destructive: 0 62% 30%;
    --destructive-foreground: 0 0% 98%;

    --ring: 220 90% 65%;
}

/* =============================================================================
   Base Reset
   ============================================================================= */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-height) + 24px);
}

body {
    font-family: var(--font-sans);
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    line-height: 1.6;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color var(--transition-fast);
}

:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

/* =============================================================================
   Header (GitBook Style - Always Visible)
   ============================================================================= */

.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: hsl(var(--header-bg));
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: var(--layout-max-width);
    padding: 0 24px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: white;
    font-weight: 600;
    font-size: 1.125rem;
    text-decoration: none;
}

.header-logo img {
    height: 32px;
    width: auto;
}

.header-logo-text {
    color: white;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.header-search {
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    padding: 8px 16px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 240px;
}

@media (min-width: 768px) {
    .header-search {
        display: flex;
    }
}

.header-search:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.header-search-icon {
    width: 16px;
    height: 16px;
    opacity: 0.8;
}

.header-search-text {
    flex: 1;
}

.header-search-shortcut {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.icon {
    width: 20px;
    height: 20px;
}

/* Mobile menu button - only shows on small screens */
.menu-toggle {
    display: flex;
}

@media (min-width: 1024px) {
    .menu-toggle {
        display: none;
    }
}

/* Theme Icons */
.dark .sun-icon { display: block; }
.dark .moon-icon { display: none; }
.light .sun-icon { display: none; }
.light .moon-icon { display: block; }
:root:not(.dark):not(.light) .sun-icon { display: none; }
:root:not(.dark):not(.light) .moon-icon { display: block; }

/* =============================================================================
   Layout Structure (Centered like GitBook)
   ============================================================================= */

.layout {
    display: flex;
    min-height: 100vh;
    padding-top: var(--header-height);
    max-width: var(--layout-max-width);
    margin: 0 auto;
    position: relative;
}

/* =============================================================================
   Sidebar (Left)
   ============================================================================= */

.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background-color: hsl(var(--background));
    border-right: 1px solid hsl(var(--border));
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
    z-index: 40;
    overflow: hidden;
}

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

@media (min-width: 1024px) {
    .sidebar {
        position: sticky;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        transform: translateX(0);
        box-shadow: none;
        flex-shrink: 0;
    }
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--border)) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: hsl(var(--border));
    border-radius: 99px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid hsl(var(--border));
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.sidebar-footer a {
    color: hsl(var(--muted-foreground));
    text-decoration: none;
}

.sidebar-footer a:hover {
    color: hsl(var(--foreground));
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.sidebar-overlay--visible {
    opacity: 1;
    visibility: visible;
}

@media (min-width: 1024px) {
    .sidebar-overlay {
        display: none;
    }
}

/* =============================================================================
   Navigation Links (GitBook Style)
   ============================================================================= */

.nav-section {
    margin-bottom: 20px;
}

.nav-section-title {
    font-size: 0.6875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    padding: 0 12px;
    margin-bottom: 6px;
}

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

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 400;
    color: hsl(var(--muted-foreground));
    transition: all var(--transition-fast);
    text-decoration: none;
    cursor: pointer;
    line-height: 1.5;
}

.nav-link:hover {
    color: hsl(var(--foreground));
    background-color: hsl(var(--muted));
}

.nav-link--active {
    background-color: hsl(var(--primary) / 0.08);
    color: hsl(var(--primary));
    font-weight: 500;
}

.nav-link--active:hover {
    background-color: hsl(var(--primary) / 0.12);
    color: hsl(var(--primary));
}

/* Collapsible Groups */
.nav-group {
    width: 100%;
}

.nav-group-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    cursor: pointer;
    list-style: none;
    transition: all var(--transition-fast);
    user-select: none;
}

.nav-group-title::-webkit-details-marker {
    display: none;
}

.nav-group-title:hover {
    background-color: hsl(var(--muted));
}

.nav-group-title--active {
    color: hsl(var(--primary));
}

.nav-arrow {
    width: 14px;
    height: 14px;
    color: hsl(var(--muted-foreground));
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

details[open] > .nav-group-title .nav-arrow {
    transform: rotate(90deg);
}

.nav-children {
    list-style: none;
    margin-left: 8px;
    padding-left: 12px;
    margin-top: 1px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    position: relative;
}

.nav-children::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background-color: hsl(var(--border));
}

.nav-featured {
    margin-right: 6px;
    font-size: 0.875em;
}

.nav-empty {
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    padding: 16px;
    text-align: center;
}

/* =============================================================================
   Table of Contents (Right)
   ============================================================================= */

.toc {
    display: none;
}

@media (min-width: 1280px) {
    .toc {
        display: block;
        position: sticky;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        width: var(--toc-width);
        overflow-y: auto;
        background-color: hsl(var(--background));
        border-left: 1px solid hsl(var(--border));
        flex-shrink: 0;
    }
}

.toc-container {
    padding: 24px 20px;
}

.toc-title {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    margin-bottom: 12px;
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toc-link {
    display: block;
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
    transition: color var(--transition-fast);
    padding: 4px 0 4px 12px;
    border-left: 2px solid transparent;
    line-height: 1.4;
}

.toc-link:hover {
    color: hsl(var(--foreground));
}

.toc-link--active {
    color: hsl(var(--primary));
    border-left-color: hsl(var(--primary));
}

.toc-level-2 { }
.toc-level-3 { padding-left: 24px; }

/* =============================================================================
   Main Content Area
   ============================================================================= */

.main {
    flex: 1;
    min-width: 0;
    padding-bottom: 80px;
}

/* =============================================================================
   Breadcrumbs
   ============================================================================= */

.breadcrumb {
    margin-bottom: 24px;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.breadcrumb ol {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.breadcrumb li {
    display: flex;
    align-items: center;
}

.breadcrumb li:not(:last-child)::after {
    content: '/';
    margin: 0 8px;
    opacity: 0.5;
}

.breadcrumb a {
    color: hsl(var(--muted-foreground));
    transition: color var(--transition-fast);
}

.breadcrumb a:hover {
    color: hsl(var(--primary));
}

.breadcrumb li[aria-current="page"] {
    color: hsl(var(--foreground));
    font-weight: 500;
}

/* =============================================================================
   Pagination (Prev / Next)
   ============================================================================= */

.pagination {
    margin: 48px auto 0;
    padding-top: 32px;
    border-top: 1px solid hsl(var(--border));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    max-width: var(--content-max-width);
    padding-left: 24px;
    padding-right: 24px;
}

@media (min-width: 768px) {
    .pagination {
        padding-left: 48px;
        padding-right: 48px;
    }
}

.pagination-link {
    display: flex;
    flex-direction: column;
    padding: 16px;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    transition: all var(--transition-fast);
    text-decoration: none;
    background: hsl(var(--background));
}

.pagination-link:hover {
    border-color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.03);
}

.pagination-link--next {
    text-align: right;
    align-items: flex-end;
}

.pagination-sub {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pagination-title {
    font-weight: 500;
    color: hsl(var(--primary));
    font-size: 0.9375rem;
}

/* =============================================================================
   Prose (Article) Styles
   ============================================================================= */

.prose {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 32px 24px;
}

@media (min-width: 768px) {
    .prose {
        padding: 48px;
    }
}

/* Headings */
.prose h1 {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.025em;
    margin-bottom: 16px;
    color: hsl(var(--foreground));
}

@media (min-width: 768px) {
    .prose h1 {
        font-size: 2.5rem;
    }
}

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

.prose h3 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-top: 32px;
    margin-bottom: 12px;
    color: hsl(var(--foreground));
}

.prose h4,
.prose h5 {
    font-size: 1.0625rem;
    font-weight: 600;
    margin-top: 24px;
    margin-bottom: 8px;
    color: hsl(var(--foreground));
}

/* Body Text */
.prose p {
    margin-bottom: 16px;
    color: hsl(var(--foreground) / 0.9);
    line-height: 1.7;
}

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

/* Links */
.prose a {
    color: hsl(var(--primary));
    font-weight: 500;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.prose a:hover {
    border-bottom-color: hsl(var(--primary));
}

/* Lists */
.prose ul,
.prose ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.prose li {
    margin-bottom: 8px;
    line-height: 1.7;
}

.prose li::marker {
    color: hsl(var(--muted-foreground));
}

/* Blockquotes & Callouts */
.prose blockquote {
    border-left: 3px solid hsl(var(--primary));
    background: hsl(var(--muted));
    padding: 16px 20px;
    margin: 24px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: hsl(var(--foreground));
}

.prose blockquote p {
    margin-bottom: 0;
}

/* Code Blocks */
.prose pre {
    background-color: hsl(220 20% 13%);
    color: #e2e8f0;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    padding: 20px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 24px 0;
    position: relative;
}

/* Inline Code */
.prose code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background-color: hsl(var(--muted));
    color: hsl(var(--foreground));
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.prose pre code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-size: inherit;
    font-weight: normal;
}

/* Copy Button Styling */
.copy-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-sm);
    color: #94a3b8;
    cursor: pointer;
    transition: all var(--transition-fast);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #f8fafc;
}

.copy-btn--success {
    color: #4ade80 !important;
}

/* Tables */
.prose table {
    width: 100%;
    margin: 24px 0;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.prose th {
    text-align: left;
    padding: 12px 16px;
    background-color: hsl(var(--muted));
    color: hsl(var(--foreground));
    font-weight: 600;
    border-bottom: 2px solid hsl(var(--border));
}

.prose td {
    padding: 12px 16px;
    border-bottom: 1px solid hsl(var(--border));
    color: hsl(var(--foreground) / 0.9);
}

.prose tr:last-child td {
    border-bottom: none;
}

/* Images and Media */
.prose img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    margin: 24px 0;
}

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

/* Article Meta */
.article-meta {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-bottom: 32px;
}

/* =============================================================================
   Video Embeds
   ============================================================================= */

.video-embed,
.prose iframe[data-video-embed] {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    margin: 24px 0;
    border-radius: var(--radius);
    overflow: hidden;
    background-color: hsl(var(--muted));
}

.video-embed iframe,
.prose iframe[data-video-embed] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* =============================================================================
   Task Lists
   ============================================================================= */

.prose ul:has(input[type="checkbox"]) {
    list-style: none;
    padding-left: 0;
}

.prose li:has(> input[type="checkbox"]) {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.prose li > input[type="checkbox"] {
    margin-top: 5px;
    width: 16px;
    height: 16px;
    accent-color: hsl(var(--primary));
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* =============================================================================
   Footer
   ============================================================================= */

.footer {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 32px 24px;
    border-top: 1px solid hsl(var(--border));
    text-align: center;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}

@media (min-width: 768px) {
    .footer {
        padding: 32px 48px;
    }
}

/* =============================================================================
   Error Pages
   ============================================================================= */

.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 32px;
    text-align: center;
}

.error-title {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: hsl(var(--foreground));
    letter-spacing: -0.02em;
}

.error-message {
    color: hsl(var(--muted-foreground));
    font-size: 1rem;
    margin-bottom: 32px;
    max-width: 400px;
    line-height: 1.6;
}

.error-slug {
    background-color: hsl(var(--muted));
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.875em;
    color: hsl(var(--foreground));
}

.error-suggestions {
    text-align: left;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    padding: 24px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 360px;
}

.error-suggestions-title {
    font-weight: 600;
    margin-bottom: 12px;
    color: hsl(var(--foreground));
}

.error-suggestions-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.error-suggestions-list a {
    color: hsl(var(--primary));
    display: block;
}

.error-suggestions-list a:hover {
    text-decoration: underline;
}

.error-home-link {
    display: inline-block;
    margin-top: 24px;
    color: hsl(var(--primary));
    font-weight: 500;
    transition: opacity var(--transition-fast);
}

.error-home-link:hover {
    opacity: 0.8;
}

/* =============================================================================
   Utility Classes
   ============================================================================= */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
