:root {
    color-scheme: light;
    --ink: #172033;
    --muted: #657187;
    --line: #dce3ef;
    --blue: #1668e3;
    --cyan: #0aa6b7;
    --green: #14a36f;
    --red: #d9364e;
    --yellow: #f0b429;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --shadow: 0 18px 55px rgba(23, 32, 51, 0.14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(22, 104, 227, 0.18), transparent 32rem),
        linear-gradient(135deg, #f9fbff 0%, #eef7f4 48%, #fff7e2 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

button,
.button-link {
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
    cursor: pointer;
    font-weight: 700;
    min-height: 44px;
    padding: 0 18px;
    text-decoration: none;
}

button:hover,
.button-link:hover {
    filter: brightness(0.97);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.button-link.is-disabled {
    pointer-events: none;
    opacity: 0.55;
}

.ghost {
    color: var(--ink);
    background: #eef3fb;
}

.danger {
    color: #fff;
    background: var(--red);
}

.danger.ghost {
    color: var(--red);
    background: #fff0f3;
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.is-login .shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.login-panel,
.app-panel {
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.login-panel {
    width: min(440px, 100%);
    padding: 30px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    display: grid;
    width: 54px;
    height: 54px;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, var(--blue), var(--green));
    font-size: 24px;
    font-weight: 900;
}

.brand h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.05;
}

.brand p {
    margin: 5px 0 0;
    color: var(--muted);
}

.brand-small .brand-mark {
    width: 46px;
    height: 46px;
}

.brand-small h1 {
    font-size: 22px;
}

.login-form {
    display: grid;
    gap: 16px;
    margin-top: 28px;
}

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 700;
}

input[type="text"],
input[type="password"],
input[name="username"],
input[name="password"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    min-height: 48px;
    padding: 0 14px;
}

.form-message {
    min-height: 22px;
    margin: 0;
    color: var(--red);
    font-weight: 700;
}

.form-message.ok {
    color: var(--green);
}

.app-panel {
    padding: 22px;
}

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

.top-actions {
    display: flex;
    gap: 10px;
}

.upload-card {
    position: relative;
    display: grid;
    min-height: 260px;
    place-items: center;
    border: 2px dashed #9ab4da;
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    background: linear-gradient(135deg, rgba(22, 104, 227, 0.08), rgba(20, 163, 111, 0.08));
}

.upload-card.is-dragover {
    border-color: var(--green);
    background: rgba(20, 163, 111, 0.13);
}

.upload-card input {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
}

.upload-icon {
    display: grid;
    width: 72px;
    height: 72px;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, var(--yellow), var(--green));
    font-size: 42px;
    font-weight: 300;
}

.upload-card h2 {
    margin: 16px 0 4px;
    font-size: 26px;
}

.upload-card p {
    margin: 0 0 18px;
    color: var(--muted);
}

.viewer-note {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #b9d7ff;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(22, 104, 227, 0.1), rgba(10, 166, 183, 0.1));
    padding: 16px 18px;
}

.viewer-note strong {
    color: var(--blue);
}

.viewer-note span {
    color: var(--muted);
}

.status-row {
    display: grid;
    grid-template-columns: 130px 160px minmax(200px, 1fr);
    gap: 12px;
    margin: 18px 0;
}

.status-row > div {
    min-height: 72px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 13px 16px;
}

.status-row strong {
    display: block;
    font-size: 24px;
}

.status-row span {
    color: var(--muted);
}

.progress-wrap {
    display: grid;
    align-content: center;
    gap: 8px;
}

.progress {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8eef7;
}

.progress span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), var(--green));
    transition: width 0.2s ease;
}

.selection-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.selection-toolbar span {
    color: var(--muted);
    font-weight: 800;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
    margin-top: 18px;
}

.file-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.file-card.is-selected {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(22, 104, 227, 0.16);
}

.file-select {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
    cursor: pointer;
}

.file-select input {
    position: absolute;
    opacity: 0;
}

.file-select span {
    display: grid;
    width: 24px;
    height: 24px;
    place-items: center;
    border: 2px solid #9aa8bb;
    border-radius: 6px;
    color: transparent;
    background: #fff;
    font-size: 16px;
    font-weight: 900;
}

.file-select input:checked + span {
    border-color: var(--blue);
    color: #fff;
    background: var(--blue);
}

.thumb {
    display: grid;
    width: 100%;
    aspect-ratio: 4 / 3;
    place-items: center;
    overflow: hidden;
    background: #111827;
}

.thumb img,
.thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb .video-label,
.thumb .audio-label {
    color: #fff;
    font-weight: 800;
}

.thumb .audio-label {
    display: grid;
    width: 76px;
    height: 76px;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--blue), var(--green));
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.file-info {
    display: grid;
    gap: 8px;
    padding: 12px;
}

