:root {
    --bg: #f3f5fb;
    --card: #ffffff;
    --text: #212533;
    --muted: #6a7285;
    --line: #e5e8f0;
    --pri: #3a63f3;
    --pri-hover: #2a4ee0;
    --danger: #dc3545;
    --ok: #1c9c5e;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
}

.hidden {
    display: none !important;
}

.screen {
    min-height: 100vh;
    padding: 16px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 6px 16px rgba(15, 32, 67, 0.05);
    margin-bottom: 14px;
}

.login-card {
    width: min(94vw, 360px);
    margin: 14vh auto 0;
    padding: 22px;
}

.login-card h1 {
    margin: 6px 0 18px;
    font-size: 22px;
}

label {
    display: block;
    margin: 10px 0 6px;
    color: var(--muted);
    font-size: 13px;
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    padding: 9px 10px;
    font-size: 14px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #b5c2ff;
}

.btn {
    border: 1px solid var(--line);
    background: #fff;
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
}

.btn:hover {
    background: #f8f9ff;
}

.btn.primary {
    background: var(--pri);
    border-color: var(--pri);
    color: #fff;
}

.btn.primary:hover {
    background: var(--pri-hover);
}

.btn.danger {
    background: #fff1f3;
    border-color: #ffc8d0;
    color: #a00f26;
}

.password-container {
    position: relative;
    margin-bottom: 16px;
}

.toggle-password {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-btn-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.login-btn-container .btn.primary {
    padding: 10px 30px;
    font-size: 14px;
}

.tips {
    color: var(--muted);
    font-size: 12px;
}

.error {
    color: #d60023;
    min-height: 18px;
    font-size: 12px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.title-wrap h2 {
    margin: 0;
}

#breadcrumb {
    font-size: 13px;
    color: var(--muted);
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar {
    padding: 10px;
    display: grid;
    grid-template-columns: 1.6fr repeat(3, minmax(120px, 160px));
    gap: 10px;
    align-items: center;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-container input {
    width: 100%;
    padding-right: 120px;
}

.clear-search-btn {
    position: absolute;
    right: 80px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--muted);
    padding: 5px;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1;
}

.clear-search-btn.visible {
    opacity: 1;
    visibility: visible;
}

.clear-search-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
}

.search-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--pri);
    border: 1px solid var(--pri);
    color: white;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 0;
    min-width: 60px;
    text-align: center;
}

.search-btn:hover {
    background: var(--pri-hover);
    border-color: var(--pri-hover);
}

.search-btn:active {
    transform: translateY(-50%) scale(0.98);
}

.search-container.searching .search-btn {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.search-container.searching .search-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.dropzone {
    border-style: dashed;
    text-align: center;
    padding: 18px;
    color: var(--muted);
}

.dropzone.dragover {
    border-color: var(--pri);
    color: var(--pri);
    background: #eef2ff;
}

.list-table {
    width: 100%;
    border-collapse: collapse;
}

.list-table th,
.list-table td {
    border-bottom: 1px solid var(--line);
    padding: 9px 10px;
    text-align: left;
    vertical-align: top;
    font-size: 13px;
}

.list-table th {
    color: #4d5671;
    background: #f8f9fd;
}

.list-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.list-table th.sortable:hover {
    background: #eef2ff;
}

.sort-indicator {
    display: inline-block;
    min-width: 14px;
    color: #7a86a8;
    font-size: 12px;
}

.list-table tr:hover td {
    background: #fafbff;
}

.name-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    word-break: break-all;
}

.pdf-name {
    cursor: pointer;
}

.pdf-name:hover {
    color: var(--pri);
    text-decoration: underline;
}

.share-status-wrap {
    margin-top: 4px;
}

.share-status-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid transparent;
}

.share-status-badge.active {
    background: #eafaf2;
    color: #177f4d;
    border-color: #b9ebd1;
}

.share-status-badge.expired {
    background: #fff0f0;
    color: #b4232e;
    border-color: #ffd0d5;
}

.share-status-badge.none {
    background: #f4f6fb;
    color: #66708a;
    border-color: #e1e6f2;
}

