:root {
    color-scheme: dark;
    --bg: #000000;
    --panel: #111111;
    --panel-2: #151515;
    --border: #232323;
    --border-2: #2d2d2d;
    --text: #f4f4f4;
    --muted: #9b9b9b;
    --accent: #f1f1f1;
    --danger: #d85b5b;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    --radius: 18px;
    --radius-sm: 12px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    overflow-x: hidden;
}

img {
    max-width: 100%;
    display: block;
}

button, input {
    font: inherit;
}

.gallery-shell,
.admin-shell {
    width: min(1600px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 16px 0 32px;
}

.gallery-page {
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.03), transparent 34%),
        var(--bg);
}

.gallery-sections {
    display: grid;
    gap: 26px;
}

.gallery-section {
    display: grid;
    gap: 14px;
}

.gallery-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.gallery-separator {
    width: 100%;
    margin: 8px 0 0;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.thumb-card {
    appearance: none;
    border: 1px solid transparent;
    background: #050505;
    border-radius: var(--radius-sm);
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    box-shadow: none;
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.thumb-card:hover,
.thumb-card:focus-visible {
    transform: translateY(-2px);
    border-color: var(--border-2);
    box-shadow: var(--shadow);
    outline: none;
}

.thumb-card img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #070707;
}

.lightbox {
    position: fixed;
    inset: 0;
    display: none;
    align-items: stretch;
    justify-content: stretch;
    z-index: 50;
}

.lightbox.is-open {
    display: flex;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}

.lightbox-panel {
    position: relative;
    width: 100%;
    height: 100%;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 3;
    width: 52px;
    height: 52px;
    border-radius: 999px;
    border: 1px solid var(--border-2);
    background: rgba(10, 10, 10, 0.88);
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    width: clamp(52px, 6vw, 84px);
    height: clamp(92px, 18vh, 180px);
    border: 0;
    border-radius: 0;
    background: rgba(10, 10, 10, 0.84);
    color: var(--text);
    font-size: clamp(28px, 3vw, 44px);
    line-height: 1;
    cursor: pointer;
    opacity: 0.2;
    transition: opacity 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.lightbox-nav:hover,
.lightbox-nav:focus-visible {
    opacity: 1;
    background: rgba(10, 10, 10, 0.96);
    outline: none;
}

.lightbox-nav:disabled {
    cursor: default;
    pointer-events: none;
}

.lightbox-nav-prev {
    left: 0;
    border-top-right-radius: 18px;
    border-bottom-right-radius: 18px;
}

.lightbox-nav-next {
    right: 0;
    border-top-left-radius: 18px;
    border-bottom-left-radius: 18px;
}

.viewer-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
}

.pano-viewer {
    position: absolute;
    inset: 0;
    background: #000;
}

.pano-viewer.is-flat {
    display: grid;
    place-items: center;
    background: #050505;
}

.flat-viewer-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    background: #050505;
}

.pano-viewer .pnlm-container {
    border-radius: 0;
}

.pano-viewer .pnlm-render-container {
    background: #000;
}

.viewer-fallback {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: #000;
    font-size: 14px;
    letter-spacing: 0.01em;
}

.location-overlay {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 4;
    display: grid;
    width: clamp(180px, 22vw, 280px);
    aspect-ratio: var(--viewport-aspect, 1.777);
    max-height: 30vh;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 14px;
    overflow: hidden;
    background: #090909;
    box-shadow: var(--shadow);
}

.location-link,
.location-empty {
    position: absolute;
    inset: 0;
}

.location-link {
    display: block;
}

.location-map {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.location-empty {
    display: grid;
    place-items: center;
    background: rgba(9, 9, 9, 0.94);
    color: var(--text);
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.location-overlay.has-location .location-empty {
    display: none;
}

.location-overlay:not(.has-location) .location-link {
    display: none;
}

.location-overlay .leaflet-container {
    background: #0b0b0b;
}

.location-overlay .leaflet-control-container {
    display: none;
}

.flash {
    margin: 0 0 16px;
    padding: 12px 14px;
    border: 1px solid var(--border-2);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
}

.flash-success {
    border-color: rgba(120, 180, 120, 0.4);
}

.flash-error {
    border-color: rgba(216, 91, 91, 0.5);
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.admin-header h1,
.panel h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 650;
    letter-spacing: 0.01em;
}

.panel {
    background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent 40%), var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.panel-heading {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}

.panel-heading p {
    margin: 6px 0 0;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(340px, 0.9fr);
    gap: 18px;
    align-items: start;
}

.admin-library-panel,
.admin-sidebar {
    min-width: 0;
}

.admin-sidebar {
    display: grid;
    gap: 18px;
}

.library-collapse-list {
    display: grid;
    gap: 14px;
    margin-top: 16px;
}

.library-group {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.015);
    overflow: hidden;
}

.library-group summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-weight: 650;
}

.library-group summary::-webkit-details-marker {
    display: none;
}

.library-group summary::after {
    content: '+';
    color: var(--muted);
    font-weight: 500;
}

.library-group[open] summary::after {
    content: '−';
}

