:root {
    --radius: 14px;
    --sidebar-width: 284px;
}

body.theme-dark {
    --bg: #24282d;
    --panel: #2e333a;
    --panel-strong: #3a4048;
    --text: #ecf0f4;
    --muted: #c6ced8;
    --line: #606973;
    --accent: #91adc4;
    --input-bg: #252a30;
}

body.theme-light {
    --bg: #d8dadc;
    --panel: #f2f2f2;
    --panel-strong: #ffffff;
    --text: #1e2f40;
    --muted: #3b4a57;
    --line: #7c8894;
    --accent: #32506a;
    --input-bg: #f8fafb;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.app-shell {
    height: 100vh;
    overflow: hidden;
    gap: 24px;
    padding: 16px;
}

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--panel);
    border-radius: var(--radius);
    padding: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.28);
}

.sidebar hr {
    border-color: var(--line);
    opacity: 0.85;
    margin: 8px 0;
}

.user-row {
    background: var(--panel-strong);
    border-radius: 8px;
    min-height: 42px;
    padding: 0 8px;
    gap: 8px;
}

.user-name {
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
}

.sidebar-link {
    color: var(--text);
    display: block;
    padding: 2px 0;
    text-decoration: none;
}

.sidebar-link:hover {
    color: var(--accent);
}

.sidebar-scroll {
    overflow-y: auto;
    min-height: 120px;
}

.subdir-item {
    color: var(--text);
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 6px 0;
    text-decoration: none;
}

.subdir-item:hover {
    color: var(--accent);
}

.subdir-thumb {
    width: 70px;
    height: 45px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.subdir-fallback {
    width: 70px;
    height: 45px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 34px;
    line-height: 1;
}

.main-area {
    min-width: 0;
}

.top-bar {
    background: var(--panel);
    border-radius: 10px;
    min-height: 44px;
    padding: 4px 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.22);
}

.breadcrumb-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.crumb-link, .crumb-link-last {
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crumb-link-full {
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    max-width: 240px;
    white-space: nowrap;
}

.crumb-link:hover {
    color: var(--accent);
}

.crumb-sep {
    color: var(--muted);
}

.gallery-scroll {
    overflow-y: auto;
    min-height: 0;
    padding-top: 12px;
}

.gallery-grid {
    display: grid;
    /* Create as many fixed 128px columns as will fit and center them.
       `auto-fit` ensures the grid creates as many columns as possible
       while keeping each column exactly 128px. Use `justify-content:
       center` so the columns are centered on wider containers. */
    grid-template-columns: repeat(auto-fit, 128px);
    justify-content: center;
    gap: 24px; /* shorthand for row/column gaps */
    padding-bottom: 8px;
}

/* Image view specific styles */
.image-content {
    overflow: auto;
    flex: 1 1 auto; /* occupy available vertical space inside main-area */
    display: flex;
    align-items: center; /* center the image vertically */
    justify-content: center;
    box-sizing: border-box; /* include padding in height calculations */
}

.image-wrapper {
    /* Shrink-wrap exactly to the image. Using inline-block and zero
       line-height avoids extra inline spacing so the wrapper's width
       matches the rendered image width exactly. */
    display: inline-block;
    line-height: 0;
    border-radius: 14px;
    overflow: visible;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.35);
    /* Ensure the wrapper centers inside the flex parent. When the
       wrapping anchor is a flex container the wrapper is a flex item,
       so left/right auto margins will center it reliably. This fixes
       cases where the image appeared left-aligned. */
    margin-left: auto;
    margin-right: auto;
}

/* Ensure the clickable anchor that wraps the image fills the flex container
   so percentage-based heights on the inner wrapper/image resolve correctly. */