.tag {
    display: inline-block;
    background: #edf1ff;
    color: #3a4e90;
    border-radius: 999px;
    padding: 2px 8px;
    margin-right: 4px;
    font-size: 12px;
}

.actions-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.empty {
    padding: 20px;
    text-align: center;
    color: var(--muted);
}

.pager {
    padding: 10px;
    text-align: center;
}

.pager-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 8px;
}

#pageNumbers button.active {
    background: var(--pri);
    color: #fff;
    border-color: var(--pri);
}

.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(16, 21, 33, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 12px;
}

.modal {
    width: min(98vw, 1600px);
    height: min(94vh, 1200px);
    display: flex;
    flex-direction: column;
    margin: 0;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 6px 10px;
    min-height: 42px;
    flex-shrink: 0;
}

.modal-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#modalMask.preview-controls-only #modalTitle {
    display: none;
}

#modalMask.preview-controls-only .modal-head {
    justify-content: flex-end;
}

.icon-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

.modal-content {
    padding: 6px 8px 8px;
    overflow: auto;
    flex: 1;
}

.preview-frame {
    width: 100%;
    height: 100%;
    min-height: 420px;
    border: 1px solid var(--line);
    border-radius: 10px;
    display: block;
}

/* ESC关闭提示 */
.esc-hint {
    color: #6a7285;
    font-size: 13px;
    margin-right: 12px;
    white-space: nowrap;
    align-self: center;
}

/* PDF 预览容器 */
.pdf-viewer-container {
    width: 100%;
    height: 100%;
    display: block;
    overflow: hidden;
    position: relative;
}

/* PDF embed 标签样式 */
.preview-frame[type="application/pdf"] {
    border: none;
    border-radius: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
}

/* PDF 预览的特殊处理 */
.preview-frame::-webkit-scrollbar {
    display: auto;
}

.preview-frame {
    -ms-overflow-style: auto;
    scrollbar-width: auto;
}


.share-box,
.meta-box,
.stats-grid {
    display: grid;
    gap: 12px;
}

.share-box {
    justify-items: center;
    text-align: center;
}

.share-box #shareLink {
    width: min(92%, 760px);
}

.share-qr {
    width: 236px;
    min-height: 236px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.share-pdf-name {
    font-size: 14px;
    font-weight: 600;
    color: #31384e;
    max-width: min(92%, 760px);
    word-break: break-all;
}

.share-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.share-expire-row {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.share-expire-row label {
    margin: 0;
    font-size: 13px;
}

#shareExpireType {
    width: 140px;
}

#shareExpireCustom {
    width: 170px;
}

.share-expire-info {
    color: var(--muted);
    font-size: 12px;
}

.stats-grid {
    grid-template-columns: repeat(4, 1fr);
}

.stat-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
}

.stat-item b {
    display: block;
    font-size: 19px;
    margin-top: 6px;
}

.chart-wrap {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
}

.data-panel {
    display: grid;
    gap: 10px;
}

.data-row {
    border: 1px solid #eef1f8;
    border-radius: 8px;
    padding: 8px;
    background: #fbfcff;
}

.data-row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 6px;
}

.data-bar {
    height: 8px;
    background: #e8edf9;
    border-radius: 999px;
    overflow: hidden;
}

.data-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #3a63f3, #5e86ff);
}

.trend-summary {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 13px;
    color: #4b5677;
    padding: 4px 0 8px;
}

.trend-list {
    display: grid;
    gap: 6px;
    max-height: 320px;
    overflow: auto;
    padding-right: 4px;
}

.trend-row {
    display: grid;
    grid-template-columns: 58px 1fr 34px;
    gap: 8px;
    align-items: center;
    font-size: 12px;
}

.trend-date {
    color: #5f6882;
}

.trend-bar {
    height: 8px;
    background: #edf1fb;
    border-radius: 999px;
    overflow: hidden;
}

.trend-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #36a3ff, #5569e9);
}

.trend-count {
    margin: 0;
    text-align: right;
    color: #31384e;
}

.stats-empty {
    padding: 10px 0;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    padding: 10px 14px;
    background: #1f2434;
    color: #fff;
    border-radius: 10px;
    font-size: 13px;
    z-index: 1001;
}

