/* ========== Tokens ========== */
:root {
    --bg-0: #09090b;
    --bg-1: #111114;
    --bg-2: #19191e;
    --bg-3: #222228;
    --bg-hover: #28282f;
    --bg-active: #2f2f38;

    --text-0: #fafafa;
    --text-1: #a1a1aa;
    --text-2: #71717a;
    --text-3: #52525b;

    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-muted: rgba(99, 102, 241, 0.12);

    --green: #22c55e;
    --red: #ef4444;
    --amber: #f59e0b;

    --border: rgba(255, 255, 255, 0.06);
    --border-focus: rgba(99, 102, 241, 0.4);

    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 8px;

    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-0);
    color: var(--text-0);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ========== App Shell ========== */
.app {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ========== Header ========== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: rgba(9, 9, 11, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-count {
    font-size: 12px;
    color: var(--text-2);
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ========== Buttons ========== */
.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-xs);
    border: none;
    background: transparent;
    color: var(--text-1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.btn-icon:hover { background: var(--bg-3); color: var(--text-0); }
.btn-icon:active { background: var(--bg-active); }

.btn-create {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border-radius: var(--radius-xs);
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: background 0.15s, transform 0.1s;
}

.btn-create:hover { background: var(--accent-hover); }
.btn-create:active { transform: scale(0.97); }

/* ========== Search ========== */
.search {
    display: none;
    padding: 10px 16px 0;
}

.search.visible { display: block; }

.search-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s;
}

.search-inner:focus-within {
    border-color: var(--border-focus);
}

.search-icon {
    color: var(--text-3);
    flex-shrink: 0;
}

.search-inner input {
    flex: 1;
    border: none;
    background: none;
    color: var(--text-0);
    font-size: 15px;
    outline: none;
}

.search-inner input::placeholder { color: var(--text-3); }

.search-clear {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--bg-3);
    color: var(--text-2);
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.search-clear.visible { display: flex; }
.search-clear:hover { background: var(--red); color: #fff; }

/* ========== Sort Bar ========== */
.sort-bar {
    display: flex;
    gap: 6px;
    padding: 12px 16px 0;
}

.sort-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s;
}

.sort-chip:hover { border-color: var(--text-3); color: var(--text-1); }

.sort-chip.active {
    background: var(--accent-muted);
    border-color: var(--accent);
    color: var(--accent-hover);
}

/* ========== Content ========== */
.content {
    flex: 1;
    padding: 16px;
    padding-bottom: 100px;
}

/* ========== Sections ========== */
.section { margin-bottom: 24px; }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
}

/* ========== Folder Grid ========== */
.folder-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.folder-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.folder-card:hover {
    background: var(--bg-2);
    border-color: rgba(255, 255, 255, 0.1);
}

.folder-card:active {
    background: var(--bg-active);
}

.folder-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent-muted);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.folder-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.folder-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.folder-card:hover .folder-actions { opacity: 1; }

.folder-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: var(--bg-3);
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.folder-action-btn:hover { background: var(--red); color: #fff; }
.folder-action-btn.rename:hover { background: var(--amber); color: #000; }

/* ========== File List ========== */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    cursor: default;
}

.file-row:hover { background: var(--bg-2); }

.file-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.file-icon.image { background: rgba(99, 102, 241, 0.12); }
.file-icon.video { background: rgba(239, 68, 68, 0.12); }
.file-icon.audio { background: rgba(34, 197, 94, 0.12); }
.file-icon.file  { background: rgba(113, 113, 122, 0.12); }
.file-icon.sticker { background: rgba(245, 158, 11, 0.12); }

/* ========== Thumbnail ========== */
.file-thumb {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-3);
}

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

.file-row:has(.file-thumb) {
    cursor: pointer;
}

/* ========== Preview Overlay ========== */
.preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(12px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.preview-box {
    max-width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.preview-box img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--radius);
    object-fit: contain;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.preview-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    justify-content: space-between;
}

.preview-name {
    font-size: 13px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.preview-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.preview-close:hover { background: rgba(255, 255, 255, 0.2); }

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-3);
}

.file-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.file-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    border: none;
    background: transparent;
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.file-btn:hover { background: var(--bg-3); color: var(--text-0); }
.file-btn.move:hover { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.file-btn.delete:hover { background: rgba(239, 68, 68, 0.15); color: var(--red); }

/* ========== Empty ========== */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 24px;
    text-align: center;
}

.empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: var(--bg-2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
    margin-bottom: 20px;
}

.empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: 6px;
}

.empty-desc {
    font-size: 13px;
    color: var(--text-3);
    line-height: 1.5;
}

