/**
 * Hybrid Layout - Header + Sidebar Navigation Pattern
 * Two-tier navigation: header for global actions, sidebar for module navigation
 * @version 1.0.0
 */

/* =============================================================================
   CSS CUSTOM PROPERTIES
   ============================================================================= */

:root {
    /* Layout dimensions */
    --hybrid-header-height: 56px;
    --hybrid-sidebar-width: 260px;
    --hybrid-sidebar-collapsed-width: 0px;
    --hybrid-content-max-width: 800px;
    --hybrid-right-panel-width: 280px;

    /* Z-index layers */
    --hybrid-z-header: 100;
    --hybrid-z-sidebar: 90;
    --hybrid-z-overlay: 80;
    --hybrid-z-content: 1;

    /* Transitions */
    --hybrid-transition-fast: 150ms ease;
    --hybrid-transition-normal: 250ms ease;
    --hybrid-transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* =============================================================================
   HYBRID LAYOUT CONTAINER
   ============================================================================= */

.hybrid-layout {
    display: grid;
    grid-template-areas:
        "header header header"
        "sidebar content right-panel";
    grid-template-columns: var(--hybrid-sidebar-width) 1fr var(--hybrid-right-panel-width, 0);
    grid-template-rows: var(--hybrid-header-height) 1fr;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
}

/* Without right panel */
.hybrid-layout:not(.has-right-panel) {
    grid-template-areas:
        "header header"
        "sidebar content";
    grid-template-columns: var(--hybrid-sidebar-width) 1fr;
}

/* =============================================================================
   HEADER (Global Navigation Zone)
   ============================================================================= */

.hybrid-header {
    grid-area: header;
    position: sticky;
    top: 0;
    z-index: var(--hybrid-z-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    /* Safe area for edge-to-edge displays */
    padding-top: max(env(safe-area-inset-top, 0px), 0px);
}

.hybrid-header__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hybrid-header__center {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 0 20px;
}

.hybrid-header__right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Sidebar toggle button (hamburger) */
.sidebar-toggle {
    display: none; /* Hidden by default on desktop */
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background-color var(--hybrid-transition-fast);
}

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

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.sidebar-toggle__icon {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 20px;
}

.sidebar-toggle__icon span {
    display: block;
    width: 100%;
    height: 2px;
    background-color: currentColor;
    border-radius: 1px;
    transition: transform var(--hybrid-transition-fast), opacity var(--hybrid-transition-fast);
}

/* Hamburger to X animation when sidebar is open */
.hybrid-layout.sidebar-open .sidebar-toggle__icon span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.hybrid-layout.sidebar-open .sidebar-toggle__icon span:nth-child(2) {
    opacity: 0;
}

.hybrid-layout.sidebar-open .sidebar-toggle__icon span:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

/* Page title in header */
.hybrid-header__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Global search (optional) */
.hybrid-header__search {
    position: relative;
    width: 100%;
    max-width: 400px;
}

.hybrid-header__search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transition: border-color var(--hybrid-transition-fast), box-shadow var(--hybrid-transition-fast);
}

.hybrid-header__search-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb, 37, 99, 235), 0.1);
}

.hybrid-header__search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* =============================================================================
   SIDEBAR (Module/Section Navigation)
   ============================================================================= */

.hybrid-sidebar {
    grid-area: sidebar;
    position: sticky;
    top: var(--hybrid-header-height);
    height: calc(100vh - var(--hybrid-header-height));
    height: calc(100dvh - var(--hybrid-header-height));
    overflow-y: auto;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: var(--hybrid-z-sidebar);
    transition: transform var(--hybrid-transition-slow);
}

/* Sidebar header */
.hybrid-sidebar__header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid var(--border-color);
}

.hybrid-sidebar__app-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.hybrid-sidebar__app-icon {
    font-size: 24px;
    line-height: 1;
}

/* Navigation */
.hybrid-sidebar__nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sidebar-nav-group {
    padding: 0 12px;
    margin-bottom: 16px;
}

.sidebar-nav-group:last-child {
    margin-bottom: 0;
}

.sidebar-nav-group__title {
    padding: 8px 8px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: all var(--hybrid-transition-fast);
}

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

.sidebar-nav-item:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: -2px;
}

.sidebar-nav-item.active {
    background-color: var(--accent-color-light, rgba(var(--accent-color-rgb, 37, 99, 235), 0.1));
    color: var(--accent-color);
    font-weight: 600;
}

.sidebar-nav-item__icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav-item__badge {
    margin-left: auto;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    background-color: var(--accent-color);
    color: white;
    border-radius: 10px;
}

/* Sidebar footer */
.hybrid-sidebar__footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

/* =============================================================================
   MAIN CONTENT AREA
   ============================================================================= */

.hybrid-content {
    grid-area: content;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevent overflow */
    background-color: var(--bg-primary);
}

