:root {
    --bg: #0f1117;
    --bg-elevated: #181b24;
    --bg-card: #1e2230;
    --border: #2a3042;
    --text: #e8eaef;
    --muted: #8b93a7;
    --primary: #5b8def;
    --primary-hover: #7aa3f5;
    --accent-personal: #6ee7b7;
    --accent-public: #fbbf24;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fb923c;
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'DM Sans', system-ui, sans-serif;
}

[data-theme="light"] {
    --bg: #f0f2f8;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --border: #d8dce8;
    --text: #1a1d26;
    --muted: #6b7280;
    --primary: #3b6fd9;
    --primary-hover: #2d5fc7;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Auth */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(ellipse at 30% 20%, #1a2744 0%, var(--bg) 55%);
}
.auth-card, .install-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }
.brand h1 { margin: 0; font-size: 1.5rem; font-weight: 700; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: var(--bg-elevated);
    color: var(--muted);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: var(--transition);
}
.tab.active, .tab:hover { background: var(--primary); color: #fff; }

.form label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.85rem;
    color: var(--muted);
}
.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form input[type="search"] {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color var(--transition);
}
.form input:focus {
    outline: none;
    border-color: var(--primary);
}
.checkbox { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { width: auto; margin: 0; }

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-danger { background: var(--danger); color: #fff; }

.alert { padding: 12px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-error { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.alert-success { background: rgba(74, 222, 128, 0.15); color: var(--success); }

/* Installer */
.install-page .steps {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    font-size: 0.75rem;
    color: var(--muted);
}
.install-page .steps span.active { color: var(--primary); font-weight: 600; }
.check-list { list-style: none; padding: 0; margin: 0 0 20px; }
.check-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.check-list li.ok { color: var(--success); }
.check-list li.fail { color: var(--danger); }

/* Mode picker */
.mode-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
    animation: fadeIn 0.3s ease;
}
.mode-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    max-width: 640px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow);
}
.mode-card h2 { margin: 0 0 8px; }
.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 28px;
}
@media (max-width: 520px) {
    .mode-grid { grid-template-columns: 1fr; }
}
.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 28px 20px;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}
.mode-btn:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(91, 141, 239, 0.2);
}
.mode-btn[data-mode="personal"]:hover { border-color: var(--accent-personal); }
.mode-btn[data-mode="public"]:hover { border-color: var(--accent-public); }
.mode-icon { font-size: 2rem; }
.mode-btn strong { font-size: 1.1rem; }
.mode-btn span:last-child { font-size: 0.8rem; color: var(--muted); }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-center { flex: 1; max-width: 480px; margin: 0 auto; }
.topbar-title { font-weight: 600; }
.logo-sm { font-size: 1.25rem; }
.badge {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge.personal { background: rgba(110, 231, 183, 0.2); color: var(--accent-personal); }
.badge.public { background: rgba(251, 191, 36, 0.2); color: var(--accent-public); }

.search-wrap input {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text);
    font-family: inherit;
}
.icon-btn {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #a78bfa);
    border: none;
    cursor: pointer;
}
.avatar-menu { position: relative; }
.dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 180px;
    padding: 8px;
    box-shadow: var(--shadow);
    z-index: 60;
}
.dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    border-radius: 6px;
}
.dropdown button:hover { background: var(--bg-elevated); }
.dropdown span { display: block; padding: 8px 12px; font-size: 0.85rem; color: var(--muted); }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar {
    width: 220px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 57px;
        bottom: 0;
        z-index: 40;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}
.nav-item:hover, .nav-item.active {
    background: var(--bg-card);
    color: var(--text);
}
.sidebar-spacer { flex: 1; }
.storage-info {
    padding: 12px;
    font-size: 0.8rem;
    color: var(--muted);
}
.storage-info strong { display: block; color: var(--text); margin-top: 4px; }

.main {
    flex: 1;
    padding: 24px;
    position: relative;
    overflow: auto;
}

.drop-zone {
    position: absolute;
    inset: 16px;
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    background: rgba(91, 141, 239, 0.08);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 30;
    pointer-events: none;
}
.drop-zone.active { display: flex; }
.drop-zone p { font-size: 1.25rem; color: var(--primary); font-weight: 600; }

