:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --line: #e5e9f2;
    --text: #1f2733;
    --muted: #7b8798;
    --accent: #4c6ef5;
    --accent-soft: #eef2ff;
    --danger: #e5484d;
    --radius: 12px;
    --sidebar-w: 268px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

input,
select {
    font: inherit;
    color: inherit;
}

/* ===== 布局 ===== */

.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 14px;
}

.brand .logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #4c6ef5, #7c8cf8);
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-title {
    font-weight: 600;
    font-size: 15px;
}

.brand-sub {
    font-size: 12px;
    color: var(--muted);
}

.quick {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px 10px;
    border-bottom: 1px solid var(--line);
}

.quick button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text);
    text-align: left;
}

.quick button:hover {
    background: #f2f5fb;
}

.quick button.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.tree-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 6px;
    font-size: 12px;
    letter-spacing: .08em;
    color: var(--muted);
}

.tree-head button {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 16px;
    line-height: 1;
    color: var(--muted);
}

.tree-head button:hover {
    background: #f2f5fb;
    color: var(--accent);
}

.tree {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 8px 12px;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding-right: 6px;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.tree-row:hover {
    background: #f2f5fb;
}

.tree-row.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.tree-row.drop-before {
    box-shadow: inset 0 2px 0 var(--accent);
}

.tree-row.drop-after {
    box-shadow: inset 0 -2px 0 var(--accent);
}

.tree-row.drop-inside {
    background: #e3e9ff;
    outline: 1px dashed var(--accent);
}

.tree-row.dragging {
    opacity: .45;
}

.tree-row .caret {
    width: 14px;
    flex: 0 0 14px;
    text-align: center;
    font-size: 10px;
    color: var(--muted);
    transition: transform .15s;
}

.tree-row.open .caret {
    transform: rotate(90deg);
}

/* 根目录不显示名称，只保留一个房屋图标 */
.root-icon {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    color: var(--muted);
}

.tree-row.active .root-icon,
.crumbs a:hover .root-icon {
    color: var(--accent);
}

.crumbs .root-icon {
    display: block;
}

.tree-row .folder-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-row .row-actions {
    display: none;
    gap: 2px;
}

.tree-row:hover .row-actions {
    display: flex;
}

.tree-row .row-actions button {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    font-size: 12px;
    color: var(--muted);
}

.tree-row .row-actions button:hover {
    background: #e5e9f2;
    color: var(--text);
}

.tree-row input.rename {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--accent);
    border-radius: 5px;
    padding: 1px 4px;
    font: inherit;
    outline: none;
}

.sidebar-foot {
    border-top: 1px solid var(--line);
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.sidebar-foot button,
.sidebar-foot label {
    flex: 1;
    text-align: center;
    padding: 7px 4px;
    border-radius: 8px;
    background: #f5f7fb;
    cursor: pointer;
}

.sidebar-foot button:hover,
.sidebar-foot label:hover {
    background: #e9eefb;
    color: var(--accent);
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.crumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    font-size: 14px;
    overflow: hidden;
    white-space: nowrap;
}

.crumbs a {
    color: var(--muted);
    text-decoration: none;
    padding: 3px 6px;
    border-radius: 6px;
}

.crumbs a:hover {
    background: #f2f5fb;
    color: var(--accent);
}

.crumbs .current {
    font-weight: 600;
    color: var(--text);
}

.crumbs .sep {
    color: #c3cad6;
}

.search input {
    width: 220px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f7f9fd;
    outline: none;
    transition: border-color .15s, background .15s;
}

.search input:focus {
    border-color: var(--accent);
    background: #fff;
}

.actions {
    display: flex;
    gap: 8px;
}

.actions button {
    padding: 8px 14px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: #fff;
    white-space: nowrap;
}

.actions button:hover {
    border-color: #c8d2e8;
    background: #f7f9fd;
}

.actions button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.actions button.primary:hover {
    background: #3f5ee0;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 22px 0;
    font-size: 12px;
    color: var(--muted);
}

.toolbar select {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 5px 8px;
    background: #fff;
}

.grid {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 16px 22px 90px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
    gap: 16px;
    align-content: start;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow .18s, transform .18s, border-color .18s;
    position: relative;
}

.card:hover {
    box-shadow: 0 8px 22px rgba(31, 39, 51, .1);
    transform: translateY(-1px);
}

.card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(76, 110, 245, .18);
}

