/* Layout
 * Contains structure and positioning styles
 * Uses data-view attribute on <html> to switch between:
 *   "home"       — full-width, no sidebar, no TOC
 *   "foundation" — sidebar (foundation items) + content + TOC
 *   "components" — sidebar (component items) + content + TOC
 */

/* ─── Top Header ─── */
.top-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-secondary);
    z-index: 50;
    display: flex;
    align-items: center;
}

.top-header-inner {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 1.5rem;
    gap: 1.5rem;
}

.top-header-left {
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9375rem;
    white-space: nowrap;
    transition: opacity 0.15s ease;
}

.header-logo:hover {
    opacity: 0.8;
}

.header-logo i {
    font-size: 1.125rem;
    color: var(--fg-brand-primary);
}

.header-logo-text {
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header-logo-divider {
    width: 1px;
    height: 18px;
    background-color: var(--border-secondary);
    margin: 0 0.125rem;
}

.header-logo-label {
    font-weight: 400;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.top-header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.5rem;
}

.header-nav-link {
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.header-nav-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary-hover);
}

.header-nav-link.active {
    color: var(--fg-brand-primary);
    background-color: var(--bg-brand-primary);
    font-weight: 600;
}

.top-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

/* Header Utility Link (Changelog) */
.header-util-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.header-util-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary-hover);
}

.header-util-link.active {
    color: var(--fg-brand-primary);
    background-color: var(--bg-brand-primary);
}

.header-util-link i {
    font-size: 0.875rem;
}

/* Header Search */
.header-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    min-width: 180px;
    cursor: not-allowed;
    opacity: 0.65;
}

.header-search-icon {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

.header-search-input {
    border: none;
    background: transparent;
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    outline: none;
    width: 100%;
    cursor: not-allowed;
    font-family: inherit;
}

.header-search-input::placeholder {
    color: var(--text-placeholder, var(--text-tertiary));
}

.header-search-kbd {
    font-family: inherit;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    padding: 0.0625rem 0.375rem;
    line-height: 1.4;
}

/* ─── Main Layout Grid ─── */
.layout {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100vh;
    padding-top: 56px;
    transition: grid-template-columns 0.25s ease;
}

/* Section views: show sidebar + content */
[data-view="foundation"] .layout,
[data-view="components"] .layout {
    grid-template-columns: 248px 1fr;
}

/* ─── Sidebar ─── */
.sidebar {
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-secondary);
    overflow-y: auto;
    height: calc(100vh - 56px);
    position: sticky;
    top: 56px;
    z-index: 10;
    transition: transform 0.3s ease-in-out;
}

/* Hide sidebar on home view */
[data-view="home"] .sidebar {
    display: none;
}

.sidebar-content {
    padding: 0.75rem 0;
}

/* Sidebar sections — only show the active one */
.sidebar-section {
    display: none;
}

[data-view="foundation"] .sidebar-section[data-sidebar="foundation"] {
    display: block;
}

[data-view="components"] .sidebar-section[data-sidebar="components"] {
    display: block;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 5;
    animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mobile sidebar toggle button */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: calc(56px + 0.75rem);
    left: 0.75rem;
    z-index: 60;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.1);
    transition: background-color 0.2s;
}

.sidebar-toggle:hover {
    background-color: var(--bg-primary-hover);
}

.sidebar-toggle i {
    display: block;
    font-size: 1.25rem;
    color: var(--text-primary);
}

/* ─── Main Content ─── */
.main-content {
    background-color: var(--bg-canvas);
    min-height: calc(100vh - 56px);
    padding: 2.5rem 3rem;
    width: 100%;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 230px;
    gap: 2rem;
}

.content-wrapper {
    min-width: 0;
    max-width: 1440px;
    align-self: start;
}

/* Home view: center content with more breathing room */
[data-view="home"] .main-content {
    padding: 0;
    grid-template-columns: 1fr;
}

[data-view="home"] .content-wrapper {
    max-width: 100%;
}

