header {
    grid-area: header;

    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 0.0625rem solid black;
}

header > span {
    padding: 0.3rem;
    min-width: 35rem;

    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;

    background-color: var(--tertiary-background, #5f5f5f);
    border: 0.001rem solid white;
    border-radius: 0.5rem;
}

/* nav sidebar */
aside {
    grid-area: sidebar;

    position: relative;
    width: 3rem;
    padding: 0.5rem 0;

    border-right: 0.0625rem solid black;
}

aside nav ul {
    list-style: none;

    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

aside nav li {
    border-left: 2px solid transparent;
    transition: border-color 0.2s ease;
}

/* nesting makes sense here for pseudo-classes */
aside nav button,
aside nav a,
aside nav label {
    all: unset;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 3rem;
    cursor: pointer;
    transition: background-color 0.2s ease;

    &:hover {
        background-color: var(--hover-background, #2a2d2e);
    }
}

aside nav img {
    filter: brightness(0) invert(1);
    width: 2rem;
    height: 2rem;
}

main {
    display: contents;
}

/* file explorer stylings */
main file-explorer {
    grid-area: file-explorer;

    overflow-y: auto;
    padding: 0.5rem 0;

    background-color: var(--secondary-background, #2a2a2a);
    border-right: 0.0625rem solid #1a1a1a;
    font-size: 0.8125rem;
}

main file-explorer ul {
    list-style: none;
}

main file-explorer a {
    display: flex;
    text-decoration: none;
    cursor: pointer;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;

    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    line-height: 1.4;

    color: var(--text-color, white);
    font-size: 0.8125rem;

    transition: background-color 0.15s ease;

    &:hover {
        background-color: var(--hover-background, #2a2d2e);
    }

    &:active,
    &:focus,
    &.active {
        background-color: var(--active-background, #37373d);
        outline: none;
    }
}

main file-explorer img {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    filter: brightness(0) invert(1);
}

/* main content frame */
main iframe {
    grid-area: content;

    border: none;
    width: 100%;
    height: 100%;
}

/* footer */
footer {
    grid-area: footer;

    display: flex;
    padding: 0.25rem 1rem;

    background-color: var(--secondary-background, #2a2a2a);
    font-size: 0.75rem;
}

/* media query for tablet */
@media (max-width: 768px) {
    body {
        grid-template-rows: 2.75rem 1fr 1.5rem; /* Increased header height */
    }

    body:has(#file-explorer-toggle:checked) {
        grid-template-columns: 2.5rem 10rem 1fr;
    }

    body:has(#file-explorer-toggle:not(:checked)) {
        grid-template-columns: 2.5rem 0 1fr;
    }

    header > span {
        min-width: auto;
        width: min(70%, 25rem); /* Narrower and responsive */
        font-size: 0.8125rem;
        padding: 0.35rem 0.75rem; /* More vertical padding */
    }

    aside {
        width: 2.5rem;
        height: calc(100dvh - 4.25rem); /* Adjusted for new header height */
    }

    aside nav button,
    aside nav a,
    aside nav label {
        height: 2.5rem;
    }

    aside nav img {
        width: 1.75rem;
        height: 1.75rem;
    }

    main file-explorer {
        font-size: 0.75rem;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
    }

    main file-explorer a {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        gap: 0.375rem;
    }

    main file-explorer img {
        width: 0.875rem;
        height: 0.875rem;
    }

    footer {
        font-size: 0.625rem;
        padding: 0.25rem 0.5rem;
    }
}

/* media query for mobile */
@media (max-width: 480px) {
    body {
        grid-template-rows: 2.5rem 1fr 1.125rem; /* Increased header height */
        grid-template-columns: 2rem 0 1fr !important;
    }

    /* override the grid column changes for mobile */
    body:has(#file-explorer-toggle:checked) {
        grid-template-columns: 2rem 0 1fr !important;
    }

    body:has(#file-explorer-toggle:not(:checked)) {
        grid-template-columns: 2rem 0 1fr !important;
    }

    header > span {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem; /* More vertical padding */
        width: min(75%, 18rem); /* Narrower and responsive */
    }

    aside {
        width: 2rem;
        height: calc(100dvh - 3.625rem); /* Adjusted for new header height */
    }

    aside nav button,
    aside nav a,
    aside nav label {
        height: 2rem;
    }

    aside nav img {
        width: 1.25rem;
        height: 1.25rem;
    }

    /* overlay approach for mobile */
    main file-explorer {
        position: fixed;
        left: 2rem;
        top: 2.5rem; /* Adjusted for new header height */
        bottom: 1.125rem;
        width: 12rem;
        z-index: 1000;

        font-size: 0.6875rem;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);

        /* Smooth slide-in animation */
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    /* Show file explorer as overlay when checked */
    body:has(#file-explorer-toggle:checked) main file-explorer {
        display: block;
        transform: translateX(0);
    }

    main file-explorer a {
        padding: 0.3rem 0.4rem;
        font-size: 0.6875rem;
    }

    footer {
        font-size: 0.5625rem;
    }
}
