// CSS variables for pane dimensions (spine-based)

@font-face {
    font-family: "Zalando Sans";
    src: url("/assets/fonts/ZalandoSans-VariableFont_wdth,wght.ttf")
        format("truetype-variations");
    font-weight: 100 900;
    font-stretch: 75% 125%;
}

@font-face {
    font-family: "Zalando Sans";
    src: url("/assets/fonts/ZalandoSans-Italic-VariableFont_wdth,wght.ttf")
        format("truetype-variations");
    font-weight: 100 900;
    font-stretch: 75% 125%;
    font-style: italic;
}

:root {
    --spine-width: 40px;
    --card-width: 800px; // matches original --pane-width
    --last-card-width: var(--card-width);
    --text-wght: 400;
    --text-wdth: 115;
    --text-opsz: 100;
    --text-GRAD: 100;
}

@property --top-fade {
    syntax: "<length>";
    inherits: false;
    initial-value: 0;
}

@property --bottom-fade {
    syntax: "<length>";
    inherits: false;
    initial-value: 0;
}

// Sidebar
.side-bar {
    background-color: if($color-scheme == 'dark', darken($sidebar-color, 3%), $sidebar-color);
}

.site-logo, .home-logo {
    filter: if($color-scheme == 'dark', invert(1) brightness(2), none);
}

// Footer
.site-footer {
    color: if($color-scheme == 'dark', $grey-lt-300, $grey-dk-000);
}

footer {
    p.text-grey-dk-100,
    p.text-grey-dk-000,
    a {
        color: if($color-scheme == 'dark', $grey-lt-300, null) !important;
    }
}

.nav-footer-custom {
    width: 100%;
    display: flex;
    justify-content: flex-end;
}

// Main Content
.main-content {
    ul {
        > li {
            &::before {
                position: relative;
                margin-left: -1em;
                color: $grey-dk-000;
                content: "•";
                padding-right: 0.5em;
            }
        }
    }
}

// External link
// ----------------------------------------
a {
    &[href^="http"] {
        &:not([href*="oxibase.xyz"]) {
            &:not([href*="localhost"]) {
                &:not([href*="0.0.0.0"]) {
                    &::after {
                        content: " [↗]";
                        font-size: 0.6em;
                        margin-left: 4px;
                        vertical-align: super;
                    }
                }
            }
        }
    }
}

// Wide navigation
// ----------------------------------------

// Wide view toggle button (shadcn UI style)
.wide-view-toggle {
    display: none;

    @include mq(md) {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.3rem 0.6rem;
        border: 1px solid $border-color;
        border-radius: 0.375rem;
        background: $body-background-color;
        color: $body-text-color;
        font-size: 0.875rem;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        user-select: none;
        margin: 0.5rem 0.5rem;

        &:hover {
            background: $sidebar-color;
            border-color: $border-color;
            box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
        }

        &:active {
            transform: scale(0.98);
        }

        input {
            display: none;

            &:checked + svg {
                color: $link-color;
            }

            &:checked ~ span {
                color: $link-color;
            }
        }
    }
}

.search-active {
    .search {
        z-index: 101;
    }
    .search-overlay {
        z-index: 100;
    }
}

// Remove max-width from .main to allow wider layout
.main {
    max-width: none;
}

// Panes navigation
// ----------------------------------------
// Sliding panes styles (spine-based)
.panes-container {
    display: flex;
    height: calc(100vh - 60px);
    overflow-x: auto;
    gap: 1rem;
    scroll-behavior: smooth;
    view-timeline-name: --cards-element-scrolls-in-body;
    view-timeline-axis: inline;

    @include mq(md) {
        padding-right: 2rem;
    }
}

.pane {
    height: inherit;
    margin-top: auto;
    margin-bottom: auto;
    background-color: $body-background-color;

    --index0: calc(var(--index) - 1);
    --reverse-index: calc(var(--numcards) - var(--index));

    position: sticky;
    left: calc((var(--index0) * var(--spine-width)));
    z-index: var(--index);

    @include mq(md) {
        flex: 0 0 var(--card-width);
        width: var(--card-width);
        max-width: 80vw;
        --actual-width: min(var(--card-width), 80vw);
        right: calc(-1 * (var(--actual-width) - (var(--reverse-index) + 1) * var(--spine-width)));
    }

    &:last-child {
        z-index: calc(var(--numcards));

        @include mq(md) {
            width: var(--last-card-width);
            flex: 0 0 var(--last-card-width);
            --actual-width: var(--last-card-width);
        }
    }

    &:only-of-type {
        .pane-header {
            display: none;
        }
    }
}

