:root {
    --bg: #f3f5f8;
    --panel: #ffffff;
    --line: #dbe3ec;
    --text: #1e2a39;
    --muted: #718096;
    --brand: #2970ff;
    --brand-dark: #1958d6;
    --danger: #d13a3a;
    --ok: #1f9d60;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(180deg, #eef3f8 0%, #f7f9fc 220px, #f3f5f8 100%);
    color: var(--text);
    min-height: 100vh;
}

.topbar {
    height: 60px;
    background: linear-gradient(90deg, #1f4fa8 0%, #2c6be8 65%, #3f7eff 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    box-shadow: 0 10px 24px rgba(25, 46, 88, 0.18);
}

.brand {
    font-weight: 700;
    letter-spacing: 0.2px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.brand-badge {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.shell {
    max-width: 1180px;
    margin: 18px auto;
    padding: 0 14px 30px;
}

.tab-row {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.tab {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    border-radius: 10px;
    height: 34px;
    padding: 0 14px;
    cursor: pointer;
}

.tab.active {
    background: rgba(41, 112, 255, 0.12);
    border-color: rgba(41, 112, 255, 0.42);
    color: var(--brand-dark);
    font-weight: 600;
}

.panel {
    background: var(--panel);
    border-radius: 14px;
    border: 1px solid var(--line);
    box-shadow: 0 12px 26px rgba(19, 45, 74, 0.06);
    padding: 14px;
}

.settings-auth-panel {
    width: min(560px, 94vw);
    margin: 24px auto;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.toolbar-spacer {
    flex: 1 1 auto;
}

.view-switch {
    display: flex;
    gap: 8px;
}

.sort-select-wrap {
    position: relative;
    min-width: 168px;
}

.sort-select-wrap::after {
    content: '▾';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #6681a8;
    font-size: 12px;
    pointer-events: none;
}

.sort-select {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 34px;
    border-radius: 10px;
    border: 1px solid #cfdcf0;
    background: linear-gradient(180deg, #ffffff 0%, #f6faff 100%);
    color: #203552;
    font-size: 13px;
    padding: 0 30px 0 12px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.sort-select:hover {
    border-color: #b6cbeb;
}

.sort-select:focus {
    outline: none;
    border-color: #5f95f5;
    box-shadow: 0 0 0 3px rgba(47, 108, 255, 0.16);
}

.view-btn.active {
    background: rgba(41, 112, 255, 0.12);
    border-color: rgba(41, 112, 255, 0.42);
    color: var(--brand-dark);
}

.breadcrumb {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--muted);
}

.bc-btn {
    background: none;
    border: none;
    color: var(--brand-dark);
    cursor: pointer;
    padding: 0;
}

.btn {
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 0 12px;
    cursor: pointer;
    touch-action: manipulation;
}

a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn:hover {
    border-color: #b9c8d8;
}

.btn-primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

.btn-primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
}

.btn-danger {
    color: var(--danger);
    border-color: rgba(209, 58, 58, 0.35);
    background: #fff;
}

.btn-ghost {
    background: transparent;
}

.status-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    height: 28px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.2);
    font-size: 13px;
}

.table-wrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: auto;
    background: #fff;
}

.listing-stage {
    position: relative;
    min-height: 180px;
}

.listing-stage.loading .view-pane {
    opacity: 0.66;
}

.listing-loading {
    position: fixed;
    left: 50%;
    top: clamp(74px, 16vh, 140px);
    transform: translateX(-50%);
    z-index: 18;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 14px;
    color: #45628a;
    border-radius: 999px;
    border: 1px solid #d3e1f6;
    background: rgba(247, 250, 255, 0.96);
    backdrop-filter: blur(6px);
    box-shadow: 0 10px 22px rgba(29, 52, 90, 0.14);
    pointer-events: none;
    animation: loadingReveal 150ms ease;
}

.loading-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #9fbbef;
    border-top-color: #2b69e0;
    animation: spin 700ms linear infinite;
}

.view-pane {
    animation: viewFadeIn 220ms ease;
}

.view-pane.entering {
    animation: directoryEnter 240ms ease;
}

.view-pane.reloading {
    animation: reloadPulse 220ms ease;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 0;
    table-layout: fixed;
}

thead {
    background: #f8fbff;
}

th,
td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid #edf2f8;
    font-size: 14px;
    vertical-align: top;
}

