:root {
    color-scheme: dark;

    --background: #0d0f12;
    --surface: #15181d;
    --surface-elevated: #1c2026;
    --surface-hover: #232831;
    --border: #303640;
    --border-strong: #444c59;

    --text: #f5f7fa;
    --text-muted: #9ca5b2;
    --text-subtle: #707987;

    --primary: #29befd;
    --primary-hover: #54caff;
    --primary-text: #06141b;

    --danger: #f43256;
    --danger-hover: #ff5876;

    --success: #47e6c1;
    --warning: #ffb000;

    --shadow:
        0 18px 50px rgb(0 0 0 / 28%);

    --radius-small: 8px;
    --radius: 12px;
    --radius-large: 18px;

    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(
            circle at 15% 0%,
            rgb(41 190 253 / 8%),
            transparent 35rem
        ),
        var(--background);
}

body.dialog-open {
    overflow: hidden;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    color: inherit;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

[hidden] {
    display: none !important;
}

.brand-mark {
    display: grid;
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    place-items: center;
    border: 1px solid rgb(41 190 253 / 35%);
    border-radius: 16px;
    color: var(--primary);
    background: rgb(41 190 253 / 10%);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.brand-mark-small {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    font-size: 12px;
}

/* Buttons */

.button,
.icon-button,
.text-button {
    border: 0;
    cursor: pointer;
}

.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    transition:
        border-color 120ms ease,
        background 120ms ease,
        opacity 120ms ease,
        transform 120ms ease;
}

.button:hover {
    text-decoration: none;
    transform: translateY(-1px);
}

.button:active {
    transform: translateY(0);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.button-primary {
    color: var(--primary-text);
    background: var(--primary);
}

.button-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.button-secondary {
    border-color: var(--border);
    color: var(--text);
    background: var(--surface-elevated);
}

.button-secondary:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.button-danger {
    color: #fff;
    background: var(--danger);
}

.button-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.button-large {
    min-height: 46px;
    padding-right: 20px;
    padding-left: 20px;
}

.icon-button {
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface-elevated);
}

.icon-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.text-button {
    padding: 4px;
    color: var(--primary);
    background: transparent;
}

.text-button:hover {
    text-decoration: underline;
}

/* Forms */

.form-stack {
    display: grid;
    gap: 18px;
}

.field {
    display: grid;
    gap: 8px;
}

.field-label {
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.field-optional {
    margin-left: 4px;
    color: var(--text-subtle);
    font-size: 12px;
    font-weight: 500;
}

.field-help {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
}

.field input {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    outline: 0;
    color: var(--text);
    background: #101318;
    transition:
        border-color 120ms ease,
        box-shadow 120ms ease;
}

.field input::placeholder {
    color: var(--text-subtle);
}

.field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(41 190 253 / 14%);
}

.checkbox-field {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}

.checkbox-field input {
    width: 17px;
    height: 17px;
    margin: 2px 0 0;
    accent-color: var(--primary);
}

.form-message {
    margin: 0;
    padding: 11px 12px;
    border-radius: var(--radius-small);
    font-size: 14px;
    line-height: 1.5;
}

.form-message-error {
    border: 1px solid rgb(244 50 86 / 35%);
    color: #ff9aac;
    background: rgb(244 50 86 / 10%);
}

/* Login */

.login-page,
.admin-page {
    min-height: 100vh;
}

.login-container {
    display: grid;
    min-height: 100vh;
    padding:
        max(24px, env(safe-area-inset-top))
        max(18px, env(safe-area-inset-right))
        max(24px, env(safe-area-inset-bottom))
        max(18px, env(safe-area-inset-left));
    place-items: center;
}

.login-card {
    width: min(100%, 420px);
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    background: rgb(21 24 29 / 94%);
    box-shadow: var(--shadow);
}

.login-heading {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.login-heading h1 {
    margin: 0 0 5px;
    font-size: 24px;
}

.login-heading p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 14px;
}

/* Top bar */

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    border-bottom: 1px solid var(--border);
    background: rgb(13 15 18 / 88%);
    backdrop-filter: blur(18px);
}

.topbar-content {
    display: flex;
    width: min(100%, 1440px);
    min-height: 72px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin: 0 auto;
    padding:
        10px
        max(20px, env(safe-area-inset-right))
        10px
        max(20px, env(safe-area-inset-left));
}

.topbar-title {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
}

