:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8f0;
    --border-strong: #cfd7e3;
    --text: #1f2733;
    --text-dim: #7b8798;
    --accent: #3b6ef5;
    --accent-soft: #e8f0ff;
    --green: #16a34a;
    --red: #dc2626;
    --amber: #d97706;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d3dbe6; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b8c3d4; background-clip: content-box; }

/* ================= 登录页 ================= */
#loginView {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(160deg, #eef3ff 0%, #f7f9fc 55%, #f4f6fb 100%);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 38px 34px;
    box-shadow: var(--shadow);
}
.login-logo {
    width: 54px; height: 54px;
    margin: 0 auto 16px;
    border-radius: 15px;
    background: linear-gradient(135deg, #3b6ef5, #6d8dff);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 23px;
    box-shadow: 0 8px 20px rgba(59, 110, 245, .3);
}
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 5px; }
.login-card .sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: #46536a; }
.field input, .field select {
    width: 100%;
    padding: 11px 13px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    font-size: 14px;
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: #fff;
}
.btn-block {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 14.5px;
    font-weight: 600;
    transition: filter .15s, transform .08s;
}
.btn-block:hover { filter: brightness(1.06); }
.btn-block:active { transform: scale(.985); }
.btn-block:disabled { opacity: .6; cursor: not-allowed; }
.login-error {
    display: none;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 9px;
    padding: 9px 13px;
    font-size: 13px;
    margin-bottom: 14px;
}

/* ================= 布局 ================= */
#appView { display: none; height: 100vh; grid-template-rows: auto auto 1fr; }
#appView.on { display: grid; }

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand-icon {
    width: 32px; height: 32px; border-radius: 9px;
    background: linear-gradient(135deg, #3b6ef5, #6d8dff);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px;
}
.search-box { flex: 1; max-width: 320px; position: relative; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-dim); font-size: 12px; }
.search-box input {
    width: 100%;
    padding: 9px 12px 9px 34px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    font-size: 13px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.user-tag { font-size: 12px; color: var(--text-dim); }

.btn {
    padding: 8px 15px;
    border-radius: 9px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: all .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.07); }
.icon-btn {
    width: 34px; height: 34px; border-radius: 9px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-dim);
    display: inline-flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.icon-btn:hover { color: var(--red); border-color: #f3b6b6; background: #fff5f5; }

/* ================= 工具栏 ================= */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    min-height: 56px;
}
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13.5px; min-width: 0; }
.crumbs .crumb {
    background: none; border: none; color: var(--accent);
    padding: 4px 7px; border-radius: 7px; font-size: 13.5px; max-width: 220px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumbs .crumb:hover { background: var(--accent-soft); }
.crumbs .sep { color: var(--text-dim); }
.crumbs .here { color: var(--text); font-weight: 600; padding: 4px 7px; }
.toolbar .spacer { flex: 1; }

/* 选择/剪贴板提示条 */
.actionbar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    background: var(--accent-soft);
    border-bottom: 1px solid #d4e2ff;
    font-size: 13px;
    color: #2c4fa8;
    flex-wrap: wrap;
}
.actionbar.on { display: flex; }
.actionbar .spacer { flex: 1; }
.actionbar .sel-count { font-weight: 700; }

