/* /app/static/significantstories_com/css/nav.css */
/* Site-wide navigation drawer and header styles */

/* --- CSS Variables for Navigation --- */
:root {
    --nav-drawer-width: 280px;
    --nav-header-height: 60px;
    --nav-transition-speed: 300ms;
    --nav-transition-speed-slow: 500ms;
    --nav-overlay-color: rgba(0, 0, 0, 0.5);
}

/* --- Slow Close Animation (for larger devices) --- */
.nav-drawer.closing-slow {
    transition: transform var(--nav-transition-speed-slow) ease-out !important;
}

.nav-overlay.fade-slow {
    transition: opacity var(--nav-transition-speed-slow) ease-out !important;
}

/* --- Site Header Bar (non-article pages) --- */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-header-height);
    background-color: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    z-index: 200;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
}

.site-header-content {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* --- Hamburger Menu Button --- */
.menu-toggle {
    grid-column: 1;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    z-index: 260; /* Above overlay (250) so it's always clickable */
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    justify-self: start;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.menu-toggle:hover {
    background-color: #f0f3f6;
}

.menu-toggle-bar {
    width: 24px;
    height: 2px;
    background-color: #34495e;
    margin: 3px 0;
    border-radius: 2px;
    transition: all var(--nav-transition-speed) ease;
}

/* Hamburger to X animation */
.menu-toggle.active .menu-toggle-bar:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active .menu-toggle-bar:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active .menu-toggle-bar:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* --- Site Brand (Title + Logo link) in Header --- */
.site-header-brand {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    gap: 0;
}

/* Hide brand on homepage (hero has its own branding) */
/* Uses :has() to detect if hero section exists as a sibling - works with HTMX navigation */
.site-header:has(~ .hero) .site-header-brand {
    visibility: hidden;
}

.site-header-title {
    font-family: var(--serif-font);
    font-size: 1.25rem;
    font-weight: 600;
    color: #2c3e50;
    transition: color 0.2s ease;
}

.site-header-brand:hover .site-header-title {
    color: #3498db;
}

/* --- Header Logo (after title) --- */
.site-header-logo {
    display: flex;
    align-items: center;
}

.site-header-logo .site-logo {
    height: 44px;
    width: auto;
}

.site-header-logo .logo-star {
    fill: #d4a537;
    stroke: #d4a537;
    stroke-width: 2px;
}

.site-header-logo .logo-flourish {
    fill: #85c1e9;
    stroke: #85c1e9;
    stroke-width: 5px;
}

/* --- User Menu in Header --- */
.site-header-user {
    grid-column: 3;
    position: relative;
    display: flex;
    align-items: center;
    justify-self: end;
}

/* --- Navigation Drawer --- */
.nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--nav-drawer-width);
    height: 100vh;
    background-color: #ffffff;
    border-right: 1px solid var(--border-color);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
    z-index: 300;
    transform: translateX(-100%);
    transition: transform var(--nav-transition-speed) ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.nav-drawer.open {
    transform: translateX(0);
}

/* --- Drawer Header --- */
.nav-drawer-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-home-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.nav-home-link:hover {
    background-color: #f0f3f6;
}

.nav-home-icon {
    width: 20px;
    height: 20px;
    stroke: #95a5a6;
    transition: stroke 0.2s ease;
}

.nav-home-link:hover .nav-home-icon {
    stroke: #3498db;
}

.nav-drawer-logo {
    font-family: var(--serif-font);
    font-size: 1.3rem;
    font-weight: 600;
    color: #2c3e50;
    text-decoration: none;
    text-align: center;
    flex: 1;
    line-height: 1.3;
}

.nav-drawer-logo:hover {
    color: #3498db;
    text-decoration: none;
}

/* --- Navigation Menu --- */
.nav-menu {
    list-style: none;
    padding: 1rem 0;
    margin: 0;
    flex: 1;
}

.nav-menu-item {
    margin: 0;
}

.nav-menu-link {
    display: block;
    padding: 0.875rem 1.5rem;
    color: #34495e;
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.nav-menu-link:hover {
    background-color: #f8f9fa;
    color: #3498db;
    text-decoration: none;
    border-left-color: #3498db;
}

.nav-menu-link.active {
    background-color: #e8f4fc;
    color: #3498db;
    font-weight: 600;
    border-left-color: #3498db;
}

/* --- Guest Library Button (grayed, triggers promo) --- */
button.nav-guest-library {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    color: #95a5a6;
    font-weight: 500;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

button.nav-guest-library:hover {
    background-color: #f8f9fa;
    color: #7f8c8d;
    border-left-color: #bdc3c7;
}

.nav-library-icon {
    width: 18px;
    height: 18px;
    opacity: 0.6;
}

/* --- Submenu (for Resources / Your Notebook) --- */
.nav-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: #f0f3f6;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-menu-group.expanded .nav-submenu {
    max-height: 600px;
}

.nav-submenu-item {
    margin: 0;
}

.nav-submenu-link {
    display: block;
    padding: 0.75rem 1.5rem 0.75rem 2.5rem;
    color: #5a6a7a;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 400;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.nav-submenu-link:hover {
    color: #3498db;
    background-color: #f0f3f6;
    text-decoration: none;
    border-left-color: #3498db;
}

.nav-submenu-link.active {
    color: #3498db;
    font-weight: 500;
    background-color: #e8f4fc;
    border-left-color: #3498db;
}

/* --- Third-Level Submenu (Subsubmenu for Bookshelf) --- */
.nav-submenu-group {
    position: relative;
}

.nav-bookshelf-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-bookshelf-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.nav-subsubmenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 280px;
    overflow-y: auto;
}

.nav-subsubmenu-item {
    margin: 0;
}

.nav-subsubmenu-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.5rem 0.6rem 3.5rem;
    color: #6a7a8a;
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.nav-subsubmenu-link:hover {
    color: #3498db;
    background-color: #f0f3f6;
    text-decoration: none;
    border-left-color: #3498db;
}

.nav-book-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.nav-book-icon-star {
    color: #d4a537;
}

/* "All Books" link */
.nav-all-books-link {
    font-size: 0.8rem;
    color: #8a9aaa;
    padding-left: 3.5rem;
}

.nav-all-books-link:hover {
    color: #3498db;
}

/* History link icon */
.nav-history-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-history-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: #6a7a8a;
    transition: fill 0.15s ease;
}