th:nth-child(1),
td.col-name {
    width: 34%;
}

th:nth-child(2),
td.col-size {
    width: 12%;
}

th:nth-child(3),
td.col-updated {
    width: 20%;
}

th:nth-child(4),
td.col-actions {
    width: 34%;
}

td.col-size,
td.col-updated {
    white-space: nowrap;
}

tr:hover {
    background: #fafcff;
}

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

.icon {
    width: 20px;
    text-align: center;
}

.clickable-folder {
    display: inline-block;
    max-width: calc(100% - 28px);
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    color: #1d58ce;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clickable-folder:hover {
    color: #1647a6;
}

.file-name > span:last-child {
    display: inline-block;
    max-width: calc(100% - 28px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col-actions {
    min-width: 0;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.row-actions .btn {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
}

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

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    background: #fff;
}

.card h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.field {
    margin-bottom: 10px;
}

.field label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 10px;
    font-size: 14px;
}

.field input[type='password'] {
    max-width: 80vw;
}

.field textarea {
    min-height: 72px;
    padding: 10px;
}

.hidden {
    display: none !important;
}

.notice {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: #15263f;
    color: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    max-width: 320px;
    font-size: 13px;
    box-shadow: 0 10px 26px rgba(14, 21, 33, 0.28);
    opacity: 0;
    transform: translateY(10px);
    transition: all 180ms ease;
    pointer-events: none;
}

.notice.show {
    opacity: 1;
    transform: translateY(0);
}

.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(20, 28, 43, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.modal-mask.anim-in {
    animation: maskFadeIn 180ms ease;
}

.modal-mask.anim-out {
    animation: maskFadeOut 180ms ease forwards;
}

.modal {
    width: min(520px, 80vw);
    max-width: 80vw;
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--line);
    padding: 14px;
}

.modal.anim-in {
    animation: modalPopIn 190ms ease;
}

.modal.anim-out {
    animation: modalPopOut 160ms ease forwards;
}

.modal .field input[type='password'] {
    width: min(100%, 80vw);
}

.modal h3 {
    margin: 0 0 10px;
}

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

.action-modal {
    width: min(460px, 86vw);
}

.upload-progress-modal {
    width: min(860px, 94vw);
    max-height: 90vh;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.upload-progress-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid #e8eef7;
    background: #f8fbff;
}

.upload-progress-head h3 {
    margin: 0 0 4px;
}

.upload-conflict-panel {
    padding: 14px;
    border-bottom: 1px solid #edf2f8;
    background: #fff;
}

.upload-conflict-info {
    margin-bottom: 10px;
}

.upload-conflict-title {
    font-size: 15px;
    font-weight: 700;
    color: #203552;
    margin-bottom: 4px;
}

.upload-conflict-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.upload-conflict-actions .btn {
    min-width: 88px;
}

.upload-overall {
    padding: 12px 14px;
    border-bottom: 1px solid #edf2f8;
    background: #fff;
}

.upload-overall-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.upload-overall-row + .upload-overall-row {
    margin-top: 8px;
}

.upload-overall-bar {
    margin-top: 8px;
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: #e8eef8;
}

.upload-overall-bar > span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #2f6cff 0%, #4f89ff 100%);
    transition: width 120ms linear;
}

.upload-progress-list {
    padding: 12px 14px 14px;
    overflow: auto;
    background: #fcfdff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: min(58vh, 540px);
}

.upload-item {
    border: 1px solid #e4ebf6;
    border-radius: 10px;
    background: #fff;
    padding: 10px;
}

.upload-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 7px;
}