.hybrid-content__inner {
    flex: 1;
    width: 100%;
    max-width: var(--hybrid-content-max-width);
    margin: 0 auto;
    padding: 24px;
}

/* Content toolbar (page-level actions) */
.hybrid-content__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.hybrid-content__breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.hybrid-content__breadcrumb a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--hybrid-transition-fast);
}

.hybrid-content__breadcrumb a:hover {
    color: var(--text-primary);
}

.hybrid-content__breadcrumb-separator {
    color: var(--text-muted);
}

.hybrid-content__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* =============================================================================
   RIGHT PANEL (Optional - Inspectors/Help/Metadata)
   ============================================================================= */

.hybrid-right-panel {
    grid-area: right-panel;
    position: sticky;
    top: var(--hybrid-header-height);
    height: calc(100vh - var(--hybrid-header-height));
    height: calc(100dvh - var(--hybrid-header-height));
    overflow-y: auto;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 20px;
}

/* =============================================================================
   OVERLAY (Mobile sidebar backdrop)
   ============================================================================= */

.hybrid-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--hybrid-z-sidebar) - 1);
    opacity: 0;
    transition: opacity var(--hybrid-transition-normal);
}

/* =============================================================================
   RESPONSIVE - TABLET (< 1024px)
   ============================================================================= */

@media (max-width: 1023px) {
    .hybrid-layout {
        --hybrid-sidebar-width: 220px;
    }

    .hybrid-layout:not(.has-right-panel) {
        grid-template-columns: var(--hybrid-sidebar-width) 1fr;
    }

    /* Hide right panel on tablet */
    .hybrid-layout.has-right-panel {
        grid-template-areas:
            "header header"
            "sidebar content";
        grid-template-columns: var(--hybrid-sidebar-width) 1fr;
    }

    .hybrid-right-panel {
        display: none;
    }
}

/* =============================================================================
   RESPONSIVE - MOBILE (< 768px)
   ============================================================================= */

@media (max-width: 767px) {
    .hybrid-layout {
        grid-template-areas:
            "header"
            "content";
        grid-template-columns: 1fr;
        grid-template-rows: var(--hybrid-header-height) 1fr;
    }

    /* Show sidebar toggle on mobile */
    .sidebar-toggle {
        display: flex;
    }

    /* Sidebar becomes a drawer */
    .hybrid-sidebar {
        position: fixed;
        top: var(--hybrid-header-height);
        left: 0;
        width: var(--hybrid-sidebar-width);
        height: calc(100vh - var(--hybrid-header-height));
        height: calc(100dvh - var(--hybrid-header-height));
        transform: translateX(-100%);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.1);
    }

    /* Sidebar open state */
    .hybrid-layout.sidebar-open .hybrid-sidebar {
        transform: translateX(0);
    }

    /* Show overlay when sidebar is open */
    .hybrid-layout.sidebar-open .hybrid-overlay {
        display: block;
        opacity: 1;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }

    /* Content adjustments */
    .hybrid-content__inner {
        padding: 16px;
    }

    .hybrid-content__toolbar {
        padding: 12px 16px;
        flex-wrap: wrap;
    }

    /* Hide breadcrumb on very small screens */
    .hybrid-content__breadcrumb {
        display: none;
    }
}

/* =============================================================================
   RESPONSIVE - SMALL MOBILE (< 480px)
   ============================================================================= */

@media (max-width: 479px) {
    .hybrid-layout {
        --hybrid-sidebar-width: 280px;
    }

    .hybrid-header {
        padding: 0 12px;
    }

    .hybrid-content__inner {
        padding: 12px;
    }

    .hybrid-header__title {
        font-size: 16px;
    }
}

/* =============================================================================
   WHERE AM I INDICATOR (Breadcrumbs + Page Title)
   ============================================================================= */

.where-am-i {
    display: flex;
    align-items: center;
    gap: 8px;
}

.where-am-i__breadcrumb {
    display: none; /* Hidden on mobile, shown on desktop */
}

.where-am-i__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

@media (min-width: 768px) {
    .where-am-i__breadcrumb {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 14px;
    }

    .where-am-i__breadcrumb a {
        color: var(--text-secondary);
        text-decoration: none;
    }

    .where-am-i__breadcrumb a:hover {
        color: var(--text-primary);
    }

    .where-am-i__separator {
        color: var(--text-muted);
    }
}

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */

/* Hide on mobile */
.hide-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: initial;
    }
}

/* Hide on desktop */
.hide-desktop {
    display: initial;
}

@media (min-width: 768px) {
    .hide-desktop {
        display: none;
    }
}

/* =============================================================================
   REDUCED MOTION
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    .hybrid-sidebar,
    .hybrid-overlay,
    .sidebar-toggle__icon span {
        transition: none;
    }
}
