*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-hover: #1a1a28;
    --border: #2a2a3a;
    --text: #e0e0e8;
    --text-dim: #888898;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --danger: #ef4444;
    --radius: 8px;
    --radius-lg: 12px;
    --surface: #1a1a28;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.hidden { display: none !important; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
input:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    position: sticky;
    top: 0;
    z-index: 100;
}
.logo { font-size: 20px; font-weight: 700; color: var(--accent); cursor: pointer; }
.nav-active { color: var(--text); background: var(--bg-hover); }
.header-right { display: flex; gap: 8px; align-items: center; }
.header-mobile-only { display: none; }
.header-menu-wrap button#header-menu-btn { font-size: 30px; width: 36px; height: 36px; padding: 0 0 7px 0; align-items: center; justify-content: center; line-height: 1; }
.header-menu-wrap { position: relative; }
.header-menu-popup {
    position: absolute;
    right: 0;
    top: calc(100% + 20px);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 60;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    min-width: 120px;
}
.header-menu-popup.hidden { display: none; }
.header-menu-popup .btn { text-align: left; justify-content: flex-start; width: 100%; font-size: 15px; padding: 10px 14px; }
.controls { display: flex; gap: 8px; }
.controls select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 13px;
}

/* Auth */
.view { width: 100%; }
#auth-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 0 24px;
}
.auth-card {
    background: var(--bg-card);
    padding: 48px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 400px;
}
.auth-title { font-size: 28px; font-weight: 700; color: var(--accent); text-align: center; margin-bottom: 16px; }
.auth-subtitle { text-align: center; color: var(--text-dim); margin: 4px 0 32px; font-size: 14px; }
#auth-form input, #recovery-form input, #register-form input {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
}
#auth-form input:focus, #recovery-form input:focus, #register-form input:focus { outline: none; border-color: var(--accent); }
.field-hint { color: var(--danger, #ef4444); font-size: 12px; margin: -4px 0 4px; text-align: center; }
.password-reqs { font-size: 12px; margin: -2px 0 12px; color: #22c55e; text-align: left; padding-left: 3px; }
.password-reqs.hidden { display: none; }
.password-reqs span { color: var(--danger, #ef4444); }
.password-reqs span.met { color: #22c55e; }
.auth-buttons { display: flex; gap: 8px; margin-top: 8px; }
.auth-buttons .btn { flex: 1; padding: 12px; }
.error { color: var(--danger); font-size: 13px; margin-top: 12px; }
.success { color: var(--success, #22c55e); font-size: 13px; margin-top: 12px; }
.btn-link { margin-top: 8px;
    background: none;
    border: none;
    color: var(--text-secondary, #888);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 0 0 0;
    text-decoration: underline;
    width: 100%;
    text-align: center;
}
.btn-link:hover { color: var(--text-primary, #fff); }
#recovery-form.hidden, #register-form.hidden { display: none; }

/* Folders */
.folder-bar {
    position: relative;
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0 8px 24px; border-bottom: 1px solid var(--border);
}
.breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 14px; margin-left: -25px; max-width: calc(50% - 40px); overflow: hidden; }
.breadcrumb-full { display: contents; }
.breadcrumb-compact { display: none; }
.breadcrumb-item { color: var(--text-dim); cursor: pointer; padding: 4px 6px; border-radius: var(--radius); transition: all 0.15s ease; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; min-width: 0; flex-shrink: 1; }
.breadcrumb-item:hover { background: var(--surface); color: var(--text); }
.breadcrumb-item.drag-over { background: rgba(99,102,241,0.15); color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.breadcrumb-current { color: var(--text); font-weight: 600; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; min-width: 0; flex-shrink: 1; }
.breadcrumb-sep { color: var(--text-dim); font-size: 12px; }
.folder-filters { position: absolute; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; }
.folder-actions { display: flex; gap: 8px; align-items: center; }
.filter-desktop { display: none !important; }
.filter-mobile { display: inline-flex; }
.custom-select {
    position: relative;
    display: inline-block;
}
.custom-select-trigger {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.custom-select-trigger:hover,
.custom-select:has(.custom-select-options:not(.hidden)) .custom-select-trigger { border-color: var(--accent); }
.custom-select-trigger .caret { font-size: 10px; color: var(--text-dim); }
.custom-select-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    z-index: 70;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.custom-select-options.hidden { display: none; }
.custom-select-option {
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    white-space: nowrap;
}
.custom-select-option:hover { background: var(--surface); }
.custom-select-option.selected { color: var(--accent); font-weight: 600; }
.filter-popup {
    position: fixed;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.7);
}
.filter-popup.hidden { display: none; }
.filter-popup label {
    font-size: 14px;
    color: var(--text-dim);
}
.filter-popup .custom-select { width: 100%; }
.filter-popup .custom-select-trigger { width: 100%; justify-content: space-between; font-size: 14px; padding: 8px 14px; }
.filter-popup .custom-select-options { width: 100%; }
.filter-popup .custom-select-option { font-size: 14px; padding: 8px 14px; }
.btn-sm { font-size: 13px; padding: 6px 12px; }
.folder-item {
    position: relative;
    aspect-ratio: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.folder-item:hover, .folder-item.menu-active { transform: scale(1.02); border-color: var(--accent); }
.folder-icon { font-size: 48px; line-height: 1; }
.folder-name {
    font-size: 13px; max-width: 90%; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; text-align: center;
}
.folder-item .folder-menu-btn {
    position: absolute; top: 6px; right: 6px;
    background: rgba(0,0,0,0.5); border: none; color: #fff; cursor: pointer;
    font-size: 22px; padding: 1px 8px 7px; border-radius: 6px; line-height: 1;
}
.folder-item .folder-menu-btn:hover { background: rgba(0,0,0,0.8); }
.folder-context-menu {
    position: absolute; top: 36px; right: 8px; z-index: 50;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; min-width: 150px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.6); padding: 4px;
}
.folder-context-menu button {
    display: block; width: 100%; padding: 12px 18px; font-size: 15px;
    background: none; border: none; color: var(--text); cursor: pointer;
    text-align: left; border-radius: 4px;
}
.folder-context-menu button:hover { background: var(--surface); }
.folder-context-menu button.danger { color: var(--danger); }
.folder-context-menu button.danger:hover { background: rgba(239,68,68,0.1); }

/* Move modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.95);
    display: flex; align-items: center; justify-content: center; z-index: 300;
}
.modal-overlay.hidden { display: none; }
.modal-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 400px;
    max-height: 70vh; overflow-y: auto;
}
.modal-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-card input[type="text"] { width: 100%; padding: 10px 12px; font-size: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); margin-bottom: 12px; }
.modal-card input[type="text"]:focus { outline: none; border-color: var(--accent); }
.modal-card-actions { display: flex; gap: 8px; justify-content: flex-end; }
.move-folder-list { display: flex; flex-direction: column; gap: 4px; }
.move-folder-item {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-radius: var(--radius); cursor: pointer;
    font-size: 14px; transition: background 0.1s;
}
.move-folder-item:hover { background: var(--bg); }
.move-folder-item.active { background: var(--accent); color: #fff; }
.move-folder-indent { display: inline-block; }

/* Gallery drop-to-upload */
.gallery-drop-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.gallery-drop-overlay.hidden { display: none; }
.gallery-drop-overlay p {
    font-size: 24px; font-weight: 600; color: var(--accent);
    border: 3px dashed var(--accent); border-radius: var(--radius-lg);
    padding: 48px 64px;
}

.drop-upload-status {
    position: fixed; bottom: 24px; right: 24px; z-index: 100;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 16px 20px;
    font-size: 13px; min-width: 250px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
.drop-upload-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px;
}
.drop-upload-header span { font-weight: 600; font-size: 13px; }
.drop-upload-close {
    background: none; border: none; color: var(--text-dim); cursor: pointer;
    font-size: 16px; padding: 0 2px; line-height: 1;
}
.drop-upload-close:hover { color: var(--text); }
.drop-upload-status.hidden { display: none; }
.drop-upload-status { transition: opacity 0.5s ease; }
.drop-upload-item { padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; }
.drop-upload-item .status { color: var(--text-dim); }
.drop-upload-item .status.done { color: var(--success, #22c55e); }
.drop-upload-item .status.error { color: var(--danger); }

/* Drag and drop */
.gallery-item[draggable="true"] { cursor: grab; }
.gallery-item.dragging { opacity: 0.4; }
.folder-item[draggable="true"] { cursor: grab; }
.folder-item.dragging { opacity: 0.4; }
.folder-item.drag-over,
.folder-item.touch-drag-over {
    border-color: var(--accent); background: rgba(99,102,241,0.1);
    box-shadow: 0 0 0 2px var(--accent);
}
.breadcrumb-item.touch-drag-over { background: rgba(99,102,241,0.15); color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.touch-drag-ghost {
    position: fixed;
    z-index: 9999;
    opacity: 0.7;
    pointer-events: none;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* Admin */
.admin-panel { max-width: 600px; margin: 0 auto; padding: 24px; }
.admin-header { display: flex; align-items: center; justify-content: center; margin-bottom: 24px; }
.admin-header h2 { font-size: 20px; font-weight: 600; position: relative; }
.btn-back-circle {
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    padding: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.admin-create, .admin-users { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 16px; }
.admin-create h3, .admin-users h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.admin-create form { display: flex; flex-direction: column; gap: 0; }
.admin-create input {
    display: block; width: 100%; padding: 12px 16px; margin-bottom: 12px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: 15px;
}
.admin-create input:focus { outline: none; border-color: var(--accent); }
.admin-checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-dim); margin-bottom: 12px; cursor: pointer; white-space: nowrap; align-self: flex-start; }
.admin-checkbox input[type="checkbox"] { accent-color: var(--accent); position: relative; top: 6px; }
.admin-user-card {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; margin-bottom: 8px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
}
.admin-user-info { font-size: 14px; }
.admin-user-info .admin-badge {
    font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
    background: rgba(99,102,241,0.15); color: var(--accent); margin-left: 8px;
}
.admin-user-card .btn-danger { font-size: 13px; padding: 6px 12px; }
.admin-create form input[type="password"] {
    display: block; width: 100%; padding: 12px 16px; margin-bottom: 12px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: 15px;
}
.admin-create form input[type="password"]:focus { outline: none; border-color: var(--accent); }

/* Gallery */
#gallery-view { padding: 8px 24px 24px; }
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 10px;
}
.gallery-item {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.gallery-item:hover { transform: scale(1.02); border-color: var(--accent); }
.gallery-item.menu-active { transform: scale(1.02); border-color: var(--accent); }
.gallery-grid:has(.menu-active) .gallery-item:not(.menu-active):hover { transform: none; border-color: var(--border); }
.filter-dimmed { opacity: 0.4; pointer-events: none; transition: opacity 0.15s ease; }
.gallery-item.menu-active .item-menu-btn { opacity: 1; }
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.gallery-item .badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.gallery-item .item-menu-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.5);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 22px;
    padding: 1px 8px 7px;
    border-radius: 6px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}
.gallery-item:hover .item-menu-btn { opacity: 1; }
.gallery-item .item-menu-btn:hover { background: rgba(0,0,0,0.8); }
.gallery-item .folder-context-menu {
    position: fixed;
    z-index: 50;
}
.gallery-item .item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    font-size: 12px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gallery-empty {
    text-align: center;
    padding: 120px 24px 20px;
    color: var(--text-dim);
    font-size: 16px;
}
.gallery-loading { display: flex; justify-content: center; padding: 48px; }
.gallery-refresh { display: flex; justify-content: center; padding: 0 24px 24px; }
.btn-refresh {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.btn-refresh:hover { border-color: var(--accent); color: var(--accent); }
.refresh-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    background: none;
    border: none;
}
.refresh-tile:hover { transform: none; border-color: transparent; }
.refreshing .gallery-empty { display: block !important; visibility: hidden !important; }
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-sm { width: 18px; height: 18px; border-width: 2px; margin: 0 auto; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    color: var(--text-dim);
    font-size: 14px;
}

/* Viewer */
.viewer {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    z-index: 200;
    display: flex;
    flex-direction: column;
}
.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
}
.viewer-header span { font-size: 14px; color: var(--text-dim); }
.viewer-actions { display: flex; gap: 8px; }
.viewer-content {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 24px;
}
.viewer-content video,
.viewer-content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius);
    image-orientation: from-image;
}
.viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    font-size: 36px;
    width: 48px;
    height: 72px;
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, opacity 0.15s ease;
    z-index: 10;
    opacity: 0.6;
    user-select: none;
}
.viewer-nav:hover { background: rgba(255,255,255,0.15); opacity: 1; }
.viewer-nav:disabled { opacity: 0; pointer-events: none; }
.viewer-nav-prev { left: 16px; }
.viewer-nav-next { right: 16px; }
@media (max-width: 600px) {
    .viewer-nav { display: none; }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-content h3 { margin-bottom: 16px; }
.modal-actions { margin-top: 16px; text-align: right; }

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    color: var(--text-dim);
    cursor: pointer;
    transition: border-color 0.15s;
    position: relative;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Upload progress */
.upload-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.upload-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .status { color: var(--text-dim); font-size: 12px; }
.upload-item .progress-bar {
    width: 80px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.upload-item .progress-bar .fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.2s;
}

.delete-warning { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.move-cancel-btn { width: 100%; margin-top: 12px; }

/* Responsive */
@media (max-width: 768px) {
    header { gap: 0; }
    .header-left { flex: 1; }
    .header-center { display: none; }
    .header-right { flex: 1; justify-content: center; gap: 0; }
    .header-desktop { display: none !important; }
    .header-mobile-only { display: inline-flex !important; }
    .header-menu-wrap { position: absolute; right: 16px; }
    .folder-actions { margin-right: 0; }
    #new-folder-btn { margin-right: 0; }
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .gallery-item .item-menu-btn { opacity: 1; }
    .breadcrumb-full { display: none !important; }
    .breadcrumb-compact { display: contents !important; }
}