.breadcrumb {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 16px;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 16px;
}
.file-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.file-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.2s ease, box-shadow 0.2s ease;
    animation: slideUp 0.25s ease backwards;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
    content-visibility: auto;
    contain-intrinsic-size: 180px;
    position: relative;
    will-change: transform;
}
.file-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(91, 141, 239, 0.35);
}
.file-grid.list-view .file-card {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    min-height: auto;
    animation: none;
}
.file-grid.list-view .file-card .icon-wrap,
.file-grid.list-view .file-card .thumb-wrap {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    margin: 0;
}
.file-grid.list-view .file-card .thumb {
    width: 40px;
    height: 40px;
    margin: 0;
}
.file-grid.list-view .file-card .card-body {
    flex: 1;
    min-width: 0;
}
.file-grid.list-view .file-card .actions {
    opacity: 1;
    margin: 0;
    flex-shrink: 0;
}
.file-card:hover {
    border-color: var(--primary);
    transform: translate3d(0, -2px, 0);
    box-shadow: var(--shadow);
}
.file-card.dragging {
    opacity: 0.6;
    transform: scale(0.98);
}
.file-card .thumb-wrap {
    width: 100%;
    height: 64px;
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
    background: var(--bg);
    flex-shrink: 0;
}
.file-card .thumb {
    width: 100%;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 0;
    transition: opacity 0.25s ease;
    opacity: 0.85;
}
.file-card .thumb.thumb-loading {
    opacity: 0.5;
}
.file-card .thumb.thumb-loaded {
    opacity: 1;
}
.file-card .thumb.thumb-error {
    opacity: 0.4;
    filter: grayscale(1);
}
.file-card .icon {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 10px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.file-card .name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-card .meta {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
}
.file-card .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: auto;
    padding-top: 8px;
    max-width: 100%;
}
.file-card:hover .actions,
.file-card:focus-within .actions { opacity: 1; }
.file-card .actions .btn-sm {
    padding: 5px 7px;
    font-size: 0.7rem;
    min-width: 0;
    flex: 1 1 calc(50% - 4px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-card .actions .btn-icon {
    flex: 0 0 32px;
    padding: 5px;
}
.folder-badge {
    display: inline-block;
    font-size: 0.7rem;
    color: var(--muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
}

.empty-state {
    text-align: center;
    padding: 80px 24px;
    color: var(--muted);
}

/* Skeleton loaders */
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skeleton-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    pointer-events: none;
    animation: slideUp 0.2s ease backwards;
}
.skeleton-shimmer {
    background: linear-gradient(90deg, var(--bg) 0%, var(--border) 50%, var(--bg) 100%);
    background-size: 800px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: 6px;
}
.skeleton-card .skeleton-thumb {
    width: 100%;
    height: 64px;
    margin-bottom: 10px;
}
.skeleton-card .skeleton-line {
    height: 12px;
    margin-bottom: 8px;
}
.skeleton-card .skeleton-line.short {
    width: 55%;
    height: 10px;
    margin-bottom: 0;
}
.file-grid.list-view .skeleton-card {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    display: flex;
}
.file-grid.list-view .skeleton-card .skeleton-thumb {
    width: 40px;
    height: 40px;
    margin-bottom: 0;
    flex-shrink: 0;
}
.file-grid.list-view .skeleton-card .skeleton-body {
    flex: 1;
}

/* Infinite scroll */
.load-more-indicator {
    text-align: center;
    padding: 20px;
    color: var(--muted);
    font-size: 0.9rem;
}
.load-more-indicator .spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.scroll-sentinel {
    height: 1px;
    width: 100%;
    pointer-events: none;
}

/* Admin */
.admin-layout { padding: 24px; max-width: 1200px; margin: 0 auto; }
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-card strong { font-size: 1.5rem; display: block; }
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}
.card h3 { margin: 0 0 16px; }
.form-inline { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.form-inline label { margin-bottom: 0; }

.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.data-table th, .data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-weight: 500; }
.password-cell { font-family: monospace; font-size: 0.85rem; color: var(--accent-public); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
}
.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    padding: 24px;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--bg);
    border: none;
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1;
}
#preview-body img, #preview-body video {
    max-width: 100%;
    max-height: 75vh;
    border-radius: 8px;
}

.upload-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    z-index: 150;
}
.progress-bar {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
    margin: 8px 0;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.15s ease;
}
#upload-list { list-style: none; padding: 0; margin: 0; font-size: 0.8rem; color: var(--muted); max-height: 120px; overflow: auto; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 14px 24px;
    border-radius: 8px;
    z-index: 160;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Password toggle */
.password-wrap {
    position: relative;
    display: block;
    margin-top: 6px;
}
.password-wrap input {
    padding-right: 44px !important;
}
.pw-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    opacity: 0.7;
    line-height: 1;
}
.pw-toggle:hover { opacity: 1; }

/* Profile */
.profile-layout {
    padding: 24px;
    max-width: 720px;
    margin: 0 auto;
    display: grid;
    gap: 24px;
}
.profile-card p { margin: 8px 0; }