/* ========== FAB ========== */
.fab {
    position: fixed;
    bottom: calc(88px + var(--safe-bottom));
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    border: none;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
    transition: transform 0.15s, box-shadow 0.15s;
    z-index: 50;
}

.fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(99, 102, 241, 0.45); }
.fab:active { transform: scale(0.95); }

/* ========== Bottom Bar ========== */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 16px;
    padding-bottom: max(8px, var(--safe-bottom));
    background: rgba(9, 9, 11, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.bottom-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 16px;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: 10px;
    font-weight: 500;
    border-radius: var(--radius-xs);
    transition: color 0.15s;
}

.bottom-btn:active { color: var(--text-0); }

.bottom-btn.primary {
    background: var(--accent);
    color: #fff;
    padding: 6px 24px;
    border-radius: 20px;
    font-weight: 600;
}

.bottom-btn.primary:active { opacity: 0.85; }

/* ========== Modal ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
}

.modal.open { display: flex; }

.modal-sheet {
    width: 100%;
    max-width: 600px;
    background: var(--bg-1);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 12px 20px calc(20px + var(--safe-bottom));
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-3);
    margin: 0 auto 16px;
}

.modal-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
}

.modal-subtitle {
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-2);
    border-radius: var(--radius-xs);
    word-break: break-all;
}

.modal-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text-0);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 16px;
}

.modal-input:focus { border-color: var(--border-focus); }

.modal-row {
    display: flex;
    gap: 10px;
}

.modal-btn {
    flex: 1;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s;
}

.modal-btn.full { flex: unset; min-width: 120px; }

.modal-btn.primary {
    background: var(--accent);
    color: #fff;
}

.modal-btn.primary:hover { background: var(--accent-hover); }
.modal-btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }

.modal-btn.secondary {
    background: var(--bg-3);
    color: var(--text-1);
}

.modal-btn.secondary:hover { background: var(--bg-hover); }

/* ========== Folder Tree (Move) ========== */
.folder-tree {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.12s;
}

.tree-item:last-child { border-bottom: none; }
.tree-item:hover { background: var(--bg-2); }

.tree-item.selected {
    background: var(--accent-muted);
    color: var(--accent-hover);
}

.tree-item.root { font-weight: 600; }

/* ========== Stats ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    text-align: center;
    padding: 16px 8px;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

/* ========== Upload Overlay ========== */
.upload-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    min-width: 200px;
}

.upload-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg-3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.upload-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-1);
}

.upload-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-3);
    border-radius: 2px;
    overflow: hidden;
}

.upload-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 20px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-0);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 400;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

/* ========== Search Results ========== */
.results-panel {
    display: none;
    padding: 0 16px;
}

.results-panel.visible { display: block; }

.results-count {
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: 8px;
    font-weight: 500;
}

.result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.12s;
}

.result-item:hover { background: var(--bg-2); }

.result-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.result-icon.image { background: rgba(99, 102, 241, 0.12); }
.result-icon.video { background: rgba(239, 68, 68, 0.12); }
.result-icon.audio { background: rgba(34, 197, 94, 0.12); }
.result-icon.file { background: rgba(113, 113, 122, 0.12); }

.result-info { flex: 1; min-width: 0; }

.result-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-path {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 1px;
}

.result-size {
    font-size: 12px;
    color: var(--text-3);
    flex-shrink: 0;
}

/* ========== Drag & Drop ========== */
.content.drag-over {
    background: var(--accent-muted);
}

/* ========== Touch ========== */
@media (hover: none) {
    .folder-actions { opacity: 1; }
    .folder-card:active { background: var(--bg-2); }
    .file-row:active { background: var(--bg-2); }
}

/* ========== Mobile ========== */
@media (max-width: 600px) {
    .fab { display: none; }

    .content { padding-bottom: 100px; }

    .folder-card { padding: 10px; gap: 10px; }
    .folder-icon { width: 36px; height: 36px; border-radius: 8px; }
    .folder-name { font-size: 13px; }

    .file-row { padding: 10px; gap: 10px; }
    .file-icon { width: 36px; height: 36px; font-size: 16px; }
    .file-thumb { width: 40px; height: 40px; }
    .file-name { font-size: 13px; }

    .stats-grid { gap: 6px; }
    .stat-card { padding: 12px 6px; }
    .stat-value { font-size: 22px; }

    .modal-sheet { padding: 12px 16px calc(16px + var(--safe-bottom)); }
}

@media (max-width: 360px) {
    .header-title h1 { font-size: 16px; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ========== Reduced Motion ========== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
