* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --bg: #0a0e1a;
    --surface: rgba(255, 255, 255, 0.045);
    --surface-strong: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.09);
    --text: #f4f6fb;
    --text-muted: #98a2c0;
    --accent-1: #8b5cf6;
    --accent-2: #ff5fa2;
    --accent-gradient: linear-gradient(135deg, var(--accent-1) 0%, var(--accent-2) 100%);
    --danger: #ff5f6d;
    background: var(--bg);
    color: var(--text);
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(1100px 560px at 8% -12%, rgba(139, 92, 246, 0.28), transparent 60%),
        radial-gradient(900px 520px at 110% 8%, rgba(255, 95, 162, 0.2), transparent 60%),
        var(--bg);
    background-attachment: fixed, fixed, fixed;
}

html {
    scroll-behavior: smooth;
}

body.modal-open {
    overflow: hidden;
}

::selection {
    background: rgba(139, 92, 246, 0.4);
}

.page-shell {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 1.25rem 6rem;
}

/* Header */

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    margin: 0 -1.25rem;
    padding: 1rem 1.25rem;
    background: rgba(10, 14, 26, 0.72);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.brand-mark {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--accent-gradient);
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4);
}

.brand-text {
    min-width: 0;
}

.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.brand h1 {
    margin: 0.1rem 0 0;
    font-size: 1.3rem;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.15s ease;
}

.icon-button:hover {
    background: var(--surface-strong);
    transform: translateY(-1px);
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

.app-subtitle {
    margin: 0.9rem 0 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    max-width: 640px;
}

main {
    display: grid;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    max-width: 380px;
    width: 100%;
    text-align: center;
    display: grid;
    justify-items: center;
    gap: 0.35rem;
    padding: 2.25rem 1.75rem;
}

.login-card .brand-mark {
    margin-bottom: 0.5rem;
}

.login-card h1 {
    margin: 0.2rem 0 0;
    font-size: 1.6rem;
}

.login-card .app-subtitle {
    margin: 0.5rem 0 1.5rem;
}

.login-card .upload-form {
    width: 100%;
    text-align: left;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.upload-form {
    display: grid;
    gap: 1.1rem;
}

.field-row {
    display: grid;
    gap: 0.5rem;
}

label {
    font-weight: 700;
}

input[type="text"],
input[type="password"],
input[type="url"] {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.95rem 1rem;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
    color: var(--text-muted);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="url"]:focus {
    outline: none;
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}

.hint {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* Dropzone */

.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    text-align: center;
    padding: 2rem 1.25rem;
    border: 1.5px dashed var(--border);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
    font-weight: 400;
}

.dropzone:hover {
    border-color: rgba(139, 92, 246, 0.5);
    background: rgba(139, 92, 246, 0.06);
}

.dropzone.dragover {
    border-color: var(--accent-1);
    background: rgba(139, 92, 246, 0.12);
    transform: scale(1.01);
}

.dropzone-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.dropzone-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.dropzone-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.dropzone-text {
    color: var(--text-muted);
    font-size: 0.92rem;
    pointer-events: none;
}

.dropzone-text strong {
    color: var(--text);
    font-weight: 700;
}

/* Selected files preview */

.selected-files {
    display: grid;
    gap: 0.6rem;
}

.selected-files[hidden] {
    display: none;
}

.selected-files-summary {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 600;
}

.selected-files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 0.6rem;
}

.selected-file {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    padding-bottom: 0.4rem;
}

.selected-file img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
}

.selected-file-video-placeholder {
    width: 100%;
    height: 80px;
    background: linear-gradient(135deg, #1b2033, #2c2547);
    display: flex;
    align-items: center;
    justify-content: center;
}

.selected-file-video-placeholder::after {
    content: '';
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 7px 0 7px 12px;
    border-color: transparent transparent transparent white;
    margin-left: 2px;
}

.selected-file-name {
    display: block;
    font-size: 0.72rem;
    padding: 0.3rem 0.5rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
}

.selected-file-remove {
    position: absolute;
    top: 0.3rem;
    right: 0.3rem;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selected-file-remove:hover {
    background: rgba(0, 0, 0, 0.85);
}

.selected-file-invalid {
    background: rgba(255, 95, 109, 0.08);
    border-color: rgba(255, 95, 109, 0.35);
    padding: 0.5rem;
    display: grid;
    gap: 0.2rem;
}

.selected-file-invalid .selected-file-name {
    padding: 0;
    color: #ffb3ba;
    font-weight: 600;
}

.selected-file-reason {
    font-size: 0.7rem;
    color: #ff8b95;
}

/* Upload progress */

.upload-progress {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.75rem;
}

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

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

.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: 999px;
    transition: width 0.2s ease;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.6);
}

