/* ============================================
   WebForge — Layout (Header + Sidebar + Main)
   ============================================ */

/* === Page Wrapper === */
.page-wrapper {
    display: grid;
    grid-template-rows: var(--header-height) 1fr auto;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-areas:
        "header header"
        "sidebar content"
        "sidebar footer";
    min-height: 100vh;
    transition: grid-template-columns var(--transition-theme);
}

.page-wrapper.sidebar-collapsed {
    grid-template-columns: 0 1fr;
}

.page-wrapper.no-sidebar {
    grid-template-columns: 0 1fr;
}

/* === Header === */
.site-header {
    grid-area: header;
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-family: var(--font-heading);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.header-logo:hover {
    color: var(--accent-blue);
}

.header-logo svg {
    width: 28px;
    height: 28px;
    color: var(--accent-cyan);
}

.header-search {
    position: relative;
}

.header-search input {
    width: 260px;
    padding: var(--space-2) var(--space-4);
    padding-left: var(--space-10);
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.header-search input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px var(--accent-blue), 0 0 0 4px rgba(88, 166, 255, 0.15);
}

.header-search-icon {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    width: 16px;
    height: 16px;
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: calc(100% + var(--space-2));
    left: 0;
    right: 0;
    min-width: 420px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    max-height: 460px;
    overflow-y: auto;
    z-index: var(--z-header);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.search-results.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.search-results-header {
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.search-results-empty {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-4);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.search-results-empty svg {
    flex-shrink: 0;
    opacity: 0.5;
}

.search-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--text-primary);
    text-decoration: none;
    transition: background-color var(--transition-fast);
    border-left: 3px solid transparent;
}

.search-result-item:hover,
.search-result-item.active {
    background-color: var(--bg-tertiary);
    border-left-color: var(--accent-blue);
}

.search-result-item.active {
    background-color: rgba(88, 166, 255, 0.08);
}

.search-result-content {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.search-result-title mark {
    background-color: rgba(188, 140, 255, 0.25);
    color: var(--text-primary);
    border-radius: 2px;
    padding: 0 2px;
}

.search-result-context {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-context mark {
    background-color: rgba(188, 140, 255, 0.2);
    color: var(--text-secondary);
    border-radius: 2px;
    padding: 0 2px;
}

.search-result-category {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    opacity: 0.7;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.header-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.header-btn svg {
    width: 20px;
    height: 20px;
}

.theme-toggle-icon {
    transition: transform var(--transition-base);
}

.theme-toggle-icon.rotate {
    transform: rotate(180deg);
}

.hamburger-btn {
    display: none;
}

/* === Sidebar === */
.site-sidebar {
    grid-area: sidebar;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: var(--space-4) 0;
    transition: transform var(--transition-base), opacity var(--transition-base);
}

.sidebar-collapsed .site-sidebar {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

/* === Sidebar Navigation === */
.sidebar-nav {
    padding: 0 var(--space-3);
}

.sidebar-category {
    margin-bottom: var(--space-2);
}

.sidebar-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-heading);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast);
    user-select: none;
}

.sidebar-category-header:hover {
    background-color: var(--bg-tertiary);
}

.sidebar-category-header svg {
    width: 14px;
    height: 14px;
    transition: transform var(--transition-fast);
}

.sidebar-category.collapsed .sidebar-category-header svg {
    transform: rotate(-90deg);
}

.sidebar-category.collapsed .sidebar-category-links {
    display: none;
}

.sidebar-category-links {
    list-style: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-6);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    border-left: 2px solid transparent;
}

.sidebar-link:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-link.active {
    color: var(--accent-blue);
    background-color: rgba(88, 166, 255, 0.08);
    border-left-color: var(--accent-blue);
}

.sidebar-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link.active svg {
    opacity: 1;
    color: var(--accent-blue);
}

/* === Sidebar Cheatsheet Badge === */
.sidebar-link-badge {
    margin-left: auto;
    font-size: var(--font-size-xs);
    padding: 0.1em 0.5em;
    border-radius: var(--radius-full);
    background-color: rgba(88, 166, 255, 0.12);
    color: var(--accent-blue);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Main Content === */
.main-content {
    grid-area: content;
    padding: var(--space-8) var(--space-10);
    max-width: var(--content-max-width);
    width: 100%;
    margin: 0 auto;
}

/* === Footer === */
.site-footer {
    grid-area: footer;
    padding: var(--space-6) var(--space-10);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.site-footer > span:first-child {
    flex: 1;
}

.site-footer > .footer-links:last-child {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.footer-center {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.footer-center a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-center a:hover {
    color: var(--accent-blue);
}

.footer-center a svg {
    width: 16px;
    height: 16px;
}

.footer-sep {
    color: var(--border-color);
    user-select: none;
}

.footer-links {
    display: flex;
    gap: var(--space-4);
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--accent-blue);
}

@media (max-width: 640px) {
    .site-footer {
        flex-direction: column;
        gap: var(--space-3);
        text-align: center;
    }
}

/* === Overlay (mobile sidebar) === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
    opacity: 0;
    transition: opacity var(--transition-base);
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 16px;
    z-index: 1000;
    padding: var(--space-2) var(--space-4);
    background: var(--accent-blue);
    color: var(--text-inverse);
    font-weight: 600;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: top 0.2s;
}

.skip-link:focus {
    top: var(--space-3);
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

/* Section nav (prev/next between pages) */
.section-nav {
    display: flex;
    justify-content: space-between;
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-color);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* === Landing page override === */
.landing-page .page-wrapper {
    grid-template-columns: 1fr;
    grid-template-areas:
        "header"
        "content"
        "footer";
}

.landing-page .site-sidebar {
    display: none;
}