.nav-history-link:hover .nav-history-icon {
    fill: #5b8fa8;
}

/* Account link with user icon */
.nav-account-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-account-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: #6a7a8a;
    transition: fill 0.15s ease;
}

.nav-account-link:hover .nav-account-icon {
    fill: #5b8fa8;
}

/* --- Group Toggle Button --- */
.nav-menu-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    color: #34495e;
    font-weight: 500;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-menu-group-toggle:hover {
    background-color: #f8f9fa;
    color: #3498db;
    border-left-color: #3498db;
}

.nav-menu-group-toggle.active {
    background-color: #e8f4fc;
    color: #3498db;
    font-weight: 600;
    border-left-color: #3498db;
}

.nav-menu-chevron {
    width: 18px;
    height: 18px;
    stroke: #95a5a6;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.nav-menu-group.expanded .nav-menu-chevron {
    transform: rotate(180deg);
}

/* Legacy submenu toggle (keep for backwards compatibility) */
.nav-menu-parent {
    display: flex;
    align-items: center;
}

.nav-menu-parent .nav-menu-link {
    flex: 1;
}

.nav-submenu-toggle {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.nav-submenu-toggle svg {
    width: 16px;
    height: 16px;
    stroke: #95a5a6;
    transition: transform 0.2s ease;
}

.nav-menu-item.expanded .nav-submenu-toggle svg {
    transform: rotate(180deg);
}

/* Legacy submenu expansion - now handled by .nav-menu-group.expanded */

/* --- Overlay --- */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--nav-overlay-color);
    z-index: 250;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--nav-transition-speed) ease, visibility var(--nav-transition-speed) ease;
}

.nav-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* --- Body offset when header is present --- */
body.has-site-header {
    padding-top: var(--nav-header-height);
    transition: margin-left var(--nav-transition-speed) ease;
}

