html, body {
    margin: 0;
    min-height: 100%;
    font-family: Arial, Helvetica, sans-serif;
    background: #f3f4f1;
    color: #1e2528;
}

button, input, textarea {
    font: inherit;
}

.site-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.site-header, .site-footer {
    width: 100%;
    padding: 14px 22px;
    background: #ffffff;
    border-bottom: 1px solid #d8ddd8;
}

.site-footer {
    border-top: 1px solid #d8ddd8;
    border-bottom: 0;
}

.site-header h1 {
    margin: 0;
    font-size: 1.45rem;
}

.site-main {
    min-height: 0;
}

.gallery-layout, .admin-layout {
    height: calc(100dvh - 120px);
    min-height: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    overflow: hidden;
}

.left-column {
    width: clamp(280px, 30vw, 560px);
    min-width: 260px;
    max-width: 640px;
    resize: horizontal;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    padding: 14px;
    background: #e8ece7;
    border-right: 3px solid #aab3ad;
}

.left-column h2 {
    margin: 18px 0 10px;
    font-size: 1rem;
}

.center-column {
    min-width: 0;
    min-height: 0;
    padding: 20px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.login-panel {
    display: grid;
    gap: 8px;
}

.login-panel form, .current-user {
    display: grid;
    gap: 8px;
}

.user-summary {
    display: flex;
    align-items: baseline;
    gap: 4px;
    white-space: nowrap;
}

.sidebar-head {
    display: grid;
    gap: 10px;
    align-content: start;
    padding-bottom: 10px;
}

.album-tree-scroll {
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
}

.album-tree {
    list-style: none;
    margin: 0;
    padding-left: 0;
}

.album-tree .album-tree {
    margin-left: 20px;
}

.album-tree-item {
    margin: 2px 0;
}

.album-branch {
    display: block;
}

.album-row {
    min-height: 22px;
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    align-items: center;
}

.album-row::-webkit-details-marker {
    display: none;
}

.tree-caret {
    width: 0;
    height: 0;
    justify-self: center;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 5px solid #697674;
}

.album-branch[open] > .album-row .tree-caret {
    transform: rotate(90deg);
}

.tree-caret.empty {
    border: 0;
}

.album-node {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px;
    text-align: left;
    border: 0;
    border-radius: 3px;
    padding: 2px 4px;
    background: transparent;
    color: #1f2b2d;
    font-size: .86rem;
    line-height: 1.25;
    white-space: nowrap;
}

.album-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.album-count {
    color: #65706c;
    font-size: .78rem;
}

.album-node:hover, .album-node.selected {
    background: #cfd9d1;
}

.folder-icon {
    position: relative;
    width: 15px;
    height: 11px;
    display: inline-block;
    border: 1px solid #d1a80b;
    border-radius: 1px;
    background: linear-gradient(#ffe577, #f6c83a);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7);
}

.folder-icon::before {
    content: "";
    position: absolute;
    left: 1px;
    top: -4px;
    width: 7px;
    height: 4px;
    border: 1px solid #d1a80b;
    border-bottom: 0;
    border-radius: 1px 1px 0 0;
    background: #ffe577;
}

.album-heading {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 14px;
}

.album-heading h1 {
    margin: 0;
    font-size: 1.6rem;
}

.album-heading p {
    margin: 0;
    color: #5b6665;
}

.image-slider {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    gap: 12px;
    overflow: hidden;
}

.image-slider:focus {
    outline: none;
}

.selected-image {
    position: relative;
    height: 100%;
    min-height: 0;
    min-width: 0;
    display: grid;
    place-items: center;
    background: #f3f4f1;
    border-radius: 6px;
    cursor: zoom-in;
    overflow: hidden;
}

.selected-image img,
.selected-image video {
    display: block;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
}

.thumb-strip {
    min-height: 160px;
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    gap: 8px;
    align-items: center;
}

.thumb-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 150px;
    gap: 8px;
    overflow-x: auto;
    padding: 4px;
}

.thumb {
    position: relative;
    height: 148px;
    box-sizing: border-box;
    display: grid;
    border: 2px solid #c9d0ca;
    border-radius: 6px;
    background: #fff;
    padding: 5px;
    text-align: left;
    font-size: .72rem;
    color: #394344;
    overflow: hidden;
}

.thumb-select {
    min-width: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: 68px repeat(3, auto);
    gap: 2px;
    border: 0;
    background: transparent;
    padding: 0;
    color: inherit;
    text-align: inherit;
}

.thumb-select span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thumb.active {
    border-color: #0f766e;
    box-shadow: 0 0 0 2px rgba(15, 118, 110, .18);
}

.thumb img {
    width: calc(100% - 4px);
    height: 68px;
    object-fit: contain;
    object-position: center;
    border-radius: 4px;
    background: #dfe5df;
    justify-self: center;
    align-self: center;
}

.video-thumb {
    width: calc(100% - 4px);
    height: 68px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    border-radius: 4px;
    background: #1f2b2d;
    color: #fff;
    justify-self: center;
    align-self: center;
}

.video-play {
    font-size: 1.35rem;
    line-height: 1;
}

.video-label {
    font-size: .72rem;
    letter-spacing: 0;
}

.thumb-map {
    position: absolute;
    right: 6px;
    bottom: 6px;
    padding: 1px 5px;
    border: 1px solid #0f766e;
    border-radius: 4px;
    background: rgba(255, 255, 255, .92);
    color: #0f4f49;
    font-size: .68rem;
    line-height: 1.35;
    text-decoration: none;
}

.thumb-map:hover {
    background: #e6f4f1;
}

.image-nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    width: 38px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 1px solid #9aa7a1;
    border-radius: 4px;
    background: rgba(255, 255, 255, .86);
    color: #173a36;
    font-size: 1.4rem;
    line-height: 1;
    transform: translateY(-50%);
}