.topbar-title h1 {
    overflow: hidden;
    margin: 0 0 3px;
    font-size: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-title p {
    overflow: hidden;
    margin: 0;
    color: var(--text-muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 10px;
}

/* Shared sections */

.gallery-container,
.admin-container {
    width: min(100%, 1440px);
    margin: 0 auto;
    padding:
        28px
        max(20px, env(safe-area-inset-right))
        max(60px, env(safe-area-inset-bottom))
        max(20px, env(safe-area-inset-left));
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.section-heading h2 {
    margin: 0;
    font-size: 18px;
}

.section-heading p {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.section-meta {
    color: var(--text-muted);
    font-size: 13px;
}

.empty-state {
    display: grid;
    min-height: 220px;
    padding: 30px;
    place-items: center;
    align-content: center;
    gap: 10px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
}

.empty-state strong {
    color: var(--text);
}

.empty-state p {
    margin: 0;
}

.loading-spinner {
    width: 25px;
    height: 25px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Upload */

.upload-panel {
    display: grid;
    min-height: 150px;
    margin-bottom: 30px;
    padding: 24px;
    place-items: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-large);
    background: rgb(21 24 29 / 72%);
    cursor: pointer;
    transition:
        border-color 140ms ease,
        background 140ms ease,
        transform 140ms ease;
}

.upload-panel:hover,
.upload-panel.is-dragging {
    border-color: var(--primary);
    background: rgb(41 190 253 / 7%);
}

.upload-panel.is-dragging {
    transform: scale(1.005);
}

.upload-drop-content {
    display: flex;
    align-items: center;
    gap: 18px;
    pointer-events: none;
}

.upload-icon {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    color: var(--primary-text);
    background: var(--primary);
    font-size: 28px;
    line-height: 1;
}

.upload-drop-content strong {
    display: block;
    margin-bottom: 4px;
}

.upload-drop-content p {
    margin: 0 0 5px;
    color: var(--text-muted);
    font-size: 14px;
}

.upload-drop-content small {
    color: var(--text-subtle);
}

.upload-queue-section {
    margin-bottom: 30px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.upload-queue {
    display: grid;
    gap: 10px;
}

.upload-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: var(--radius-small);
    background: var(--surface-elevated);
}

.upload-item-main {
    min-width: 0;
}

.upload-item-name {
    overflow: hidden;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-item-progress {
    overflow: hidden;
    height: 5px;
    border-radius: 999px;
    background: var(--border);
}

.upload-item-progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transition: width 160ms ease;
}

.upload-item-status {
    color: var(--text-muted);
    font-size: 12px;
}

.upload-item.is-success .upload-item-progress-bar {
    background: var(--success);
}

.upload-item.is-error .upload-item-progress-bar {
    background: var(--danger);
}

/* Gallery */

.gallery-section {
    min-height: 300px;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
}

.image-card {
    position: relative;
    overflow: hidden;
    min-width: 0;
    aspect-ratio: 1;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
}

.image-card::after {
    position: absolute;
    inset: 0;
    border: 1px solid rgb(255 255 255 / 7%);
    border-radius: inherit;
    content: "";
    pointer-events: none;
}

.image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transform: scale(1.015);
    transition:
        opacity 180ms ease,
        transform 180ms ease;
}

.image-card.is-loaded img {
    opacity: 1;
}

.image-card:hover img {
    transform: scale(1.045);
}

.image-card-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--text-subtle);
    font-size: 12px;
}

.image-card.is-loaded .image-card-placeholder {
    display: none;
}

.load-more-sentinel {
    height: 1px;
}

.load-more-status {
    padding: 22px;
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
}

/* Image viewer */

.image-viewer {
    width: 100vw;
    max-width: none;
    height: 100vh;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    color: var(--text);
    background: transparent;
}

.image-viewer::backdrop {
    background: rgb(0 0 0 / 88%);
}

.viewer-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 88%);
}

.viewer-content {
    position: fixed;
    z-index: 1;
    inset: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.viewer-header {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding:
        max(12px, env(safe-area-inset-top))
        max(16px, env(safe-area-inset-right))
        12px
        max(16px, env(safe-area-inset-left));
    background: rgb(0 0 0 / 48%);
}

.viewer-information {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.viewer-information strong,
.viewer-information span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-information span {
    color: var(--text-muted);
    font-size: 12px;
}

.viewer-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
}

.viewer-image-area {
    position: relative;
    display: grid;
    min-height: 0;
    place-items: center;
    padding:
        16px
        max(58px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom))
        max(58px, env(safe-area-inset-left));
}

.viewer-image-area img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
}

