/**
 * SaveTool — 布局舒适化（主站）
 * 更均衡的双栏、完整展示、移动端安全区与滚动
 */

/* 刷新时本地会话有效：首屏直接进主界面，避免门禁闪烁 */
html.st-session-restored #kaimaLoginModal {
    display: none !important;
}
/* 工具台默认收起；仅打开工作区时露出 */
html.st-session-restored:not(.st-app-workspace-open) .st-app-workspace {
    transform: translateY(108%);
    opacity: 0;
    pointer-events: none;
}

html.st-session-restored.st-app-workspace-open .st-app-workspace {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* 主动退出：强制回到介绍/门禁页，避免与 st-session-restored 或抽屉层叠冲突 */
html.st-user-logged-out #kaimaLoginModal {
    display: flex !important;
    visibility: visible !important;
}
html.st-user-logged-out .container.app-shell {
    display: none !important;
}

html.st-user-logged-out #kaimaLoginModal.st-gate {
    align-items: stretch;
}

.archive-game-hint {
    margin: 8px 0 0;
    font-size: 0.78rem;
    color: var(--text-dim);
    line-height: 1.4;
}

/* ===== 主壳层 ===== */
.main-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
}

.app-shell .content {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    align-items: stretch;
    min-height: 0;
}

.tab-content {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.tab-content.active {
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 1.25rem;
}

.left-panel,
.right-panel {
    min-height: 0;
    min-width: 0;
}

.section {
    width: 100%;
    box-sizing: border-box;
}

/* ===== 存档获取：左右更均衡 ===== */
#archive-tab.tab-content.active {
    gap: 1.25rem;
}

#archive-tab .left-panel {
    flex: 0 1 42%;
    max-width: 480px;
    min-width: min(100%, 300px);
}

#archive-tab .right-panel {
    flex: 1 1 58%;
    min-width: 0;
}

/* ===== 排行榜侧栏 ===== */
.ranking-side-panel {
    flex: 0 1 38%;
    max-width: 440px;
    min-width: min(100%, 280px);
}

.ranking-table-wrap,
.save-list-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.55);
    max-width: 100%;
}

html[data-theme="dark"] .ranking-table-wrap,
html[data-theme="dark"] .save-list-container {
    background: rgba(24, 28, 38, 0.5);
}

.ranking-data-table {
    min-width: 640px;
}

.save-table {
    min-width: 420px;
}

/* ===== 4399 登录条幅 ===== */
.login4399-banner {
    margin-top: 0;
    margin-bottom: 0;
    flex-shrink: 0;
    border-top: none;
}

/* ===== 编辑器 Tab ===== */
#editor-tab.tab-content.active {
    display: flex !important;
    flex-direction: column;
    gap: 0;
    flex-wrap: nowrap;
}

.editor-tab-section {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
}

/* 编辑器卡片样式见 editor-game-cards.css */

/* ===== 工坊 / 加解密 ===== */
#workshop-tab.tab-content.active {
    flex-direction: column;
    width: 100%;
}

#crypto-tab.tab-content.active {
    width: 100%;
}

/* ===== 批量日志 / 操作日志 ===== */
.batch-log {
    max-height: min(420px, 45vh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.oplog-list,
.ranking-history-list {
    max-height: min(280px, 35vh);
}

/* ===== 空状态 ===== */
.empty-state {
    padding: 1.75rem 1rem;
}

/* ===== 平板/窄屏：双栏改单栏 ===== */
@media (max-width: 1100px) {
    .tab-content.active {
        flex-wrap: wrap;
        gap: 12px;
    }

    #archive-tab .left-panel,
    #archive-tab .right-panel,
    .ranking-side-panel {
        flex: 1 1 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
}

/* ===== 注册代理工具栏（单行横向对齐） ===== */
.reg-proxy-toolbar {
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 92%, var(--primary) 8%);
}

.reg-proxy-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.reg-proxy-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.reg-proxy-field-name {
    flex: 0 0 auto;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-dim);
    white-space: nowrap;
    line-height: 1;
}

.reg-proxy-toolbar .reg-proxy-control {
    height: 34px;
    min-height: 34px;
    max-height: 34px;
    box-sizing: border-box;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    font-size: 0.78rem;
    line-height: 1;
    border-radius: calc(var(--radius) - 2px);
}

.reg-proxy-toolbar .reg-proxy-qty-input {
    width: 64px !important;
    padding-left: 8px;
    padding-right: 8px;
}

.reg-proxy-toolbar .reg-proxy-refresh-select {
    width: auto !important;
    min-width: 124px;
    max-width: none;
    padding-left: 10px;
    padding-right: 28px;
    background-position: right 8px center;
    background-size: 12px;
}

.reg-proxy-toolbar .reg-proxy-refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-left: 14px;
    padding-right: 14px;
    white-space: nowrap;
}

.reg-proxy-status {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed color-mix(in srgb, var(--border) 85%, transparent);
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--text-dim);
    min-height: 1.2em;
}

@media (max-width: 520px) {
    .reg-proxy-row {
        gap: 10px;
    }

    .reg-proxy-toolbar .reg-proxy-refresh-btn {
        width: 100%;
        justify-content: center;
    }
}

/* 窄屏细节见 mobile-layout.css */

/* ===== 弹窗：全端统一小弹窗居中 ===== */
.modal-overlay {
    align-items: center !important;
    justify-content: center !important;
    padding: 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    width: min(440px, calc(100vw - 32px)) !important;
    max-width: min(440px, calc(100vw - 32px)) !important;
    max-height: min(85dvh, 90vh) !important;
    margin: auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.modal-header,
.modal-footer {
    flex-shrink: 0 !important;
}

.modal-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-footer {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
}

.modal-footer .btn {
    width: auto !important;
}

#exportModal .modal-content,
#workshopEditModal .modal-content,
#workshopUploadModal .modal-content.workshop-upload-modal,
.workshop-detail-modal {
    width: min(520px, calc(100vw - 32px)) !important;
    max-width: min(520px, calc(100vw - 32px)) !important;
}

#rankingDetailModal .modal-content.ranking-detail-modal {
    width: min(680px, calc(100vw - 32px)) !important;
    max-width: min(680px, calc(100vw - 32px)) !important;
}

#saveEditorModal > div {
    width: min(520px, calc(100vw - 32px)) !important;
    max-width: min(520px, calc(100vw - 32px)) !important;
}

#multiFileModal > div {
    width: min(440px, calc(100vw - 32px)) !important;
    max-width: min(440px, calc(100vw - 32px)) !important;
}

.workshop-admin-dl-btn {
    min-width: 32px;
    padding: 0.28rem 0.45rem !important;
    opacity: 0.72;
}
.workshop-admin-dl-btn:hover {
    opacity: 1;
}
