/* css/layout.css */

/* 1. Overall Page Structure & Centering - Updated Container Class
-------------------------------------------------------------------------------- */
body {
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 960px; /* Reduced from 1200px for better centering on large monitors */
    min-height: 100vh;
    margin-inline: auto; /* Modern logical property for centering */
    width: 100%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* 2. Enhanced Header (`<header>`) - Updated with Logo Styles
-------------------------------------------------------------------------------- */
header[role="banner"] {
    position: sticky;
    top: 0;
    min-height: 64px; /* Increased from 52px for better proportion */
    background-color: rgba(255, 255, 255, 0.85); /* Semi-transparent surface for glassy effect */
    backdrop-filter: blur(6px); /* Modern blur effect */
    -webkit-backdrop-filter: blur(6px); /* Safari compatibility */
    z-index: 1000;
    border-bottom: 1px solid rgba(46, 49, 69, 0.1); /* Translucent bottom border */
    box-shadow: 0 2px 6px rgba(0, 10, 40, 0.06); /* Consistent surface shadow */
    width: 100%;
    flex-shrink: 0;
}

/* Fallback for browsers that don't support backdrop-filter */
@supports not (backdrop-filter: blur(6px)) {
    header[role="banner"] {
        background-color: rgba(255, 255, 255, 0.95); /* More opaque fallback for legibility */
    }
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    height: 100%;
    max-width: 100%;
}

/* New branding container to replace header-title */
.header-branding {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-link {
    display: block;
    flex-shrink: 0;
    text-decoration: none;
    color: inherit;
    line-height: 0; /* Remove any line-height spacing */
}

/* Logo styling with high specificity to override base.css */
.header-branding .logo-link .header-logo {
    display: block !important;
    height: 44px !important;   /* Force explicit height */
    width: auto !important;    /* Maintain aspect ratio */
    max-height: 44px !important; /* Reinforce maximum height */
    max-width: 200px;  /* Add max-width constraint */
    min-height: 44px;  /* Ensure minimum height */
    border-radius: 0 !important; /* Remove rounded corners from base.css */
    object-fit: contain !important; /* Scale to fit within bounds */
    flex-shrink: 0;  /* Prevent flexbox from shrinking it */
}

.site-identity {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.site-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--clr-indigo);
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.logo-link:hover .header-logo {
    transform: scale(1.05);
    transition: transform 0.2s ease;
}

.logo-link:focus-visible {
    outline: 2px solid var(--clr-highlight);
    outline-offset: 2px;
    border-radius: 4px;
}

.header-tagline {
    font-size: 0.95rem;
    color: var(--clr-ink-light, #5a5f78);
    margin: 0;
    font-weight: 400;
    max-width: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* Space between action buttons */
}

.header-helper-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    min-width: auto; /* Allow button to size naturally */
}

.helper-btn-icon {
    font-size: 1.1em;
    line-height: 1;
}

.helper-btn-text {
    line-height: 1;
}

/* 3. Main Grid Container (`main.grid`)
-------------------------------------------------------------------------------- */
main.grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-areas: "sidebar main-content";
    gap: 1.5rem;
    padding: 1.5rem;
    flex-grow: 1;
    width: 100%;
    min-height: 0; /* Allow content to shrink if needed */
}

/* 4. Enhanced Sidebar (`.sidebar`)
-------------------------------------------------------------------------------- */
.sidebar[role="navigation"] {
    grid-area: sidebar;
    background-color: var(--clr-surface);
    padding: 1rem;
    border: 1px solid var(--clr-border); /* Full border for surface consistency */
    border-radius: 12px; /* Consistent surface styling */
    box-shadow: 0 2px 6px rgba(0, 10, 40, 0.06); /* Soft, consistent surface shadow */
    overflow-y: auto;
    height: fit-content; /* Allow sidebar to size to content */
    max-height: calc(100vh - 200px); /* Prevent sidebar from being too tall */
}

/* Enhanced sidebar group styling for better visual hierarchy */
.sidebar-group {
    margin-bottom: 0.75rem; /* Reduced spacing between groups */
}

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

.sidebar-group-toggle {
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.95rem; /* Slightly smaller for better proportion */
    color: var(--clr-indigo);
    background-color: var(--clr-surface);
    border: none;
    border-bottom: 1px solid var(--clr-border);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease-out, color 0.2s ease-out;
    border-radius: 0.375rem 0.375rem 0 0; /* Rounded top corners */
}

.sidebar-group:last-child .sidebar-group-toggle,
.sidebar-group-toggle[aria-expanded="true"] {
    border-bottom: none;
}

.sidebar-group-toggle:hover {
    background-color: var(--clr-lavender);
    color: var(--clr-indigo);
}

.sidebar-group-toggle::after {
    content: '+';
    font-size: 1.2em;
    font-weight: 400;
    color: var(--clr-indigo);
    transition: transform 0.2s ease-out;
    line-height: 1;
    min-width: 1.2em;
    text-align: center;
}

.sidebar-group-toggle[aria-expanded="true"]::after {
    content: '−';
}

.sidebar-group-content {
    background-color: var(--clr-surface);
    border-top: 1px solid var(--clr-border);
    border-radius: 0 0 0.375rem 0.375rem; /* Rounded bottom corners */
}

.sidebar-group-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-group-content li {
    margin: 0;
    position: relative; /* Allow absolute positioning for dot pseudo-element */
}

/* Navigation Links */
.sidebar-group-content li a {
    display: block;
    padding: 1rem 2rem 0.6rem 2.5rem; /* Extra left padding for dot */
    text-decoration: none;
    color: var(--clr-ink);
    font-size: 0.9rem;
    font-weight: 400;
    border-bottom: 1px solid var(--clr-border);
    transition: background-color 0.2s ease-out, color 0.2s ease-out, padding-left 0.2s ease-out, font-weight 0.2s ease-out;
    position: relative;
}

/* Dot/Icon Prefix */
.sidebar-group-content li a::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--clr-lavender);
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.2s ease-out, background-color 0.2s ease-out;
}