.viewer-loading {
    position: absolute;
    z-index: 2;
    display: grid;
    place-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

.viewer-navigation {
    position: absolute;
    z-index: 3;
    top: 50%;
    display: grid;
    width: 42px;
    height: 54px;
    padding: 0;
    place-items: center;
    border: 1px solid rgb(255 255 255 / 12%);
    border-radius: 12px;
    color: #fff;
    background: rgb(0 0 0 / 45%);
    cursor: pointer;
    font-size: 34px;
    transform: translateY(-50%);
}

.viewer-navigation:hover {
    background: rgb(255 255 255 / 12%);
}

.viewer-navigation:disabled {
    visibility: hidden;
}

.viewer-navigation-previous {
    left: max(10px, env(safe-area-inset-left));
}

.viewer-navigation-next {
    right: max(10px, env(safe-area-inset-right));
}

/* Admin */

.admin-container {
    display: grid;
    gap: 28px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.stat-card {
    display: grid;
    min-height: 112px;
    align-content: center;
    gap: 10px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.stat-card span {
    color: var(--text-muted);
    font-size: 13px;
}

.stat-card strong {
    font-size: 25px;
}

.admin-section {
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    background: var(--surface);
}

.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
}

.data-table td {
    font-size: 14px;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.table-actions-column {
    width: 1%;
}

.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
}

.table-action-button {
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    background: var(--surface-elevated);
    cursor: pointer;
    font-size: 12px;
}

.table-action-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.table-action-button-danger {
    color: #ff91a5;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
}

.status-badge::before {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    content: "";
}

.status-badge-enabled {
    color: var(--success);
    background: rgb(71 230 193 / 9%);
}

.status-badge-enabled::before {
    background: var(--success);
}

.status-badge-disabled {
    color: var(--text-muted);
    background: rgb(156 165 178 / 9%);
}

.status-badge-disabled::before {
    background: var(--text-muted);
}

/* Dialogs */

.modal {
    width: min(calc(100% - 28px), 520px);
    max-height: calc(100vh - 28px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal::backdrop {
    background: rgb(0 0 0 / 72%);
    backdrop-filter: blur(3px);
}

.modal-card {
    display: grid;
    max-height: calc(100vh - 28px);
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 20px;
}

.modal-header {
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0 0 4px;
    font-size: 18px;
}

.modal-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.modal-body {
    overflow-y: auto;
    padding: 20px;
}

.modal-body p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.6;
}

.modal-body strong {
    color: var(--text);
}

.modal-footer {
    justify-content: flex-end;
    border-top: 1px solid var(--border);
}

/* Toast */

.toast-container {
    position: fixed;
    z-index: 100;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    display: grid;
    width: min(calc(100% - 36px), 360px);
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    color: var(--text);
    background: var(--surface-elevated);
    box-shadow: var(--shadow);
    font-size: 14px;
    line-height: 1.45;
    animation: toast-in 160ms ease-out;
}

.toast-success {
    border-color: rgb(71 230 193 / 36%);
}

.toast-error {
    border-color: rgb(244 50 86 / 45%);
}

.toast-warning {
    border-color: rgb(255 176 0 / 42%);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */

@media (max-width: 1100px) {
    .image-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .topbar-content {
        min-height: 64px;
    }

    .topbar-title .brand-mark {
        display: none;
    }

    .topbar-actions .button {
        padding-right: 12px;
        padding-left: 12px;
    }

    .gallery-container,
    .admin-container {
        padding-top: 18px;
    }

    .upload-panel {
        min-height: 130px;
    }

    .image-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 7px;
    }

    .admin-section {
        padding: 16px;
    }

    .section-heading {
        align-items: flex-start;
    }

    .data-table th,
    .data-table td {
        padding-right: 10px;
        padding-left: 10px;
    }
}

@media (max-width: 520px) {
    .login-card {
        padding: 22px;
    }

    .topbar-title h1 {
        max-width: 125px;
    }

    .topbar-title p {
        display: none;
    }

    .topbar-actions {
        gap: 7px;
    }

    .topbar-actions .button {
        min-height: 36px;
        padding: 7px 10px;
        font-size: 13px;
    }

    .upload-drop-content {
        display: grid;
        justify-items: center;
        text-align: center;
    }

    .image-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 9px;
    }

    .stat-card {
        min-height: 96px;
        padding: 15px;
    }

    .stat-card strong {
        font-size: 20px;
    }

    .section-heading {
        flex-wrap: wrap;
    }

    .viewer-header {
        min-height: 58px;
    }

    .viewer-information {
        max-width: 45%;
    }

    .viewer-navigation {
        width: 36px;
        height: 48px;
    }

    .viewer-image-area {
        padding-right: 45px;
        padding-left: 45px;
    }
}