/* Sidebar favorites */
.sidebar-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.sidebar-label {
    display: block;
    padding: 0 14px 8px;
    color: var(--muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}
.favorites-list { display: flex; flex-direction: column; gap: 2px; }
.sidebar-empty { padding: 0 14px; margin: 0; }
.fav-pin {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
}
.fav-pin:hover { background: var(--bg-card); color: var(--text); }
.fav-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Breadcrumb */
.breadcrumb .crumb {
    background: none;
    border: none;
    color: var(--primary);
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    padding: 0;
}
.breadcrumb .crumb:hover { text-decoration: underline; }
.breadcrumb .crumb.active { color: var(--text); cursor: default; }
.breadcrumb .crumb-sep { color: var(--muted); }

/* File cards drag/drop */
.file-card.is-folder { border-style: dashed; }
.file-card.dragging { opacity: 0.45; }
.file-card.drop-target,
.crumb.drop-target {
    border-color: var(--accent-personal) !important;
    background: rgba(110, 231, 183, 0.1);
    box-shadow: 0 0 0 2px var(--accent-personal);
}
.fav-btn.active { color: var(--accent-public); }

/* Trash bar */
.trash-bar {
    margin-bottom: 16px;
    display: flex;
    justify-content: flex-end;
}

/* Text editor */
.editor-modal {
    width: min(900px, 95vw);
    height: min(80vh, 700px);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.editor-actions { display: flex; align-items: center; gap: 8px; }
#editor-content {
    flex: 1;
    width: 100%;
    border: none;
    resize: none;
    padding: 20px;
    background: var(--bg);
    color: var(--text);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
}
#editor-content:focus { outline: none; }

/* Upload controls */
.upload-toast-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.upload-controls { display: flex; gap: 6px; }
.upload-item.uploading { color: var(--primary); }
.upload-item.paused { color: var(--accent-public); }
.upload-item.done { color: var(--success); }
.upload-item.error { color: var(--danger); }

/* Empty state actions */
.empty-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 16px;
}

/* Input modal */
.input-modal { width: min(420px, 92vw); }
.input-modal h3 { margin: 0 0 16px; }
.input-modal input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    margin-bottom: 16px;
}
.input-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Context menu */
.context-menu {
    position: fixed;
    z-index: 500;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    min-width: 180px;
    box-shadow: var(--shadow);
}
.context-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 6px;
}
.context-menu button:hover { background: var(--bg-elevated); }
.context-menu .ctx-label {
    padding: 8px 14px 4px;
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.context-menu button[data-ctx="sort"] {
    display: flex;
    align-items: center;
    gap: 8px;
}
.context-menu button[data-ctx="sort"] .sort-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid var(--muted);
    flex-shrink: 0;
}
.context-menu button[data-ctx="sort"].active-sort .sort-dot {
    background: var(--text);
    border-color: var(--text);
}
.context-menu button[data-ctx="sort"] .sort-arrow {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--muted);
}
.context-menu hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 6px 0;
}

/* Image viewer */
.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    flex-direction: column;
    background: #0a0a0a;
}
.image-viewer.hidden { display: none !important; }
.iv-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}
.iv-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 60px 20px 100px;
    position: relative;
    z-index: 1;
}
.iv-loading {
    position: absolute;
    z-index: 5;
    color: #aaa;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}
.iv-stage img,
.iv-stage .iv-preview {
    max-width: none;
    max-height: none;
    transition: transform 0.15s ease, opacity 0.25s ease;
    cursor: grab;
    user-select: none;
    transform-origin: center center;
}
.iv-preview {
    position: absolute;
    filter: blur(12px);
    opacity: 0;
    z-index: 1;
}
.iv-preview.iv-preview-visible {
    opacity: 0.85;
}
#iv-image {
    position: relative;
    z-index: 2;
    opacity: 0;
}
#iv-image.iv-ready {
    opacity: 1;
}
.iv-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 6;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(30, 34, 48, 0.85);
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
}
.iv-nav:hover {
    background: rgba(91, 141, 239, 0.9);
    transform: translateY(-50%) scale(1.05);
}
.iv-nav-prev { left: 16px; }
.iv-nav-next { right: 16px; }
.iv-counter {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    color: #ccc;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 12px;
    border-radius: 20px;
}
.iv-stage img.dragging { cursor: grabbing; }
.sort-label { font-size: 0.8rem; margin-left: 2px; }
.remember-row { margin-top: 12px; font-size: 0.9rem; color: var(--muted); }
@media (max-width: 640px) {
    .iv-nav { width: 40px; height: 40px; font-size: 1.6rem; }
    .sort-label { display: none; }
}
.iv-toolbar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: rgba(30, 34, 48, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 10px 16px;
    min-width: min(900px, 94vw);
    flex-wrap: wrap;
}
.iv-toolbar-left, .iv-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.iv-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #e8eaef;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.iv-btn:hover { background: rgba(255, 255, 255, 0.16); }
.iv-btn.active { color: #fbbf24; background: rgba(251, 191, 36, 0.15); }
.iv-close { font-size: 1.4rem; }
.iv-sep {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
}
.iv-meta {
    font-size: 0.8rem;
    color: #a0a8bc;
    white-space: nowrap;
}
.iv-zoom-select {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e8eaef;
    border-radius: 6px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 0.85rem;
}
#iv-zoom-slider {
    width: 100px;
    accent-color: var(--primary);
}
.iv-filmstrip {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9;
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(20, 22, 30, 0.95);
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 90vw;
    overflow-x: auto;
}
.iv-filmstrip.hidden { display: none !important; }
.iv-filmstrip img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.7;
}
.iv-filmstrip img.active,
.iv-filmstrip img:hover {
    border-color: var(--primary);
    opacity: 1;
}
.iv-info-panel {
    position: absolute;
    top: 80px;
    right: 24px;
    z-index: 10;
    background: rgba(30, 34, 48, 0.95);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    min-width: 220px;
}
.iv-info-panel.hidden { display: none !important; }
.iv-info-panel h4 { margin: 0 0 12px; word-break: break-all; }
.iv-info-panel p { margin: 8px 0; font-size: 0.9rem; }