.upload-progress-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 3.2em;
    text-align: right;
}

/* Buttons */

.primary-button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 14px;
    padding: 0.85rem 1.3rem;
    font-weight: 700;
    font-size: 0.95rem;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.primary-button {
    background: var(--accent-gradient);
    color: white;
    padding: 0.95rem 1.4rem;
    box-shadow: 0 12px 30px rgba(139, 92, 246, 0.3);
}

.button {
    background: var(--surface-strong);
    color: var(--text);
    border: 1px solid var(--border);
}

.button.secondary {
    background: rgba(139, 92, 246, 0.12);
    color: #d6c8ff;
    border-color: rgba(139, 92, 246, 0.3);
}

.button.danger {
    background: rgba(255, 95, 109, 0.14);
    color: #ffb3ba;
    border-color: rgba(255, 95, 109, 0.35);
}

.primary-button:hover,
.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 32px rgba(139, 92, 246, 0.28);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
    box-shadow: none;
}

.delete-form {
    margin: 0;
}

/* Toast messages */

.messages {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1500;
    display: grid;
    gap: 0.6rem;
    width: min(420px, calc(100vw - 2rem));
    pointer-events: none;
}

@keyframes toast-in {
    from {
        transform: translateY(-14px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

.message {
    pointer-events: auto;
    padding: 1rem 1.1rem;
    border-radius: 16px;
    font-weight: 600;
    font-size: 0.92rem;
    border: 1px solid var(--border);
    background: rgba(20, 24, 40, 0.92);
    backdrop-filter: blur(16px);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
    animation: toast-in 0.35s ease, toast-out 0.4s ease 4.6s forwards;
}

.message.success { color: #8ff7c6; border-color: rgba(52, 211, 153, 0.35); }
.message.warning { color: #ffd88a; border-color: rgba(251, 191, 36, 0.35); }
.message.error { color: #ffb3ba; border-color: rgba(255, 95, 109, 0.35); }

.share-box {
    margin-top: 0.5rem;
    padding: 1rem 1rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.02);
}

.share-box p {
    margin: 0 0 0.75rem;
    color: var(--text-muted);
}

.share-box input {
    width: 100%;
    cursor: pointer;
}

/* Folders */

.folder-section {
    display: grid;
    gap: 1rem;
}

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

.folder-tile {
    display: grid;
    justify-items: center;
    gap: 0.35rem;
    text-align: center;
    padding: 1.25rem 1rem;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: transform 0.16s ease, background 0.16s ease;
}

.folder-tile:hover {
    transform: translateY(-2px);
    background: var(--surface-strong);
}

.folder-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.folder-name {
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.folder-count {
    font-size: 0.76rem;
    color: var(--text-muted);
}

.create-folder-form {
    display: flex;
    gap: 0.6rem;
}

.create-folder-form input[type="text"] {
    flex: 1;
}

.folder-breadcrumb {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
}

.folder-breadcrumb-name {
    font-weight: 700;
    flex: 1;
}

/* Gallery */

.gallery {
    display: grid;
    gap: 1rem;
}

.gallery-toolbar {
    display: flex;
    justify-content: flex-end;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.photo-tile {
    margin: 0;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
}

.photo-thumb {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.photo-thumb:hover img {
    transform: scale(1.06);
}

.photo-thumb-placeholder {
    display: flex;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1b2033, #2c2547);
}

.play-badge {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.play-badge::after {
    content: '';
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 9px 0 9px 15px;
    border-color: transparent transparent transparent white;
    margin-left: 3px;
}

.select-indicator {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.85);
    background: rgba(0, 0, 0, 0.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

.gallery.selection-mode .select-indicator {
    display: flex;
}

.photo-thumb.selected .select-indicator {
    background: var(--accent-gradient);
    border-color: transparent;
}

.photo-thumb.selected .select-indicator::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -2px);
}

.photo-thumb.selected::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(139, 92, 246, 0.28);
    pointer-events: none;
    z-index: 1;
}

.thumb-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 1.4rem 0.7rem 0.55rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
    display: grid;
    gap: 0.1rem;
    text-align: left;
    pointer-events: none;
}

.thumb-name {
    font-size: 0.82rem;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thumb-meta {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.75);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    border: 1.5px dashed var(--border);
    border-radius: 24px;
    background: var(--surface);
}

.empty-state h2 {
    margin: 0 0 0.75rem;
    font-size: 1.45rem;
}

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

/* Bulk selection bar */

.selection-bar {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.85rem 1.1rem;
    border-radius: 20px;
    background: rgba(20, 24, 40, 0.92);
    border: 1px solid var(--border);
    backdrop-filter: blur(18px);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    max-width: calc(100vw - 2rem);
    flex-wrap: wrap;
}

.selection-bar[hidden] {
    display: none;
}

.selection-count {
    font-weight: 700;
    font-size: 0.9rem;
    white-space: nowrap;
}

.selection-move-form {
    display: flex;
    gap: 0.6rem;
}

.selection-move-form select {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.65rem 0.75rem;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
}

/* Floating action button */

.fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 45;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 16px 40px rgba(139, 92, 246, 0.45);
    text-decoration: none;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.fab:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 20px 48px rgba(139, 92, 246, 0.55);
}

.fab:active {
    transform: scale(0.96);
}

.fab svg {
    width: 24px;
    height: 24px;
}

/* Modal preview */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.modal:not([hidden]) {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 7, 16, 0.82);
    backdrop-filter: blur(8px);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    background: #0b0e1a;
    border: 1px solid var(--border);
    border-radius: 24px;
    width: min(920px, 96vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 40px 120px rgba(0, 0, 0, 0.55);
}

.modal-image-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #05070f;
    padding: 1rem;
}

.modal-image-wrap img,
.modal-image-wrap video {
    max-width: 100%;
    max-height: 74vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    border-radius: 8px;
}

.modal-image-wrap video {
    background: black;
}

.modal-image-wrap img[hidden],
.modal-image-wrap video[hidden] {
    display: none;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.75);
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.modal-nav:hover {
    background: rgba(0, 0, 0, 0.75);
}

.modal-nav-prev {
    left: 0.75rem;
}

.modal-nav-next {
    right: 0.75rem;
}

.modal-footer {
    background: rgba(255, 255, 255, 0.03);
    border-top: 1px solid var(--border);
    padding: 1rem 1.25rem;
    display: grid;
    gap: 0.85rem;
}

.modal-footer-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.modal-info {
    min-width: 0;
}

.modal-info strong {
    display: block;
    font-size: 1rem;
    color: var(--text);
}

.modal-info span {
    display: block;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.modal-actions {
    display: flex;
    gap: 0.6rem;
    flex-shrink: 0;
}

.move-form {
    display: flex;
    gap: 0.6rem;
    border-top: 1px solid var(--border);
    padding-top: 0.85rem;
}

.move-form select {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 0.8rem;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
}

@media (max-width: 600px) {
    .page-shell {
        padding: 0 1rem 6rem;
    }

    .app-header {
        margin: 0 -1rem;
        padding: 0.85rem 1rem;
    }

    .brand h1 {
        font-size: 1.1rem;
    }

    .count-badge {
        display: none;
    }

    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 0.75rem;
    }

    .modal-nav {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.6rem;
    }

    .modal-footer-top {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-actions {
        justify-content: stretch;
    }

    .modal-actions .button,
    .modal-actions .delete-form {
        flex: 1;
    }

    .fab {
        right: 1rem;
        bottom: 1rem;
    }

    .folder-breadcrumb {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .create-folder-form {
        flex-direction: column;
    }
}