/* ─── Right TOC Sidebar — In-flow, Sticky ─── */
.toc-sidebar {
    position: sticky;
    top: calc(56px + 2rem);
    max-height: calc(100vh - 56px - 4rem);
    overflow-y: auto;
    background: transparent;
    border: none;
    padding: 0;
}

/* Hide TOC on home view */
[data-view="home"] .toc-sidebar {
    display: none;
}

.toc-header {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    padding: 0 0.5rem;
    margin-bottom: 0.75rem;
}

.toc-nav {
    display: flex;
    flex-direction: column;
}

.toc-link {
    display: block;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    text-decoration: none;
    transition: color 0.15s ease;
    line-height: 1.5;
    border-left: 2px solid transparent;
}

.toc-link:hover {
    color: var(--text-primary);
}

.toc-link.active {
    color: var(--fg-brand-primary);
    border-left-color: var(--fg-brand-primary);
    font-weight: 500;
}

.toc-link.toc-h3 {
    padding-left: 1.25rem;
    font-size: 0.75rem;
}

/* ─── Standalone pages (home-view pages that need constrained content) ─── */
#changelog-page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2.5rem 3rem;
}

/* ─── Container sizes ─── */
.container-sm { max-width: 640px; margin: 0 auto; }
.container-md { max-width: 768px; margin: 0 auto; }
.container-lg { max-width: 1024px; margin: 0 auto; }
.container-xl { max-width: 1280px; margin: 0 auto; }
.container-fluid { width: 100%; }

/* ─── Grid system ─── */
.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
}

.grid-col-1 { grid-column: span 1; }
.grid-col-2 { grid-column: span 2; }
.grid-col-3 { grid-column: span 3; }
.grid-col-4 { grid-column: span 4; }
.grid-col-5 { grid-column: span 5; }
.grid-col-6 { grid-column: span 6; }
.grid-col-7 { grid-column: span 7; }
.grid-col-8 { grid-column: span 8; }
.grid-col-9 { grid-column: span 9; }
.grid-col-10 { grid-column: span 10; }
.grid-col-11 { grid-column: span 11; }
.grid-col-12 { grid-column: span 12; }

/* ─── Responsive ─── */

/* Hide TOC when content needs more room */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .toc-sidebar {
        display: none;
    }
}

/* Collapse sidebar on tablet */
@media (max-width: 992px) {
    [data-view="foundation"] .layout,
    [data-view="components"] .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        width: 280px;
        top: 56px;
        transform: translateX(-100%);
        box-shadow: none;
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.1);
    }

    /* Show sidebar toggle button on tablet when in a section view */
    [data-view="foundation"] .sidebar-toggle,
    [data-view="components"] .sidebar-toggle {
        display: block;
    }

    .content-wrapper {
        margin-top: 0;
    }

    .main-content {
        padding: 1.5rem;
        padding-top: 3.5rem;
    }

    [data-view="home"] .main-content {
        padding: 0;
    }

    .grid {
        gap: 1rem;
    }
}

/* Small screens */
@media (max-width: 768px) {
    .header-search {
        display: none;
    }

    .header-util-link span {
        display: none;
    }

    .top-header-inner {
        gap: 0.75rem;
        padding: 0 0.75rem;
    }

    .top-header-nav {
        margin-left: 0.5rem;
    }

    .header-nav-link {
        padding: 0.25rem 0.5rem;
        font-size: 0.8125rem;
    }

    .header-logo-label {
        display: none;
    }

    .header-logo-divider {
        display: none;
    }
}

@media (max-width: 576px) {
    .grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.75rem;
    }

    .content-wrapper {
        padding: 0.5rem;
    }

    [class^="grid-col-"] {
        grid-column: span 4;
    }

    .sidebar-toggle {
        top: calc(56px + 0.5rem);
        left: 0.5rem;
    }

    .component-section .component-demo {
        padding: 1rem;
    }

    .component-section .component-example {
        margin-right: 0.75rem;
        margin-bottom: 0.75rem;
        padding: 0.75rem;
    }
}