/* Remove border from last link */
.sidebar-group-content li:last-child a {
    border-bottom: none;
}

/* Link hover state */
.sidebar-group-content li a:hover {
    background-color: var(--clr-lavender);
    color: var(--clr-indigo);
    text-decoration: none;
    padding-left: 1.75rem; /* Slight indent on hover for visual feedback */
    font-weight: 600; /* Bold label on hover */
}

/* Dot hover effect - enlarge and change color */
.sidebar-group-content li a:hover::before {
    transform: translateY(-50%) scale(1.5); /* Enlarge dot on hover */
    background-color: var(--clr-indigo); /* Change dot color on hover */
}

/* Link focus state */
.sidebar-group-content li a:focus-visible {
    outline: 2px solid var(--clr-highlight);
    outline-offset: -2px;
    background-color: var(--clr-lavender);
    color: var(--clr-indigo);
    font-weight: 600; /* Bold on focus as well */
}

/* Focus state dot effect */
.sidebar-group-content li a:focus-visible::before {
    transform: translateY(-50%) scale(1.5);
    background-color: var(--clr-indigo);
}

/* Active/current page link styling */
.sidebar-group-content li a.current,
.sidebar-group-content li a[aria-current="page"] {
    background-color: var(--clr-indigo);
    color: var(--clr-surface);
    font-weight: 600; /* Bold for active state */
}

.sidebar-group-content li a.current::before,
.sidebar-group-content li a[aria-current="page"]::before {
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    height: auto;
    border-radius: 0;
    background-color: var(--clr-mint);
    transform: none; /* Reset dot transform for active indicator */
}

/* Active state still shows the navigation dot */
.sidebar-group-content li a.current::after,
.sidebar-group-content li a[aria-current="page"]::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--clr-surface);
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%) scale(1.3); /* Slightly larger for active state */
}

/* 5. Enhanced Content Area (`.content`)
-------------------------------------------------------------------------------- */
.content[role="main"] {
    grid-area: main-content;
    max-width: 680px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-bottom: 3rem;
}

/* Enhanced content navigation styling */
.content-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--clr-border);
}

/* Single button in navigation should center itself */
.content-navigation .btn:only-child {
    margin-left: auto;
    margin-right: auto;
}

/* Progress bar container styling */
.progress-bar-container {
    margin: 2rem 0;
    padding: 0.5rem 0; /* Add some breathing room */
}