/* ================= 文件区 ================= */
.main { overflow-y: auto; padding: 20px 22px 70px; }
.section-label {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .8px;
    margin: 6px 2px 12px;
}
.section-label:not(:first-child) { margin-top: 28px; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 12px;
}
.card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s, transform .1s;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.card-check {
    position: absolute; top: 8px; left: 8px; z-index: 3;
    width: 20px; height: 20px; cursor: pointer; accent-color: var(--accent);
    opacity: 0; transition: opacity .12s;
}
.card:hover .card-check, .card.selected .card-check { opacity: 1; }
.card-thumb {
    height: 104px;
    background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; cursor: pointer; border-bottom: 1px solid var(--border);
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-thumb i { font-size: 34px; }
.card-thumb .folder-ico { font-size: 40px; color: #f0b429; }
.card-thumb .play-badge {
    position: absolute; width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.85); color: #1f2733;
    display: flex; align-items: center; justify-content: center; font-size: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
}
.card-info { padding: 9px 11px 11px; }
.card-name {
    font-size: 12.8px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    cursor: pointer;
}
.card-name:hover { color: var(--accent); }
.card-meta { font-size: 11px; color: var(--text-dim); margin-top: 4px; display: flex; justify-content: space-between; gap: 6px; }
.card-actions {
    position: absolute; top: 7px; right: 7px; z-index: 2;
    display: flex; gap: 4px; opacity: 0; transition: opacity .12s;
}
.card:hover .card-actions { opacity: 1; }
.card-actions button {
    width: 26px; height: 26px; border-radius: 7px; border: none;
    background: rgba(255,255,255,.92); color: #38445a; font-size: 11.5px;
    box-shadow: 0 1px 4px rgba(16,24,40,.16);
    display: inline-flex; align-items: center; justify-content: center;
}
.card-actions button:hover { background: var(--accent); color: #fff; }
.card-actions button.del:hover { background: var(--red); }

.empty-state { text-align: center; padding: 70px 20px; color: var(--text-dim); }
.empty-state i { font-size: 42px; opacity: .35; margin-bottom: 12px; display: block; }

/* ================= 拖拽遮罩 ================= */
#dropOverlay {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(59,110,245,.12); backdrop-filter: blur(2px);
    display: none; align-items: center; justify-content: center;
    pointer-events: none;
}
#dropOverlay.on { display: flex; }
.drop-inner {
    border: 3px dashed var(--accent); border-radius: 20px;
    padding: 50px 80px; text-align: center; color: var(--accent);
    background: rgba(255,255,255,.9);
}
.drop-inner i { font-size: 44px; margin-bottom: 12px; display: block; }
.drop-inner p { font-size: 16px; font-weight: 700; }

/* ================= 弹窗 ================= */
.modal-bg {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(23,32,48,.45);
    display: none; align-items: center; justify-content: center;
    padding: 20px; opacity: 0; transition: opacity .18s;
}
.modal-bg.on { display: flex; }
.modal-bg.show { opacity: 1; }
.modal {
    background: var(--surface);
    border-radius: 16px;
    width: 100%; max-width: 430px; max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 24px 60px rgba(16,24,40,.28);
    transform: translateY(14px) scale(.98);
    transition: transform .18s;
}
.modal-bg.show .modal { transform: none; }
.modal.wide { max-width: 860px; }
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 18px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 9px; padding: 0 20px 20px; }
.modal-foot .btn { flex: 1; justify-content: center; padding: 10px; }
.warn-box {
    background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
    border-radius: 9px; padding: 11px 13px; font-size: 13px; margin-bottom: 15px; line-height: 1.6;
}
.hint { font-weight: 400; color: var(--text-dim); font-size: 12px; }

/* 上传队列 */
.up-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 9px; margin-bottom: 7px;
}
.up-item .nm { flex: 1; min-width: 0; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .st { font-size: 11.5px; color: var(--text-dim); flex-shrink: 0; }
.up-item .st.err { color: var(--red); }
.up-item .st.ok { color: var(--green); }
.up-bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.up-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .12s; }

/* 预览 */
#lightbox {
    position: fixed; inset: 0; z-index: 600;
    background: rgba(15,20,30,.9);
    display: none; align-items: center; justify-content: center; padding: 30px;
}
#lightbox.on { display: flex; }
.preview-box { max-width: 92vw; max-height: 92vh; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.preview-box img, .preview-box video { max-width: 92vw; max-height: 82vh; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.5); background: #000; }
.preview-box iframe { width: 88vw; height: 82vh; border: none; border-radius: 8px; background: #fff; }
.preview-name { color: #e5e9f0; font-size: 13px; }

/* Toast */
#toasts { position: fixed; bottom: 22px; right: 22px; z-index: 700; display: flex; flex-direction: column; gap: 9px; }
.toast {
    display: flex; align-items: center; gap: 9px;
    padding: 11px 16px; border-radius: 10px; color: #fff;
    font-size: 13.5px; font-weight: 500;
    box-shadow: 0 10px 28px rgba(16,24,40,.22);
    animation: toastIn .2s ease-out; max-width: 340px;
}
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }
@keyframes toastIn { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.out { animation: toastOut .2s ease-in forwards; }
@keyframes toastOut { to { transform: translateY(14px); opacity: 0; } }

@media (max-width: 760px) {
    .topbar { gap: 10px; }
    .search-box { order: 3; max-width: none; flex-basis: 100%; }
    .main { padding: 14px 12px 70px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    .toolbar { padding: 10px 12px; }
}