.image-nav:hover:not(:disabled) {
    background: #fff;
    border-color: #0f766e;
}

.image-nav:disabled {
    opacity: .35;
    cursor: default;
}

.image-nav-prev {
    left: 10px;
}

.image-nav-next {
    right: 10px;
}

.public-slider .thumb-strip {
    min-height: 104px;
}

.public-slider .thumb-list {
    grid-auto-columns: 120px;
}

.public-slider .thumb {
    height: 92px;
    align-content: start;
    justify-items: center;
    padding: 4px 4px 3px;
}

.public-slider .thumb-select {
    grid-template-rows: 79px;
}

.public-slider .thumb img {
    width: 100%;
    height: 79px;
    max-width: 100%;
    max-height: 100%;
    margin-top: 0;
    object-fit: contain;
}

.public-slider .video-thumb {
    width: 100%;
    height: 79px;
}

.icon-button {
    width: 38px;
    height: 38px;
    border: 1px solid #9aa7a1;
    border-radius: 6px;
    background: #fff;
}

.details-band, .admin-tools, .editor-row, .upload-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    padding: 10px;
    background: #fff;
    border: 1px solid #d8ddd8;
    border-radius: 6px;
}

.details-band {
    min-height: 0;
    justify-content: space-between;
    padding: 6px 10px;
    flex-wrap: nowrap;
}

.image-description {
    min-width: 0;
    flex: 1 1 auto;
}

.details-band p {
    margin: 2px 0 0;
    color: #5b6665;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.comment-form {
    flex: 0 1 min(1040px, 75%);
    display: flex;
    align-items: center;
    gap: 6px;
}

.comment-form textarea {
    min-height: 30px;
    height: 30px;
    resize: none;
}

.comment-form button {
    white-space: nowrap;
}

.fullscreen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    background: #f3f4f1;
    padding: 50px;
    box-sizing: border-box;
    overflow: hidden;
}

.fullscreen .image-nav {
    position: fixed;
    width: 44px;
    height: 60px;
}

.fullscreen .image-nav-prev {
    left: 16px;
}

.fullscreen .image-nav-next {
    right: 16px;
}

.fullscreen img,
.fullscreen video {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 100px);
    max-height: calc(100dvh - 100px);
    object-fit: contain;
}

.close-button {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: #fff;
}

.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    z-index: 1001;
    display: grid;
    place-items: center;
    background: rgba(17, 22, 21, .55);
}

.move-dialog, .confirm-dialog, .comments-dialog, .upload-dialog, .map-dialog {
    width: min(420px, calc(100vw - 28px));
    max-height: 80vh;
    overflow: auto;
    padding: 18px;
    background: #fff;
    border-radius: 8px;
}

.move-dialog {
    width: min(720px, calc(100vw - 28px));
    max-height: 88vh;
}