/* 6. Enhanced Footer (`<footer>`)
-------------------------------------------------------------------------------- */
footer[role="contentinfo"] {
    padding: 2rem 1.5rem;
    background-color: var(--clr-surface);
    border-top: 1px solid var(--clr-border);
    box-shadow: 0 -2px 6px rgba(0, 10, 40, 0.06); /* Consistent surface shadow from above */
    text-align: center;
    font-size: 0.9rem;
    color: #5a5f78; /* Muted text color */
    width: 100%;
    flex-shrink: 0;
    margin-top: auto; /* Push footer to bottom */
}

footer[role="contentinfo"] p {
    margin-bottom: 0.5rem;
    max-width: none; /* Override paragraph width limit for footer */
}

footer[role="contentinfo"] p:last-child {
    margin-bottom: 0;
}

footer[role="contentinfo"] a {
    color: var(--clr-indigo);
    font-weight: 500;
}

/* 7. Enhanced Responsive Adjustments (Mobile <= 768px)
-------------------------------------------------------------------------------- */
@media (max-width: 768px) {
    main.grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "sidebar"
            "main-content";
        padding: 1rem;
        gap: 1rem;
    }

    main.grid > .sidebar, main.grid > .content {
        grid-area: auto;
    }

    header[role="banner"] {
        min-height: 60px; /* Slightly smaller on mobile */
    }

    .header-content {
        padding: 0.6rem 1rem;
    }
    
    /* Logo responsive adjustments with high specificity */
    .header-branding .logo-link .header-logo {
        height: 40px !important;
        max-height: 40px !important;
        min-height: 40px !important;
    }
    
    .site-identity {
        gap: 0.125rem; /* Tighter spacing on mobile */
    }
    
    .site-title {
        font-size: 1.5rem;
    }
    
    .header-tagline {
        font-size: 0.85rem;
    }

    .header-helper-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .helper-btn-text {
        display: none; /* Hide text on very small screens, keep icon */
    }

    .sidebar[role="navigation"] {
        border: 1px solid var(--clr-border); /* Full border maintained on mobile */
        border-radius: 12px 12px 0 0; /* Rounded top corners only on mobile */
        padding: 0.75rem;
        max-height: none; /* Remove height restriction on mobile */
    }

    .sidebar-group-toggle {
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    .sidebar-group-content li a {
        padding: 0.5rem 0.75rem 0.5rem 1.25rem; /* Adjusted for mobile with dot space */
        font-size: 0.85rem;
    }

    .sidebar-group-content li a::before {
        left: 0.625rem; /* Adjust dot position for mobile */
    }

    .sidebar-group-content li a:hover {
        padding-left: 1.5rem; /* Adjusted hover indent for mobile */
    }

    /* Mobile active state adjustments */
    .sidebar-group-content li a.current::after,
    .sidebar-group-content li a[aria-current="page"]::after {
        left: 0.625rem; /* Adjust active dot position for mobile */
    }

    .content[role="main"] {
        padding: 0 0.5rem 2rem 0.5rem;
    }

    .content-navigation {
        flex-direction: column;
        gap: 0.75rem;
    }

    .content-navigation .btn {
        width: 100%; /* Full width buttons on mobile */
    }

    footer[role="contentinfo"] {
        padding: 1.5rem 1rem;
        font-size: 0.85rem;
    }
}

/* 8. Enhanced spacing for very small screens */
@media (max-width: 480px) {
    .header-content {
        padding: 0.5rem 0.75rem;
    }

    /* Logo adjustments for very small screens */
    .header-branding .logo-link .header-logo {
        height: 36px !important;
        max-height: 36px !important;
        min-height: 36px !important;
    }
    
    .site-title {
        font-size: 1.3rem;
    }
    
    .header-tagline {
        font-size: 0.8rem;
        display: none; /* Hide tagline on very small screens to save space */
    }

    .helper-btn-icon {
        font-size: 1.2em;
    }

    main.grid {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .sidebar[role="navigation"] {
        padding: 0.5rem;
        border-radius: 8px 8px 0 0; /* Smaller radius on very small screens */
    }

    .content[role="main"] {
        padding: 0 0.25rem 1.5rem 0.25rem;
    }
}