.card.dragging {
    opacity: .45;
}

.card-thumb {
    aspect-ratio: 16 / 9;
    background: #f0f3fa;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #fff;
}

.card-thumb .kind-badge {
    padding: 6px 10px;
    border-radius: 999px;
    background: #e4e9f7;
    color: #5268a8;
    font-weight: 600;
}

.card-thumb .kind-badge.html {
    background: #e7f6ee;
    color: #2f8a5c;
}

.card-body {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.card-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-sub {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    gap: 6px;
    align-items: center;
}

.card-fav {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .92);
    color: #c9d0dc;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(31, 39, 51, .08);
}

.card-fav.on {
    color: #f0a020;
}

.card-fav:hover {
    color: #f0a020;
}

.empty {
    position: absolute;
    inset: 40% 0 auto;
    text-align: center;
    color: var(--muted);
    pointer-events: none;
}

.selection-bar {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1f2733;
    color: #fff;
    border-radius: 999px;
    box-shadow: 0 10px 26px rgba(31, 39, 51, .3);
    z-index: 20;
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100% - 24px);
}

.selection-bar span {
    margin-right: 6px;
    font-size: 12px;
    opacity: .8;
}

.selection-bar button {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    white-space: nowrap;
}

.selection-bar button:hover {
    background: rgba(255, 255, 255, .24);
}

.selection-bar button.danger:hover {
    background: var(--danger);
}

.drop-hint {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(76, 110, 245, .12);
    border: 2px dashed var(--accent);
    border-radius: 16px;
    margin: 70px 22px 22px;
    color: var(--accent);
    font-weight: 600;
    pointer-events: none;
    z-index: 10;
}

.drop-hint.show {
    display: flex;
}

.upload-progress {
    position: absolute;
    right: 22px;
    bottom: 22px;
    background: #1f2733;
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 12px;
    box-shadow: 0 10px 26px rgba(31, 39, 51, .25);
}

/* ===== 通用弹层 ===== */

.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(20, 26, 36, .38);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 20px;
}

.modal {
    width: min(460px, 100%);
    max-height: 80vh;
    overflow: auto;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(20, 26, 36, .3);
    padding: 18px 20px 16px;
}

.modal h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.modal p {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 13px;
}

.modal input[type="text"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    outline: none;
}

.modal input[type="text"]:focus {
    border-color: var(--accent);
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.modal-foot button {
    padding: 8px 16px;
    border-radius: 9px;
    border: 1px solid var(--line);
}

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

.modal-foot button.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.version-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.version-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    font-size: 13px;
}

.version-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.version-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.version-meta {
    color: var(--muted);
    font-size: 12px;
}

.version-actions {
    display: flex;
    gap: 6px;
    flex: none;
}

.version-row button {
    padding: 5px 10px;
    border-radius: 7px;
    background: var(--accent-soft);
    color: var(--accent);
}

.version-row button[data-act="delete"] {
    background: #fdecec;
    color: var(--danger);
}

/* ===== 导出图片 ===== */

.modal.modal-export {
    width: min(720px, 100%);
}

.export-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 10px;
}

.export-empty {
    grid-column: 1 / -1;
    margin: 12px 0;
    font-size: 13px;
    color: var(--muted);
}

.export-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.export-thumb {
    display: block;
    aspect-ratio: 16 / 9;
    background: #f4f6fb;
}

