/* Base Reset & Variables */
:root {
    /* Fallback variables before JS loads */
    --font-family: 'Inter', system-ui, sans-serif;
    --bg-page: #09090b;
    --bg-surface: #121214;
    --text-primary: #ededef;
    --text-secondary: #a1a1aa;
    --accent-primary: #3b82f6;
    --border-subtle: rgba(255,255,255,0.06);
    
    --sidebar-width: 280px;
    --header-height: 64px;
}

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

body {
    font-family: var(--typography-font_family, var(--font-family));
    background-color: var(--colors-semantic-background-page, var(--bg-page));
    color: var(--colors-semantic-text-primary, var(--text-primary));
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--colors-semantic-background-surface, var(--bg-surface));
    border-right: 1px solid var(--colors-semantic-border-subtle, var(--border-subtle));
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.brand {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--colors-semantic-border-subtle, var(--border-subtle));
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    font-size: 0.875rem;
}

.brand h1 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.nav-menu {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

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

.nav-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--colors-semantic-text-muted, #52525b);
    display: block;
    margin-bottom: 0.75rem;
    padding-left: 0.75rem;
    font-weight: 600;
}

.nav-item {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    color: var(--colors-semantic-text-secondary, var(--text-secondary));
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.nav-subgroup {
    padding-left: 0.5rem;
    margin-top: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-subgroup .nav-item {
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
}

.nav-item:hover {
    background: var(--colors-semantic-background-elevated);
    color: var(--colors-semantic-text-primary, var(--text-primary));
}

.nav-item.active {
    background: var(--colors-semantic-accent-subtle, rgba(59, 130, 246, 0.1));
    color: var(--colors-semantic-accent-primary, #3b82f6);
    font-weight: 500;
}

.nav-item i {
    font-size: 1.125rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--colors-semantic-border-subtle, var(--border-subtle));
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    font-size: 0.875rem;
    color: var(--colors-semantic-text-secondary, var(--text-secondary));
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.top-bar {
    height: var(--header-height);
    border-bottom: 1px solid var(--colors-semantic-border-subtle, var(--border-subtle));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    backdrop-filter: blur(10px);
    background: var(--colors-semantic-background-surface);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
}

.breadcrumbs {
    font-size: 0.875rem;
    color: var(--colors-semantic-text-muted, var(--text-secondary));
}

.breadcrumbs span {
    color: var(--colors-semantic-text-primary, var(--text-primary));
    font-weight: 500;
}

.action-btn {
    text-decoration: none;
    color: var(--colors-semantic-text-secondary, var(--text-secondary));
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--colors-semantic-border-subtle, var(--border-subtle));
    border-radius: 6px;
    transition: all 0.2s;
}

.action-btn:hover {
    border-color: var(--colors-semantic-text-muted, #52525b);
    color: var(--colors-semantic-text-primary, var(--text-primary));
}

.content-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--header-height) + 2rem) 2rem 2rem 2rem;
}

/* Sections */
.section {
    max-width: 1200px;
    margin: 0 auto var(--spacing-xl, 4rem) auto;
    animation: fadeIn 0.4s ease-out;
}

.section-header {
    margin-bottom: 2rem;
}

.section-title {
    font-size: 2.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    letter-spacing: -0.02em;
}

.section-desc {
    font-size: 1.125rem;
    color: var(--colors-semantic-text-secondary, var(--text-secondary));
    max-width: 60ch;
}

/* Cards & Grid for Colors */
.grid-auto-fill {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-lg, 1.5rem);
}

.color-card {
    background: var(--colors-semantic-background-surface);
    border: 1px solid var(--colors-semantic-border-subtle);
    border-radius: var(--radius-lg, 1rem);
    overflow: hidden;
    transition: transform 0.2s;
}

.color-card:hover {
    box-shadow: var(--shadows-lg);
    border-color: var(--colors-semantic-accent-primary);
}

.interactive-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
}

.interactive-card:hover {
    box-shadow: var(--shadows-premium);
    border-color: var(--colors-semantic-accent-primary) !important;
}

.interactive-card::after {
    content: '\eb91'; /* Boxicons arrow-right */
    font-family: 'boxicons';
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    font-size: 1.25rem;
    color: var(--colors-semantic-accent-primary);
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.3s ease;
}

.interactive-card:hover::after {
    opacity: 1;
    transform: translateX(0);
}

.color-swatch {
    height: 100px;
    width: 100%;
    position: relative;
}

.color-info {
    padding: 1rem;
}

.color-name {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    color: var(--colors-semantic-text-primary);
}

.color-value {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--colors-semantic-text-muted);
}

/* Typography Preview */
.type-scale-row {
    display: flex;
    align-items: baseline;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--colors-semantic-border-subtle);
    gap: 2rem;
}

.type-meta {
    width: 150px;
    flex-shrink: 0;
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--colors-semantic-text-muted);
}

.type-preview {
    color: var(--colors-semantic-text-primary);
}

/* Component Demo */
.component-demo-stage {
    padding: 3rem;
    background-image: 
        linear-gradient(45deg, var(--colors-semantic-border-subtle) 25%, transparent 25%), 
        linear-gradient(-45deg, var(--colors-semantic-border-subtle) 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, var(--colors-semantic-border-subtle) 75%), 
        linear-gradient(-45deg, transparent 75%, var(--colors-semantic-border-subtle) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    border: 1px solid var(--colors-semantic-border-subtle);
    border-radius: var(--radius-lg, 1rem);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
}

/* Generated Classes from JSON will map to these if possible */
.btn-primary {
    background: var(--colors-semantic-accent-primary);
    color: var(--colors-semantic-text-on_accent);
    border: none;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--colors-semantic-accent-glow);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--colors-semantic-border-default);
    color: var(--colors-semantic-text-primary);
    cursor: pointer;
}

/* Loading */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    color: var(--colors-semantic-text-muted);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--colors-semantic-border-subtle);
    border-radius: 50%;
    border-top-color: var(--colors-semantic-accent-primary);
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Switch Toggle */
.switch { position: relative; display: inline-block; width: 40px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--colors-semantic-border-prominent); transition: .4s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--colors-semantic-accent-primary); }
input:checked + .slider:before { transform: translateX(16px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }
/* Mobile Responsiveness */

/* Menu Button - Hidden on Desktop */
.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--colors-semantic-text-primary, var(--text-primary));
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.5rem;
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 260px;
    }

    .app-container {
        position: relative;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: var(--sidebar-width);
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        left: 0;
    }

    .menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .content-scrollable {
        padding: calc(var(--header-height) + 1rem) 1rem 1rem 1rem;
    }

    .grid-auto-fill {
        grid-template-columns: 1fr;
    }

    /* Bento Stacking */
    [style*="display: grid"][style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
    }

    [style*="grid-column: span"], [style*="grid-row: span"] {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        backdrop-filter: blur(4px);
        z-index: 9;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
}