.upload-item-name {
    font-size: 13px;
    color: #233a5a;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-badge {
    font-size: 11px;
    line-height: 1;
    border-radius: 999px;
    padding: 4px 8px;
    border: 1px solid #dce5f4;
    color: #4b607f;
    background: #f6f9ff;
    white-space: nowrap;
}

.upload-badge.pending {
    color: #4b607f;
    border-color: #dce5f4;
    background: #f6f9ff;
}

.upload-badge.signing,
.upload-badge.uploading {
    color: #1f56c4;
    border-color: #bed2ff;
    background: #edf3ff;
}

.upload-badge.success {
    color: #137248;
    border-color: #bfe8d2;
    background: #ebfaf2;
}

.upload-badge.error {
    color: #b12f2f;
    border-color: #f2c3c3;
    background: #fff0f0;
}

.upload-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.upload-item-bar {
    margin-top: 7px;
    height: 6px;
    border-radius: 999px;
    overflow: hidden;
    background: #eaf0fa;
}

.upload-item-bar > span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #2f6cff 0%, #4f89ff 100%);
    transition: width 120ms linear;
}

.upload-item-error {
    margin-top: 6px;
    font-size: 12px;
    color: #b33131;
    word-break: break-word;
}

.protected-list {
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.protected-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid #edf2f8;
    font-size: 14px;
}

.protected-row:last-child {
    border-bottom: none;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.gallery-card {
    border: none;
    border-radius: 0;
    overflow: visible;
    background: transparent;
    width: 100%;
    min-width: 0;
}

.gallery-card[data-preview-key] {
    cursor: pointer;
}

.gallery-thumb {
    min-height: 0;
    background: transparent;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    font-size: 24px;
    color: #8ca2c1;
    overflow: visible;
    padding: 0;
    width: 100%;
    position: relative;
}

.gallery-thumb-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: min(44vh, calc(100vh - 230px));
    color: #5f779a;
    font-size: 13px;
}

.gallery-thumb img,
.gallery-thumb video,
.gallery-thumb canvas {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: min(44vh, calc(100vh - 230px));
    object-fit: contain;
    display: block;
    border: 2px solid #2f6cff;
    border-radius: 12px;
    background: transparent;
    pointer-events: none;
}

.gallery-thumb video {
    box-shadow: 0 18px 36px rgba(16, 42, 84, 0.12);
}

.gallery-thumb canvas {
    box-shadow: 0 18px 36px rgba(16, 42, 84, 0.12);
}

.gallery-file-badge {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: rgba(16, 27, 55, 0.82);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    pointer-events: none;
    box-shadow: 0 10px 24px rgba(7, 17, 37, 0.22);
}

.gallery-pdf-badge {
    width: auto;
    min-width: 42px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: rgba(187, 42, 42, 0.92);
}

.preview-modal {
    width: min(1120px, 80vw);
    max-width: 80vw;
    max-height: 80vh;
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-modal.anim-in {
    animation: modalPopIn 190ms ease;
}

.preview-modal.anim-out {
    animation: modalPopOut 160ms ease forwards;
}

.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 14px;
    height: 14px;
    margin-left: -7px;
    margin-top: -7px;
    border: 2px solid rgba(31, 58, 108, 0.2);
    border-top-color: #1e4aa7;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

.btn.btn-primary.is-loading::after {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
}

.preview-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid #e8eef7;
    background: #f9fbff;
}

.preview-title-wrap h3 {
    margin: 0 0 4px;
}

.preview-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.preview-actions .btn {
    height: 32px;
    padding: 0 12px;
}

.preview-body {
    min-height: 220px;
    max-height: calc(80vh - 78px);
    padding: 12px;
    overflow: auto;
    background: #fdfefe;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-media {
    max-width: 100%;
    max-height: calc(80vh - 130px);
    border-radius: 8px;
    border: 1px solid #e3ebf5;
    background: #fff;
}