.export-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.export-meta {
    padding: 8px 10px 4px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.export-actions {
    display: flex;
    gap: 8px;
    padding: 4px 10px 10px;
}

.export-actions button {
    flex: 1;
    padding: 6px 8px;
    border-radius: 7px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
}

.export-actions button.danger {
    flex: 0 0 auto;
    background: #fdecec;
    color: var(--danger);
}

.export-actions button:disabled {
    opacity: .5;
    cursor: default;
}

/* ===== 浮层提示 ===== */

.toast-host {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 4000;
    pointer-events: none;
}

.toast {
    padding: 9px 16px;
    border-radius: 999px;
    background: #1f2733;
    color: #fff;
    font-size: 13px;
    box-shadow: 0 10px 24px rgba(20, 26, 36, .28);
    animation: toast-in .18s ease-out;
}

.toast.error {
    background: var(--danger);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}

/* ===== 课件查看器 ===== */

body.viewer {
    background: #e9edf5;
}

.viewer-frame {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #fff;
}

/* ===== 只读浏览（未登录） ===== */

body.readonly .admin-only {
    display: none !important;
}

.sidebar-foot {
    flex-direction: column;
    align-items: stretch;
}

.account {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.account form {
    margin: 0;
}

.account-name {
    font-size: 12px;
    color: var(--muted);
}

.account-btn {
    padding: 5px 10px;
    border-radius: 8px;
    background: #f5f7fb;
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
    cursor: pointer;
}

.account-btn:hover {
    background: #e9eefb;
}

.foot-actions {
    display: flex;
    gap: 8px;
}

.foot-actions button,
.foot-actions label {
    flex: 1;
}

.selection-bar[hidden] {
    display: none;
}

/* ===== 视图切换 ===== */

.view-switch {
    display: flex;
    gap: 2px;
    margin-left: auto;
    margin-right: 10px;
    padding: 2px;
    border-radius: 8px;
    background: #f1f4fa;
}

.view-switch button {
    width: 28px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--muted);
    font-size: 13px;
}

.view-switch button.active {
    background: #fff;
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}

.grid.list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    grid-template-columns: none;
    padding-top: 10px;
}

.grid.list .card {
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 10px;
    padding-right: 12px;
}

.grid.list .card-thumb {
    flex: 0 0 88px;
    width: 88px;
    height: 50px;
    aspect-ratio: auto;
    border-radius: 6px;
    overflow: hidden;
}

.grid.list .card-body {
    flex: 1;
    min-width: 0;
    padding: 8px 0;
}

.grid.list .card-name {
    margin-bottom: 2px;
}

.grid.list .card-fav {
    position: static;
    display: inline-flex;
    box-shadow: none;
    background: transparent;
}

/* ===== 登录页 ===== */

body.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #f4f7fd 0%, #e8eef9 100%);
}

.login-card {
    width: min(380px, calc(100vw - 32px));
    padding: 28px 26px 22px;
    border-radius: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 20px 48px rgba(31, 39, 51, .12);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 20px;
}

.login-tip {
    margin: 0 0 18px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--muted);
}

.login-error {
    margin-bottom: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #fdecec;
    color: #c0392b;
    font-size: 12px;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--muted);
}

.login-field input {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    color: var(--ink);
    outline: none;
}

.login-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(76, 110, 245, .14);
}

.login-submit {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    color: #fff;
    background: var(--accent);
    font-size: 14px;
}

.login-submit:hover {
    background: #3f5ee0;
}

.login-back {
    display: block;
    margin-top: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    text-decoration: none;
}

.login-back:hover {
    color: var(--accent);
}

.login-card-wide {
    width: min(440px, calc(100vw - 32px));
}

.settings-title {
    margin: 0 0 6px;
    font-size: 14px;
    color: var(--ink);
}

.settings-divider {
    margin: 22px 0 18px;
    border: none;
    border-top: 1px solid var(--line);
}

.login-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--muted);
}

@media (max-width: 900px) {
    :root {
        --sidebar-w: 216px;
    }

    .search input {
        width: 130px;
    }

    .actions button {
        padding: 8px 10px;
    }
}