@media (max-width: 768px) {
    .iv-toolbar { min-width: 94vw; padding: 8px 10px; }
    #iv-zoom-slider { width: 60px; }
}

/* File type icons */
.ft-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin: 0 auto 10px;
}
.file-grid.list-view .ft-icon { width: 40px; height: 40px; margin: 0; font-size: 0.55rem; }
.ft-folder { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.ft-image { background: rgba(96, 165, 250, 0.2); color: #60a5fa; }
.ft-video { background: rgba(167, 139, 250, 0.2); color: #a78bfa; }
.ft-audio { background: rgba(251, 146, 60, 0.2); color: #fb923c; }
.ft-pdf { background: rgba(248, 113, 113, 0.2); color: #f87171; }
.ft-doc { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.ft-sheet { background: rgba(74, 222, 128, 0.2); color: #4ade80; }
.ft-ppt { background: rgba(251, 113, 133, 0.2); color: #fb7185; }
.ft-archive { background: rgba(250, 204, 21, 0.2); color: #facc15; }
.ft-text { background: rgba(148, 163, 184, 0.2); color: #94a3b8; }
.ft-code { background: rgba(45, 212, 191, 0.2); color: #2dd4bf; }
.ft-file { background: rgba(139, 147, 167, 0.2); color: #8b93a7; }

/* Storage bar */
.storage-bar-wrap { margin: 8px 0 6px; }
.storage-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}
.storage-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background: var(--success);
    transition: width 0.4s ease, background 0.3s;
}
.storage-bar-fill.warn { background: var(--warning); }
.storage-bar-fill.full { background: var(--danger); }
.storage-quota-label { display: block; margin-top: 4px; color: var(--muted); font-size: 0.75rem; }

/* Selection */
.selection-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    margin-bottom: 12px;
}
.select-marquee {
    position: absolute;
    border: 2px dashed var(--primary);
    background: rgba(91, 141, 239, 0.12);
    pointer-events: none;
    z-index: 25;
}

/* Theme toggle */
.theme-toggle { display: flex; gap: 10px; margin-top: 12px; }
.theme-btn.active { background: var(--primary); color: #fff; }

/* PDF viewer */
.pdf-modal { width: min(900px, 96vw); height: min(90vh, 800px); display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.pdf-header, .video-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.pdf-controls { display: flex; align-items: center; gap: 10px; }
.pdf-canvas-wrap {
    flex: 1; overflow: auto; padding: 20px; background: #525659; text-align: center;
}
#pdf-canvas { max-width: 100%; box-shadow: var(--shadow); }

/* Video player */
.video-modal { width: min(960px, 96vw); padding: 0; overflow: hidden; }
#video-player { width: 100%; max-height: 75vh; background: #000; display: block; }
.video-modal { position: relative; }
.video-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.55);
    color: #e8eaef;
    font-size: 0.95rem;
    z-index: 2;
    pointer-events: none;
}

.dup-actions { flex-wrap: wrap; justify-content: flex-end; }

/* Responsive */
@media (max-width: 1024px) {
    .topbar-center { max-width: 280px; }
}
@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; padding: 10px; }
    .topbar-center { order: 3; flex: 1 1 100%; max-width: none; margin-top: 8px; }
    .file-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .sidebar { width: 260px; }
}
@media (max-width: 480px) {
    .file-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .topbar-right .btn-ghost:not(#btn-switch-mode) { padding: 8px 10px; font-size: 0.8rem; }
}
@media (min-width: 1600px) {
    .main { max-width: 1600px; margin: 0 auto; }
    .file-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