.preview-text {
    width: min(96%, 980px);
    max-height: calc(80vh - 150px);
    overflow: auto;
    border: 1px solid #e3ebf5;
    background: #fff;
    border-radius: 8px;
    padding: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
}

.pdf-viewer {
    width: min(100%, 1024px);
    max-width: 100%;
    height: min(calc(80vh - 142px), 860px);
    max-height: calc(80vh - 142px);
    border: 1px solid #e3ebf5;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-self: stretch;
    margin: 0 auto;
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid #e8eef7;
    background: #f8fbff;
    flex-wrap: wrap;
}

.pdf-toolbar .btn {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
}

.pdf-toolbar .btn.active {
    background: rgba(41, 112, 255, 0.14);
    border-color: rgba(41, 112, 255, 0.45);
    color: var(--brand-dark);
}

.pdf-toolbar-spacer {
    flex: 1 1 auto;
}

.pdf-page-indicator,
.pdf-zoom,
.pdf-status {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.pdf-canvas-wrap {
    flex: 1 1 auto;
    overflow: auto;
    background: #f3f7fd;
    display: flex;
    justify-content: center;
    padding: 12px;
}

.pdf-canvas-wrap canvas {
    background: #fff;
    box-shadow: 0 8px 22px rgba(23, 49, 90, 0.15);
    border-radius: 6px;
}

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

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

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

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

@keyframes modalPopIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modalPopOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
}

@keyframes viewFadeIn {
    from {
        opacity: 0.3;
    }
    to {
        opacity: 1;
    }
}

@keyframes directoryEnter {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes reloadPulse {
    from {
        opacity: 0.45;
    }
    to {
        opacity: 1;
    }
}

@media (max-width: 780px) {
    .shell {
        margin-top: 10px;
    }

    .topbar {
        height: auto;
        padding: 10px 12px;
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .toolbar {
        gap: 6px;
    }

    .toolbar-spacer {
        display: none;
    }

    .view-switch {
        width: 100%;
    }

    .view-switch .btn {
        flex: 1 1 auto;
    }

    .sort-select-wrap {
        width: 100%;
        min-width: 0;
    }

    table {
        table-layout: fixed;
    }

    th,
    td {
        padding: 8px 6px;
        font-size: 13px;
    }

    th:nth-child(2),
    td.col-size,
    th:nth-child(3),
    td.col-updated {
        display: none;
    }

    th:nth-child(1),
    td.col-name {
        width: 44%;
    }

    th:nth-child(4),
    td.col-actions {
        width: 56%;
    }

    .row-actions .btn {
        flex: 1 1 calc(50% - 6px);
        min-width: 0;
        padding: 0 8px;
    }

    .row-actions .btn[data-action="protect-folder"] {
        flex-basis: 100%;
    }

    .preview-head {
        flex-direction: column;
    }

    .preview-actions {
        width: 100%;
    }

    .preview-actions .btn {
        flex: 1 1 auto;
    }

    .gallery-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .listing-loading {
        top: clamp(96px, 18vh, 170px);
    }

    .gallery-thumb {
        width: 100%;
    }

    .gallery-thumb img,
    .gallery-thumb video,
    .gallery-thumb canvas {
        max-width: 100%;
        max-height: min(30vh, calc(100vh - 260px));
    }

    .preview-modal {
        width: min(80vw, 80vw);
        max-width: 80vw;
        max-height: 80vh;
    }

    .preview-body {
        max-height: calc(80vh - 112px);
    }

    .pdf-viewer {
        height: min(calc(80vh - 188px), 64vh);
        max-height: calc(80vh - 188px);
    }

    .pdf-toolbar-spacer {
        display: none;
    }

    .upload-progress-modal {
        width: min(96vw, 96vw);
        max-height: 88vh;
    }

    .upload-progress-head {
        flex-direction: column;
    }

    .upload-progress-head .btn {
        width: 100%;
    }

    .upload-conflict-actions .btn {
        flex: 1 1 auto;
    }

    .upload-progress-list {
        max-height: 52vh;
    }
}