.upload-dialog {
    display: grid;
    gap: 8px;
    text-align: center;
}

.upload-dialog h2,
.upload-dialog p {
    margin: 0;
}

.upload-dialog strong {
    overflow-wrap: anywhere;
}

.comments-dialog {
    width: min(820px, calc(100vw - 28px));
    display: grid;
    gap: 12px;
}

.map-dialog {
    width: min(820px, calc(100vw - 28px));
    max-height: 86vh;
    display: grid;
    grid-template-rows: auto minmax(260px, 58vh);
    gap: 12px;
}

.map-frame {
    width: 100%;
    height: 100%;
    min-height: 260px;
    border: 1px solid #cbd3ce;
    border-radius: 6px;
}

.dialog-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dialog-title-row h2,
.comments-dialog p {
    margin: 0;
}

.comments-table td:first-child {
    white-space: nowrap;
}

.confirm-dialog {
    display: grid;
    gap: 12px;
}

.confirm-dialog h2, .confirm-dialog p {
    margin: 0;
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.admin-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    margin: 6px 0 0;
    overflow-x: auto;
}

.admin-tabs button {
    flex: 0 0 auto;
    border: 1px solid #acb7b0;
    border-radius: 5px;
    padding: 6px 8px;
    text-align: center;
    background: #fff;
    white-space: nowrap;
}

.admin-tabs button.active {
    background: #154c45;
    color: #fff;
}

.admin-main {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    align-content: stretch;
    gap: 14px;
    min-height: 0;
    overflow: hidden;
}

.admin-main > .editor-row,
.admin-main > .upload-row {
    min-height: max-content;
}

.reader-main {
    grid-template-rows: minmax(0, 1fr);
}

.cfg-editor {
    display: grid;
    gap: 10px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #d8ddd8;
}

.data-table th, .data-table td {
    padding: 8px;
    border-bottom: 1px solid #e5e8e4;
    text-align: left;
    vertical-align: top;
}

.empty-state {
    min-height: 180px;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid #d8ddd8;
    border-radius: 6px;
    color: #65706c;
}

#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
}

@media (max-width: 760px) {
    .gallery-layout, .admin-layout {
        display: block;
        height: auto;
        overflow: visible;
    }

    .center-column {
        display: block;
        overflow: visible;
    }

    .image-slider {
        height: auto;
        grid-template-rows: minmax(280px, 50vh) auto auto auto;
        overflow: visible;
    }

    .selected-image {
        min-height: 280px;
    }

    .details-band {
        flex-wrap: wrap;
    }

    .comment-form {
        flex-basis: 100%;
    }

    .left-column {
        width: 100%;
        max-width: none;
        resize: none;
        display: block;
        overflow: visible;
        border-right: 0;
        border-bottom: 3px solid #aab3ad;
    }

    .album-tree-scroll {
        overflow: visible;
    }

    .thumb-strip {
        grid-template-columns: repeat(4, auto);
    }

    .thumb-list {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .fullscreen {
        padding: 16px;
    }

    .fullscreen img,
    .fullscreen video {
        max-width: calc(100vw - 32px);
        max-height: calc(100dvh - 32px);
    }
}

/* Production guard: keep backend controls and map buttons stable even after cached or framework styles. */
.admin-layout .left-column {
    min-height: 0 !important;
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    overflow: hidden !important;
}

.admin-layout .sidebar-head {
    display: grid !important;
    gap: 10px !important;
    align-content: start !important;
}

.admin-layout .album-tree-scroll {
    min-height: 0 !important;
    overflow: auto !important;
}

.admin-layout .admin-tabs {
    display: flex !important;
    flex-flow: row nowrap !important;
    gap: 6px !important;
    overflow-x: auto !important;
}

.admin-layout .admin-tabs button {
    flex: 0 0 auto !important;
    width: auto !important;
    white-space: nowrap !important;
    padding: 6px 8px !important;
}

.thumb .thumb-map {
    position: absolute !important;
    right: 6px !important;
    bottom: 6px !important;
    width: auto !important;
    min-width: 0 !important;
    height: auto !important;
    padding: 1px 5px !important;
    border: 1px solid #0f766e !important;
    border-radius: 4px !important;
    background: rgba(255, 255, 255, .92) !important;
    color: #0f4f49 !important;
    font-size: .68rem !important;
    line-height: 1.35 !important;
    text-align: center !important;
}