.hover-preview-panel {
    position: fixed;
    left: 360px;
    top: 140px;
    width: min(34vw, 560px);
    height: min(78vh, 760px);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 8px 26px rgba(18, 36, 80, 0.18);
    z-index: 900;
    overflow: hidden;
}

.hover-preview-head {
    height: 38px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 13px;
    color: #4d5671;
    border-bottom: 1px solid var(--line);
    background: #f8f9fd;
}

.hover-preview-frame {
    width: 100%;
    height: calc(100% - 38px);
    border: none;
}

.upload-progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16, 21, 33, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1002;
}

.upload-progress-box {
    background: #fff;
    border-radius: 14px;
    padding: 24px 32px;
    min-width: 320px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.upload-progress-title {
    font-size: 15px;
    font-weight: 600;
    color: #1f2434;
    margin-bottom: 10px;
}

.upload-progress-info {
    font-size: 24px;
    font-weight: 700;
    color: var(--pri);
    margin-bottom: 12px;
}

.upload-progress-bar {
    height: 10px;
    background: #e8edf9;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 10px;
}

.upload-progress-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--pri), #5e86ff);
    border-radius: 999px;
    transition: width 0.2s ease;
}

.upload-progress-detail {
    font-size: 12px;
    color: var(--muted);
}

.share-countdown {
    color: var(--ok);
    font-weight: 600;
}

.share-status-badge.revoked {
    background: #fff0f0;
    color: #b4232e;
    border-color: #ffd0d5;
}

input[type="datetime-local"] {
    width: auto;
    min-width: 200px;
}

#customTimeRow {
    margin-top: 8px;
}

#customTimeRow label {
    margin: 0;
}

@media (max-width: 860px) {
    .toolbar {
        grid-template-columns: 1fr 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .list-table thead {
        display: none;
    }
    .list-table,
    .list-table tbody,
    .list-table tr,
    .list-table td {
        display: block;
        width: 100%;
    }
    .list-table tr {
        border-bottom: 1px solid var(--line);
        padding: 8px 0;
    }
    .list-table td {
        border: none;
        padding: 6px 10px;
    }
    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }
    .hover-preview-panel {
        display: none !important;
    }
    .modal-mask {
        padding: 0;
        z-index: 9999;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: stretch;
        justify-content: stretch;
        transform: none;
    }
    .modal {
        width: 100%;
        height: 100%;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        position: relative;
        flex: 1;
        transform: none;
        overflow: hidden;
    }
    .modal-head {
        padding: 10px 16px;
        min-height: 60px;
        flex-shrink: 0;
        background: var(--card);
        border-bottom: 1px solid var(--line);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .modal-head-actions {
        gap: 12px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
    }
    .icon-btn {
        width: 48px;
        height: 48px;
        font-size: 24px;
        padding: 0;
        border: none;
        background: transparent;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition: background-color 0.2s ease;
    }
    .icon-btn:hover,
    .icon-btn:active {
        background: rgba(58, 99, 243, 0.1);
    }
    #modalClose {
        font-size: 16px;
        padding: 12px 24px;
        border: 1px solid var(--line);
        background: var(--card);
        border-radius: 8px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition: all 0.2s ease;
    }
    #modalClose:hover,
    #modalClose:active {
        background: #f8f9ff;
        transform: translateY(-1px);
    }
    .modal-content {
        padding: 0;
        overflow: auto;
        flex: 1;
        display: flex;
        flex-direction: column;
        background: #f5f5f5;
        -webkit-overflow-scrolling: touch;
    }
    .preview-frame {
        width: 100%;
        height: 100%;
        min-height: 0;
        flex: 1;
        border: none;
        border-radius: 0;
        display: block;
        background: white;
    }
    /* 确保模态框在横屏模式下也能正常显示 */
    @media (orientation: landscape) {
        .modal-head {
            min-height: 50px;
            padding: 8px 12px;
        }
        .icon-btn {
            width: 40px;
            height: 40px;
            font-size: 20px;
        }
        #modalClose {
            font-size: 14px;
            padding: 10px 20px;
        }
    }
}