.library-group .admin-list {
    margin: 0;
    padding: 14px;
}

.library-group-unassigned {
    opacity: 0.96;
}

.stack-form {
    display: grid;
    gap: 14px;
    margin-top: 14px;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.field {
    display: grid;
    gap: 8px;
    color: var(--muted);
}

.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="file"],
.field select {
    width: 100%;
    padding: 12px 14px;
    background: #0c0c0c;
    border: 1px solid var(--border-2);
    border-radius: 12px;
    color: var(--text);
}

.button {
    appearance: none;
    border: 1px solid var(--border-2);
    background: var(--accent);
    color: #000;
    border-radius: 999px;
    padding: 11px 18px;
    cursor: pointer;
    font-weight: 650;
}

.button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.button-ghost {
    background: #121212;
    color: var(--text);
}

.button-danger {
    background: rgba(216, 91, 91, 0.1);
    color: #ffb1b1;
    border-color: rgba(216, 91, 91, 0.32);
}

.inline-form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.admin-list {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.admin-row {
    display: grid;
    grid-template-columns: 168px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
}

.admin-thumb {
    width: 168px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 10px;
    background: #080808;
}

.admin-meta {
    min-width: 0;
}

.title-form input[type="text"] {
    min-width: min(420px, 100%);
}

.admin-paths {
    margin-top: 10px;
    color: var(--muted);
    overflow-wrap: anywhere;
    font-size: 13px;
    display: grid;
    gap: 4px;
}

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

.gallery-create-form {
    max-width: 520px;
}

.gallery-note {
    margin-top: 14px;
}

.upload-dropzone {
    position: relative;
    display: grid;
    gap: 12px;
    padding: 18px;
    border: 1px dashed rgba(255, 255, 255, 0.22);
    border-radius: 18px;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.05), transparent 40%),
        rgba(255, 255, 255, 0.02);
    transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.upload-dropzone.is-dragover {
    border-color: rgba(241, 241, 241, 0.75);
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.1), transparent 40%),
        rgba(255, 255, 255, 0.05);
    transform: translateY(-1px);
}

.upload-dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-dropzone-inner {
    display: grid;
    gap: 4px;
    pointer-events: none;
}

.upload-dropzone-inner strong {
    font-size: 15px;
    letter-spacing: 0.01em;
}

.upload-dropzone-inner span {
    color: var(--muted);
    font-size: 13px;
}

.upload-browse {
    justify-self: start;
    position: relative;
    z-index: 1;
}

.upload-file-list {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.upload-file-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--text);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.upload-file-item small {
    color: var(--muted);
    white-space: nowrap;
}

.upload-progress {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    padding: 14px 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
}

.upload-progress[hidden] {
    display: none;
}

.upload-progress-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
}

.upload-progress-head span:first-child {
    color: var(--text);
}

.upload-progress-head span:last-child {
    color: var(--muted);
}

.upload-progress-track {
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
}

.upload-progress-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #7ab7ff, #9ee7ff);
    transition: width 120ms linear;
}

.upload-progress-list {
    display: grid;
    gap: 8px;
}

.upload-progress-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--text);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.upload-progress-item small {
    color: var(--muted);
    white-space: nowrap;
}

.upload-progress-item[data-state="queued"] {
    opacity: 0.8;
}

.upload-progress-item[data-state="uploading"] {
    border-color: rgba(122, 183, 255, 0.35);
}

.upload-progress-item[data-state="done"] {
    border-color: rgba(125, 212, 163, 0.4);
}

.upload-progress-item[data-state="error"] {
    border-color: rgba(239, 113, 113, 0.5);
}

.upload-progress-item[data-state="paused"] {
    border-color: rgba(181, 125, 31, 0.55);
}

.upload-progress-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.gallery-admin-list {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.gallery-admin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
}

.gallery-title-form {
    flex: 1 1 auto;
    min-width: min(420px, 100%);
}

.library-section {
    margin-top: 20px;
}

.library-section-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.item-form {
    margin-top: 0;
}

.admin-meta .inline-form {
    flex-wrap: wrap;
}

@media (max-width: 900px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .admin-row {
        grid-template-columns: 1fr;
    }

    .field-grid {
        grid-template-columns: 1fr;
    }

    .admin-thumb {
        width: 100%;
    }

    .admin-actions,
    .title-form {
        flex-wrap: wrap;
    }

    .gallery-admin-row {
        flex-direction: column;
        align-items: stretch;
    }

    .gallery-title-form {
        min-width: 0;
    }

    .library-section-header {
        align-items: start;
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .gallery-shell,
    .admin-shell {
        width: min(100vw - 20px, 1600px);
        padding-top: 10px;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
    }

    .gallery-sections {
        gap: 20px;
    }

    .lightbox-close {
        top: 10px;
        right: 10px;
        width: 46px;
        height: 46px;
        font-size: 22px;
    }

    .location-overlay {
        right: 10px;
        bottom: 10px;
        width: clamp(150px, 32vw, 220px);
        max-height: 24vh;
    }

    .lightbox-nav {
        width: 42px;
        height: 72px;
        font-size: 26px;
    }
}