/* --- Pin Toggle Button --- */
.nav-pin-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    align-items: center;
    justify-content: center;
}

.nav-pin-toggle:hover {
    background-color: #f0f3f6;
}

.nav-pin-toggle svg {
    width: 18px;
    height: 18px;
    stroke: #95a5a6;
    transition: stroke 0.2s ease;
}

.nav-drawer.pinned .nav-pin-toggle svg {
    stroke: #3498db;
}

/* --- Pin functionality for desktop --- */
@media (min-width: 1200px) {
    .nav-pin-toggle {
        display: flex;
    }

    .nav-drawer.pinned {
        transform: translateX(0);
        box-shadow: none;
    }

    body.nav-pinned {
        margin-left: var(--nav-drawer-width);
    }

    body.nav-pinned .site-header {
        left: var(--nav-drawer-width);
    }

    /* Simplified header when pinned - site name visible in main header */
    .nav-drawer.pinned .nav-drawer-header {
        position: relative;
        justify-content: center;
        height: var(--nav-header-height);
        padding-top: 0;
        padding-bottom: 0;
        box-sizing: border-box;
    }

    .nav-drawer.pinned .nav-drawer-logo {
        display: none;
    }

    .nav-drawer.pinned .nav-pin-toggle {
        position: absolute;
        right: 1rem;
    }

    /* Hide hamburger when drawer is pinned - pin icon is the only control */
    body.nav-pinned .menu-toggle {
        display: none;
    }
}

/* --- Responsive adjustments --- */
@media (max-width: 768px) {
    :root {
        --nav-drawer-width: 260px;
    }

    .site-header {
        padding: 0 1rem;
    }

    .nav-drawer-header {
        padding: 1rem;
    }

    .nav-menu-link,
    .nav-menu-group-toggle {
        padding: 0.75rem 1rem;
        padding-left: 1rem;
        border-left-width: 3px;
    }

    .nav-submenu-link {
        padding: 0.75rem 1rem 0.75rem 2rem;
    }
}

/* --- Article page menu icon (smaller, integrated) --- */
.article-menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    margin-right: 0.75rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.article-menu-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.article-menu-toggle .menu-toggle-bar {
    width: 18px;
    height: 2px;
    margin: 2px 0;
}


/* --- Site Footer --- */
.site-footer {
    margin-top: 3rem;
    padding: 2rem 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border-color, #e0e0e0);
    background-color: #f8f9fa;
}

.site-footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.site-footer-copyright {
    font-size: 0.875rem;
    color: #5a6a7a;
}

.site-footer-copyright a {
    color: #34495e;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.site-footer-copyright a:hover {
    color: #3498db;
}


/* --- Nav Drawer Article Context (when viewing an article) --- */

.nav-article-context .nav-menu-link.nav-menu-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-article-context .nav-menu-chevron.expanded {
    transform: rotate(180deg);
}

.nav-article-hierarchy {
    padding: 0.5rem 1.5rem 1rem;
    background-color: #f0f3f6;
    border-left: 3px solid #dde2e7;
    margin-left: 0;
}

a.nav-hierarchy-series {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #8b7355;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
    text-decoration: none;
    transition: color 0.15s ease;
}

a.nav-hierarchy-series:hover {
    color: #6d5a42;
    text-decoration: underline;
}

a.nav-hierarchy-topic {
    display: block;
    font-size: 0.95rem;
    font-weight: 500;
    color: #5a6a7a;
    margin-bottom: 0.75rem;
    text-decoration: none;
    transition: color 0.15s ease;
}

a.nav-hierarchy-topic:hover {
    color: #3498db;
    text-decoration: underline;
}

.nav-topic-articles {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-topic-article {
    margin: 0;
}

.nav-topic-article-link {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    color: #5a6a7a;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.nav-topic-article-link:hover {
    background-color: #f0f3f6;
    color: #3498db;
}

.nav-topic-article.current .nav-topic-article-link {
    background-color: #e8f4fc;
    color: #3498db;
    font-weight: 500;
}