// Card content and spine structure
.pane-content {
    height: 100%;
    width: 100%;
    border-right: 1px solid $border-color;
    box-shadow:
        -4px 0 10px rgba(0, 0, 0, 0.05),
        0 0 0 1px rgba(0, 0, 0, 0.02);
    overflow: hidden;
    display: flex;
    flex-direction: row;

    // Animation Logic
    --start-range: calc(var(--index0) / var(--numcards) * 100%);
    --end-range: calc((var(--index)) / var(--numcards) * 100%);

    animation: linear scale forwards;
    animation-timeline: --cards-element-scrolls-in-body;
    animation-range: exit-crossing var(--start-range) exit-crossing
        var(--end-range);

    transform-origin: left center;
}

@keyframes scale {
    to {
        filter: brightness(0.92);
    }
}

// Spine (header) on left
.pane-header {
    height: 100%;
    width: var(--spine-width);
    flex-shrink: 0;
    border-right: 1px solid $border-color;
    background-color: if($color-scheme == 'dark', darken($sidebar-color, 3%), $sidebar-color);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    padding: 1rem 0;
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    flex-direction: row-reverse;

    @include fs-3;

    &:hover {
        background-color: if($color-scheme == 'dark', darken($sidebar-color, 6%), $feedback-color);
    }
}

// Body content

@keyframes scrollfade {
    0% {
        --top-fade: 0;
    }
    10%,
    100% {
        --top-fade: 5rem;
    }
    0%,
    90% {
        --bottom-fade: 5rem;
    }
    100% {
        --bottom-fade: 0;
    }
}

.pane-body {
    padding: 2rem;
    flex-grow: 1;
    overflow-y: auto;
    min-width: 0;
    background: linear-gradient(
        to bottom,
        $body-background-color,
        rgba(0,0,0,0) var(--top-fade) calc(100% - var(--bottom-fade)),
        $body-background-color
    );
    mask: linear-gradient(
        to bottom,
        #0000,
        #ffff var(--top-fade) calc(100% - var(--bottom-fade)),
        #0000
    );
    animation: scrollfade;
    animation-timeline: --scrollfade;
    scroll-timeline: --scrollfade y;
    scroll-snap-type: y mandatory;
}

// Adjust sidebar and main layout for wide view (narrow sidebar)
.wide-view {
    --sidebar-width: 16.5rem;
}

.wide-view .side-bar {
    @include mq(md) {
        width: var(--sidebar-width);
    }
}

.wide-view .main {
    @include mq(md) {
        margin-left: var(--sidebar-width);
    }
}

// Enable transitions after initial load
.has-transition .side-bar {
    @include mq(md) {
        transition: width 0.3s ease;
    }
}

.has-transition .main {
    transition: margin 0.3s ease;
}

// Table adjustments
// ---------------------------------------
table {
    th {
        background-color: darken($table-background-color, 6%);
    }
}

// SVG Zoom Modal Styles
// ---------------------------------------
.svg-pan-expand-btn, .svg-pan-reset-btn {
    position: absolute;
    z-index: 9999;
    cursor: pointer;
    background: if($color-scheme == 'dark', rgba(0, 0, 0, 0.7), rgba(255, 255, 255, 0.9));
    border-radius: 4px;
    padding: 6px;
    display: none;
    color: if($color-scheme == 'dark', #ccc, #333);
    transition: background 0.1s;
    height: 32px;
    width: 32px;
    
    &:hover {
        background: if($color-scheme == 'dark', #000, white);
        color: if($color-scheme == 'dark', white, black);
    }
}

.svg-pan-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;

    &.active {
        opacity: 1;
        pointer-events: all;
    }
}

.svg-pan-modal-content {
    width: 80vw;
    height: 80vh;
    background: $body-background-color;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid $border-color;

    svg {
        width: 100%;
        height: 100%;
        display: block;
    }
}

.svg-pan-modal-close, .svg-pan-modal-reset {
    position: absolute;
    top: 15px;
    background: if($color-scheme == 'dark', rgba(255,255,255,0.1), rgba(255,255,255,0.8));
    border: 1px solid $border-color;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.2s;
    color: $body-text-color;

    &:hover {
        background: if($color-scheme == 'dark', rgba(255,255,255,0.2), white);
    }
}

.svg-pan-modal-close {
    right: 15px;
    font-weight: bold;
    font-size: 18px;
}

.svg-pan-modal-reset {
    right: 60px;
}


h1,
h2,
h3,
h4,
h5,
h6 {
    font-family:
        "Zalando Sans",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    font-variation-settings:
        "wght" var(--text-wght),
        "wdth" var(--text-wdth),
        "opsz" var(--text-opsz),
        "GRAD" var(--text-GRAD);
}