.image-content > a {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.image-full {
    display: block;
    /* Constrain by both available width and height. Use a viewport-based
       max-height to ensure the image never forces the page to scroll. The
       exact topbar/controls height can vary; 120px is a conservative
       approximation (top bar + padding). If you want pixel-perfect, we can
       compute this from the layout or expose a CSS variable. */
    max-width: calc(100%);
    max-height: calc(100vh - 120px);
    width: auto;
    height: auto;
    border-radius: 14px;
}

.info-menu {
    min-width: 275px;
    border-radius: 8px;
}

/* Ensure dropdowns follow the active theme and receive a subtle drop shadow */
.dropdown-menu {
    box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.5);
}

/* Dark theme specific dropdown styles */
body.theme-dark .dropdown-menu {
    background: var(--panel-strong);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

body.theme-dark .dropdown-menu .dropdown-item {
    color: var(--text);
}

body.theme-dark .dropdown-menu .dropdown-item:hover,
body.theme-dark .dropdown-menu .dropdown-item:focus {
    background: rgba(255, 255, 255, 0.03);
    color: var(--accent);
}

body.theme-dark .dropdown-menu .small,
body.theme-dark .dropdown-menu .text-muted {
    color: var(--muted);
}

/* Make muted/helper text readable in dark theme */
body.theme-dark .text-muted,
body.theme-dark .small.text-muted {
    /* use the theme text color with reduced opacity for contrast */
    color: rgba(236, 240, 244, 0.78) !important;
}

.thumb-card {
    width: 128px;
    display: block;
    border-radius: 14px;
    overflow: hidden;
    text-decoration: none;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.35);
}

.thumb-card img,
.thumb-fallback {
    width: 128px;
    height: 128px;
    object-fit: cover;
    border-radius: 14px;
    display: block;
    filter: brightness(1);
    transition: filter 0.25s ease;
}

.thumb-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 44px;
    background: var(--panel-strong);
}

.thumb-card:hover img,
.thumb-card:hover .thumb-fallback {
    filter: brightness(1.25);
}

.search-input,
.search-input:focus {
    background: var(--input-bg);
    color: var(--text);
    border-color: var(--line);
    box-shadow: none;
}

.search-input::placeholder {
    color: var(--muted);
    opacity: 1;
}

.search-input::-webkit-input-placeholder {
    color: var(--muted);
}

.search-input::-moz-placeholder {
    color: var(--muted);
    opacity: 1;
}

.search-addon {
    background: var(--input-bg);
    color: var(--muted);
    border-color: var(--line);
}

.btn-plain {
    color: var(--text);
    background: var(--panel-strong);
}

.btn-plain:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.offcanvas {
    background: var(--panel);
    color: var(--text);
    width: var(--sidebar-width) !important;
}

.offcanvas .sidebar {
    width: 100%;
    border-radius: 0;
    padding: 0;
    background: transparent;
}

.sort-menu {
    max-height: 220px;
    overflow-y: auto;
}

.sort-menu .dropdown-item {
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
}

.sort-menu .dropdown-item.active-sort {
    text-decoration: underline;
    background: transparent;
}

.login-form {
    background: var(--panel-strong);
    border-radius: 0 1rem 1rem 0;
}

.card {
    background: var(--bg);
}

media (max-width: 991.98px) {
    .app-shell {
        padding: 0px;
        gap: 12px;
    }

    .offcanvas {
        width: 100vw !important;
    }

    .top-bar {
        border-radius: 0px;
    }

    .crumb-link {
        display: none;
    }

    .crumb-sep {
        display: none;
    }

    .gallery-scroll {
        padding-left: 16px;
        padding-right: 16px;
    }
}
@media (max-width: 767px) {
    .login-form {
        background: var(--panel-strong);
        border-radius: 1rem 1rem 1rem 1rem;
    }
}

@media (max-width: 575.98px) {
    /* On narrow viewports keep the fixed 128px thumbnails but allow the
       grid to place as many side-by-side as fit. Reduce breadcrumb max
       width to preserve layout. */
    .crumb-link {
        max-width: 130px;
    }

    .crumb-link-full {
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@supports not (display: grid) {
    .gallery-grid {
        display: block;
    }

    .thumb-card {
        display: inline-block;
        margin: 0 24px 24px 0;
    }
}
