:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #e2e4e9;
    --text: #1c1e21;
    --muted: #6b7280;
    --accent: #2f6fed;
    --accent-hover: #2559c4;
    --accent-soft: #eef3ff;
    --danger: #d1453b;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* --- Auth screen --- */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 24px rgba(0,0,0,.06);
}

.auth-box h1 {
    font-size: 1.25rem;
    margin: 0 0 8px;
}

.auth-hint {
    color: var(--muted);
    font-size: .9rem;
    margin: 0 0 20px;
}

.auth-box input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    margin-bottom: 12px;
}

.auth-box button {
    width: 100%;
    padding: 10px 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
}

.auth-box button:hover { background: var(--accent-hover); }

.auth-error {
    color: var(--danger);
    font-size: .85rem;
    margin: -4px 0 12px;
}

/* --- App shell --- */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: rgba(255, 255, 255, .85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 1px 0 var(--border), var(--shadow-sm);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.brand {
    font-weight: 600;
    letter-spacing: -.01em;
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 3px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
}

.logout-link {
    color: var(--muted);
    text-decoration: none;
    font-size: .85rem;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background-color .15s ease, color .15s ease;
}
.logout-link:hover { color: var(--text); background: var(--bg); }

.main-layout {
    flex: 1;
    display: flex;
    min-height: 0;
}

.tree-pane {
    width: 272px;
    flex-shrink: 0;
    background: var(--panel);
    box-shadow: 1px 0 0 var(--border);
    overflow-y: auto;
    padding: 14px 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.tree-pane::-webkit-scrollbar { width: 8px; }
.tree-pane::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
.tree-pane::-webkit-scrollbar-thumb:hover { background: #c9ccd4; }

.tree-pane-title {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    padding: 4px 10px 12px;
}

.tree, .tree ul {
    list-style: none;
    margin: 0;
    padding-left: 16px;
}

.tree { padding-left: 0; }
.tree ul { position: relative; }
.tree ul::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 4px;
    width: 1px;
    background: var(--border);
}

.tree-node-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    margin: 1px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: .87rem;
    user-select: none;
    position: relative;
    color: var(--text);
    transition: background-color .12s ease, color .12s ease;
}

.tree-node-row:hover { background: var(--bg); }
.tree-node-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-node-row.active::before {
    content: "";
    position: absolute;
    left: -7px;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 3px;
    background: var(--accent);
}

.tree-caret {
    width: 14px;
    flex-shrink: 0;
    display: inline-block;
    text-align: center;
    color: var(--muted);
    font-size: .65rem;
    transition: transform .18s ease;
}
.tree-caret.expanded { transform: rotate(90deg); }

@keyframes tree-node-in {
    from { opacity: 0; transform: translateY(-3px); }
    to { opacity: 1; transform: translateY(0); }
}
.tree-node-enter { animation: tree-node-in .16s ease both; }

.content-pane {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    font-size: .85rem;
    color: var(--muted);
    margin-bottom: 18px;
}
.breadcrumb a {
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
    padding: 3px 4px;
    border-radius: 4px;
    transition: background-color .12s ease, color .12s ease;
}
.breadcrumb a:hover { background: var(--bg); color: var(--accent); }
.breadcrumb .crumb-current {
    color: var(--text);
    font-weight: 600;
    padding: 3px 4px;
}
.breadcrumb .crumb-sep {
    color: var(--border);
    margin: 0 2px;
    font-size: .75rem;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-row, .folder-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    background: var(--panel);
    border: 1px solid var(--border);
    transition: border-color .12s ease, box-shadow .12s ease;
}

.folder-row {
    cursor: pointer;
}
.folder-row:hover, .file-row:hover { border-color: #c7d2e0; box-shadow: var(--shadow-sm); }
.folder-row:hover { border-color: var(--accent); }

.row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.folder-badge {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent);
}

.file-badge {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8.5px;
    font-weight: 700;
    letter-spacing: .01em;
    text-transform: uppercase;
    line-height: 1;
}

.file-badge--image  { background: #f3e8ff; color: #9333ea; }
.file-badge--video   { background: #ffe4e6; color: #e11d48; }
.file-badge--audio   { background: #fce7f3; color: #db2777; }
.file-badge--pdf     { background: #fee2e2; color: #dc2626; }
.file-badge--archive { background: #fef3c7; color: #b45309; }
.file-badge--doc     { background: #dbeafe; color: #2563eb; }
.file-badge--sheet   { background: #dcfce7; color: #16a34a; }
.file-badge--slide   { background: #ffedd5; color: #c2410c; }
.file-badge--code    { background: #e2e8f0; color: #475569; }
.file-badge--exe     { background: #f1f5f9; color: #64748b; }
.file-badge--default { background: #f1f5f9; color: #94a3b8; }

.tree-node-row .folder-badge {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    background: transparent;
}
.tree-node-row .folder-badge svg { width: 13px; height: 13px; }
.row-meta { color: var(--muted); font-size: .8rem; flex-shrink: 0; }

.drag-handle {
    color: var(--muted);
    cursor: grab;
    width: 14px;
    text-align: center;
    flex-shrink: 0;
    font-size: .9rem;
}
.file-row.dragging, .folder-row.dragging { opacity: .4; }
.folder-row.drop-target {
    border-color: var(--accent);
    background: #eaf1ff;
    box-shadow: inset 0 0 0 2px var(--accent);
}

.inline-rename-input {
    flex: 1;
    padding: 3px 6px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    font-size: .95rem;
    font-family: inherit;
}

.download-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: .82rem;
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
}
.download-btn:hover { background: var(--accent-hover); }

.empty-state {
    color: var(--muted);
    font-size: .9rem;
    padding: 40px 0;
    text-align: center;
}

/* --- Admin extras --- */
.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--panel);
    cursor: pointer;
    font-size: .85rem;
    transition: border-color .12s ease, color .12s ease, background-color .12s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    color: var(--muted);
    transition: border-color .12s ease, color .12s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--muted);
    margin-bottom: 16px;
    font-size: .9rem;
}
.dropzone.dragover { border-color: var(--accent); color: var(--accent); background: #f3f7ff; }

.upload-queue { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.upload-item {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: .82rem;
}
.upload-item .upload-name { display: flex; justify-content: space-between; margin-bottom: 6px; }
.upload-bar-track { background: var(--bg); border-radius: 4px; height: 6px; overflow: hidden; }
.upload-bar-fill { background: var(--accent); height: 100%; width: 0%; transition: width .15s; }
.upload-item.error .upload-bar-fill { background: var(--danger); }
.upload-item.done .upload-bar-fill { background: #2fb35a; }

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
    background: var(--panel); border-radius: var(--radius); padding: 24px;
    width: 100%; max-width: 380px; box-shadow: 0 12px 32px rgba(0,0,0,.15);
}
.modal-box h2 { margin: 0 0 14px; font-size: 1.05rem; }
.modal-box input[type="text"], .modal-box input[type="password"] {
    width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: .95rem; margin-bottom: 12px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
