/* ==========================================================================
   CSS VARIABLES
   ========================================================================== */
:root {
    /* Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-sidebar: #0f172a;
    --bg-code: #1e293b;
    --bg-card: #ffffff;
    --bg-header: #f1f5f9;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-code: #e2e8f0;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-alpha: rgba(59, 130, 246, 0.1);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --border: #e2e8f0;
    --border-dark: #334155;

    --radius-sm: 0.375rem;
    --radius: 0.75rem;
    --radius-lg: 1rem;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    --transition: all 0.2s ease-in-out;
    --transition-slow: all 0.3s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-sidebar: #020617;
        --bg-code: #1a2238;
        --bg-card: #1e293b;
        --bg-header: #1e293b;

        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        --text-code: #cbd5e1;

        --border: #334155;
    }
}

/* Manual dark mode override */
html.dark {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-sidebar: #020617;
    --bg-code: #1a2238;
    --bg-card: #1e293b;
    --bg-header: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-code: #cbd5e1;

    --border: #334155;
}

/* ==========================================================================
   BASE
   ========================================================================== */
*,
*::before,
*::after {
    margin: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    transition: var(--transition);
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   TYPOGRAPHY
   ========================================================================== */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.3;
    margin: 1.5rem 0 1rem;
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 1.875rem;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
}

p {
    margin: 1rem 0;
    color: var(--text-secondary);
}

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

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

code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875em;
}

strong {
    font-weight: 600;
    color: var(--text-primary);
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    overflow-y: auto;
    padding: 1.5rem 1rem;
    border-right: 1px solid var(--border);
    z-index: 40;
    transition: var(--transition-slow);
}