.file-name {
    overflow: hidden;
    margin: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.file-meta {
    color: var(--muted);
    font-size: 13px;
}

.file-actions {
    display: flex;
    gap: 8px;
}

.file-actions a,
.file-actions button {
    display: inline-grid;
    flex: 1;
    min-height: 38px;
    place-items: center;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 800;
}

.file-actions a {
    color: var(--blue);
    background: #edf4ff;
}

.file-actions button {
    color: var(--red);
    background: #fff0f3;
}

.empty {
    display: none;
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 34px;
    text-align: center;
}

.empty.is-visible {
    display: block;
}

.empty h2 {
    margin: 0 0 6px;
}

.empty p {
    margin: 0;
    color: var(--muted);
}

.has-lightbox {
    overflow: hidden;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    opacity: 0;
    padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    pointer-events: none;
    visibility: hidden;
}

.lightbox.is-open {
    place-items: center;
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(9, 16, 29, 0.78);
    backdrop-filter: blur(8px);
}

.lightbox-panel {
    position: relative;
    display: block;
    width: min(1100px, calc(100vw - 36px));
    height: min(820px, calc(100vh - 48px));
    height: min(820px, calc(100dvh - 48px));
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    overflow: hidden;
    border-radius: 8px;
    background: #0f172a;
    box-shadow: 0 22px 80px rgba(0, 0, 0, 0.45);
}

.lightbox-header {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    z-index: 5;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    z-index: 3;
    width: 56px;
    min-height: 72px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #fff;
    background: rgba(15, 23, 42, 0.72);
    font-size: 54px;
    line-height: 1;
    transform: translateY(-50%);
}

.lightbox-prev {
    left: 12px;
}

.lightbox-next {
    right: 12px;
}

.lightbox-close {
    position: relative;
    z-index: 4;
    width: 48px;
    min-height: 48px;
    margin: 10px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: #fff;
    background: rgba(15, 23, 42, 0.74);
    font-size: 30px;
    line-height: 1;
    pointer-events: auto;
}

.lightbox-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #030712;
}

.lightbox-media {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: 76px 72px 72px;
}

.lightbox-media .lightbox-image {
    display: block;
    flex: 0 1 auto;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center center;
}

.lightbox-media .lightbox-video {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center center;
}

.lightbox-media .lightbox-audio {
    width: min(720px, calc(100% - 48px));
}

.lightbox-caption {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 4;
    min-height: 56px;
    padding: 16px 20px;
    color: #e5edf8;
    background: rgba(17, 24, 39, 0.9);
    font-weight: 800;
    overflow-wrap: anywhere;
}

@media (max-width: 760px) {
    .shell {
        width: 100%;
        padding: 0;
    }

    .app-panel,
    .login-panel {
        border-radius: 0;
        padding: 14px;
    }

    .login-panel {
        width: 100%;
        min-height: 100dvh;
        display: grid;
        align-content: center;
    }

    .brand h1 {
        font-size: 24px;
    }

    .topbar,
    .top-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .status-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .status-row > div {
        min-height: 62px;
    }

    .selection-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .selection-toolbar button,
    .selection-toolbar .button-link,
    .top-actions button,
    .top-actions .button-link {
        width: 100%;
    }

    .viewer-note {
        align-items: flex-start;
        flex-direction: column;
    }

    .upload-card {
        min-height: 200px;
        padding: 22px 14px;
    }

    .upload-card h2 {
        font-size: 22px;
    }

    .gallery {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .file-actions {
        flex-direction: column;
    }

    .file-actions a,
    .file-actions button {
        min-height: 44px;
    }

    .lightbox {
        padding: 0;
    }

    .lightbox-panel {
        width: 100%;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .lightbox-close {
        width: 52px;
        min-height: 52px;
        margin: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px 8px;
        font-size: 34px;
    }

    .lightbox-header {
        padding-top: env(safe-area-inset-top);
    }

    .lightbox-nav {
        width: 48px;
        min-height: 64px;
        font-size: 46px;
        background: rgba(15, 23, 42, 0.82);
    }

    .lightbox-prev {
        left: max(6px, env(safe-area-inset-left));
    }

    .lightbox-next {
        right: max(6px, env(safe-area-inset-right));
    }

    .lightbox-caption {
        min-height: 52px;
        padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
        font-size: 14px;
    }

    .lightbox-media {
        padding: calc(68px + env(safe-area-inset-top)) 0 calc(72px + env(safe-area-inset-bottom));
    }

    .lightbox-media .lightbox-image {
        max-width: 100%;
        max-height: 100%;
    }

    .lightbox-media .lightbox-video {
        width: 100%;
        height: 100%;
    }

    .lightbox-media .lightbox-audio {
        width: calc(100% - 28px);
    }
}