.main-content {
    margin-left: 280px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.header {
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.search-container {
    display: none;
    position: relative;
    max-width: 400px;
    flex: 1;
    margin: 0 auto;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    font-size: 0.9375rem;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-alpha);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.theme-toggle,
.mobile-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover,
.mobile-toggle:hover {
    background: var(--bg-secondary);
}

.theme-toggle i,
.mobile-toggle i {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
}

/* ==========================================================================
   SIDEBAR NAV
   ========================================================================== */
.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.5rem;
    margin-bottom: 2rem;
    color: white;
    text-decoration: none;
}

.logo i {
    width: 32px;
    height: 32px;
}

.nav-group {
    margin-bottom: 1.5rem;
}

.nav-title {
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 600;
    color: #94a3b8;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    padding-left: 0.75rem;
}

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

.nav-item {
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9375rem;
    transition: var(--transition);
}

.nav-link i {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    transition: var(--transition);
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-link:hover i {
    opacity: 1;
}

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

.nav-link.active i {
    opacity: 1;
}

/* ==========================================================================
   CONTENT
   ========================================================================== */
.content {
    flex: 1;
    padding: 2rem;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
    color: var(--text-primary);
}

.page-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.meta-item i {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.prose h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 2rem 0 1rem;
    color: var(--text-primary);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.text {
    margin: 1rem 0;
    color: var(--text-secondary);
}

.highlight {
    color: var(--primary);
    background: var(--primary-alpha);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

/* ==========================================================================
   CODE BLOCKS
   ========================================================================== */
.code-block {
    position: relative;
    margin: 1.5rem 0;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-code);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.1);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.lang {
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

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

pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    background: transparent;
}

code {
    color: var(--text-code);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ==========================================================================
   NEXT STEPS CARDS
   ========================================================================== */
.next-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.next-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    background: var(--bg-card);
    transition: var(--transition);
}

.next-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.next-card i {
    width: 40px;
    height: 40px;
    padding: 0.5rem;
    background: var(--primary-alpha);
    color: var(--primary);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.next-card strong {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.next-card p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ==========================================================================
   ALERTS
   ========================================================================== */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin: 1.5rem 0;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    font-size: 0.9375rem;
    border-left: 4px solid;
}

.alert i {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--primary);
    color: var(--text-primary);
}

.alert-info i {
    color: var(--primary);
}

.alert-warning {
    background: rgba(251, 191, 36, 0.1);
    border-color: var(--warning);
    color: var(--text-primary);
}

.alert-warning i {
    color: var(--warning);
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-style: italic;
}

.error-page {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.error-page h2 {
    color: var(--danger, #ef4444);
    margin-bottom: 1rem;
}

.error-page code {
    background: var(--bg-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
}

/* -------------------------------------------------
   Demo iframe wrapper – keeps the demo centered
   and scrollable on tiny screens.
   ------------------------------------------------- */
.demo-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 1.5rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background: #000;
    /* matches demo background */
}

/* 16:9 fallback for very wide screens */
.demo-wrapper::before {
    content: "";
    display: block;
    padding-top: 56.25%;
    /* 9/16 * 100% */
}

/* The iframe fills the wrapper */
.demo-wrapper>iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* -------------------------------------------------
   Clean embed (top) – fixed height
   ------------------------------------------------- */
.clean-demo {
    position: relative;
    width: 100%;
    height: 600px;
    margin: 1.5rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.clean-demo>iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

/* -------------------------------------------------
   Full interactive demo (bottom) – responsive
   ------------------------------------------------- */
.full-demo {
    position: relative;
    width: 100%;
    height: 80vh;
    max-height: 900px;
    margin: 2rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.full-demo>iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

/* ==========================================================================
   MOBILE
   ========================================================================== */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    backdrop-filter: blur(4px);
}

.overlay.active {
    display: block;
}

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 50;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-toggle {
        display: block;
    }

    .content {
        max-width: 100%;
        padding: 1.5rem;
    }

    .header {
        padding: 1rem;
    }

    .search-container {
        max-width: 200px;
    }
}

@media (max-width: 640px) {
    .page-title {
        font-size: 1.875rem;
    }

    .next-steps {
        grid-template-columns: 1fr;
    }

    .demo-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .demo-wrapper::before {
        display: none;
    }

    .demo-wrapper>iframe {
        position: static;
        height: 80vh;
    }

    .clean-demo, .full-demo { height: 70vh; }
}

/* ==========================================================================
   SCROLLBAR
   ========================================================================== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.video-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 1.5rem auto;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    background: #000;
}

.video-wrapper video {
    width: 100%;
    height: 414px;
    display: block;
}

/* Optional: Add subtle play button overlay if no poster */
.video-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.05);
    pointer-events: none;
    z-index: 1;
}

.table-container {
    margin: 2.5rem auto;
    overflow-x: auto;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    background: #fff;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.table-container table {
    width: 100%;
    min-width: 560px;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
}

.table-container thead th {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
    padding: 1.2rem 1rem;
    text-align: center;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
}

.table-container tbody tr {
    transition: all 0.2s ease;
}

.table-container tbody tr:nth-child(even) {
    background-color: rgba(59, 130, 246, 0.04);
}

.table-container tbody tr:hover {
    background-color: rgba(59, 130, 246, 0.12);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.15);
}

.table-container td {
    padding: 1.1rem 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(59, 130, 246, 0.15);
}

.table-container td:first-child {
    text-align: left;
    font-weight: 600;
    color: #1e293b;
}

.table-container td:last-child {
    font-weight: 700;
    color: #2563eb;
    font-size: 1.05em;
}

/* Rounded corners */
.table-container thead th:first-child {
    border-top-left-radius: 12px;
}

.table-container thead th:last-child {
    border-top-right-radius: 12px;
}

.table-container tbody tr:last-child td:first-child {
    border-bottom-left-radius: 12px;
}

.table-container tbody tr:last-child td:last-child {
    border-bottom-right-radius: 12px;
}

/* Mobile friendly */
@media (max-width: 768px) {
    .table-container {
        margin: 2rem -1rem;
        border-radius: 0;
        box-shadow: none;
    }
}

.section-divider {
    margin: 3rem 0;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
}

@media (prefers-color-scheme: light) {
    .section-divider {
        border-top-color: rgba(0, 0, 0, 0.1);
    }
}