:root {
    --primary: #1677ff;
    --primary-weak: #e6f4ff;
    --success: #52c41a;
    --success-weak: #f6ffed;
    --warn: #faad14;
    --warn-weak: #fffbe6;
    --error: #ff4d4f;
    --error-weak: #fff2f0;
    --title: #17233d;
    --sub: #808695;
    --content: #515a6e;
    --border: #dcdee2;
    --bg: #f5f5f5;
    --white: #ffffff;
    --radius: 12px;
    --radius-sm: 8px;
    --font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--title);
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* 顶部栏 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--white);
    border-bottom: 0.5px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #1677ff, #4096ff);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.brand-name {
    font-size: 15px;
    font-weight: 600;
}

.brand-sub {
    font-size: 11px;
    color: var(--sub);
}

.tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px;
    border-radius: 10px;
    background: var(--bg);
}

.tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--content);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.tab:hover {
    color: var(--primary);
}

.tab.is-active {
    background: var(--white);
    color: var(--primary);
    box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
    font-weight: 500;
}

.tab-count {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--primary-weak);
    color: var(--primary);
    font-size: 11px;
    line-height: 18px;
    text-align: center;
}

.topbar-inner > #comfy-pill {
    margin-left: auto;
}

/* 页面与卡片 */
.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.panel {
    display: none;
}

.panel.is-active {
    display: block;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--title);
}

.banner {
    margin-bottom: 12px;
    padding: 10px 14px;
    border: 1px solid #ffe58f;
    border-radius: var(--radius-sm);
    background: var(--warn-weak);
    color: #ad6800;
    font-size: 13px;
}

/* 状态标签 */
.pill {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 12px;
    line-height: 22px;
    white-space: nowrap;
}

.pill--muted {
    border-color: var(--border);
    background: #fafafa;
    color: var(--sub);
}

.pill--primary {
    border-color: #91caff;
    background: var(--primary-weak);
    color: var(--primary);
}

.pill--success {
    border-color: #b7eb8f;
    background: var(--success-weak);
    color: #389e0d;
}

.pill--warn {
    border-color: #ffe58f;
    background: var(--warn-weak);
    color: #d48806;
}

.pill--error {
    border-color: #ffa39e;
    background: var(--error-weak);
    color: #cf1322;
}

/* 表单 */
.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field-label {
    font-size: 12px;
    color: var(--sub);
}

textarea,
select,
.upload input[type="file"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
    resize: vertical;
    min-height: 96px;
    line-height: 1.6;
}

textarea:focus,
select:focus,
.upload input[type="file"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgb(22 119 255 / 12%);
}

select {
    cursor: pointer;
}

.form-grid {
    display: grid;
    gap: 12px;
}

.form-grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.form-grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field--switch {
    justify-content: flex-end;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--content);
}

.switch-row input {
    accent-color: var(--primary);
}

.upload input[type="file"] {
    padding: 7px 10px;
    color: var(--content);
}

.upload input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 4px 10px;
    border: none;
    border-radius: 6px;
    background: var(--primary-weak);
    color: var(--primary);
    cursor: pointer;
}

.file-summary {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: #fafafa;
    color: var(--content);
    font-size: 12px;
}

.file-summary-lines {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.hint {
    color: var(--sub);
    font-size: 12px;
}

/* 按钮 */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--content);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.button--primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button--primary:hover {
    border-color: #4096ff;
    background: #4096ff;
    color: #fff;
}

.button--text {
    height: auto;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--primary);
}

.button--text:hover {
    color: #4096ff;
}

.button--danger {
    color: var(--error);
}

.button--danger:hover {
    color: #ff7875;
}

.button--small {
    height: 28px;
    padding: 0 10px;
    font-size: 12px;
    text-decoration: none;
}

/* 表格 */
.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.table th,
.table td {
    padding: 12px 10px;
    border-bottom: 0.5px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.table th {
    background: #fafafa;
    color: var(--sub);
    font-size: 12px;
    font-weight: 500;
}

.table tbody tr:hover {
    background: #fafcff;
}

.cell-prompt {
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cell-meta {
    color: var(--sub);
    font-size: 12px;
}

.cell-actions {
    display: flex;
    gap: 14px;
}

.progress {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 150px;
}

.progress-rail {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #f0f0f0;
}

.progress-bar {
    height: 100%;
    border-radius: 999px;
    background: var(--primary);
    transition: width 0.3s ease;
}

.progress-bar.is-running {
    width: 32%;
    animation: progress-slide 1.2s infinite linear;
}

.progress-bar.is-error {
    background: var(--error);
}

.progress-text {
    color: var(--sub);
    font-size: 12px;
}

@keyframes progress-slide {
    from {
        transform: translateX(-100%);
    }

    to {
        transform: translateX(320%);
    }
}

.empty {
    padding: 36px 0;
    color: var(--sub);
    text-align: center;
}

/* 详情弹窗 */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal[hidden] {
    display: none;
}

.modal-mask {
    position: absolute;
    inset: 0;
    background: rgb(0 0 0 / 45%);
}

.modal-card {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(860px, 100%);
    max-height: 86vh;
    border-radius: var(--radius);
    background: var(--white);
    box-shadow: 0 12px 40px rgb(0 0 0 / 18%);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 0.5px solid var(--border);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    padding: 16px 20px 20px;
}

.icon-button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--sub);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.icon-button:hover {
    background: var(--bg);
    color: var(--title);
}

.detail-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.detail-row {
    display: flex;
    gap: 12px;
}

.detail-row > span:first-child {
    flex-shrink: 0;
    width: 72px;
    color: var(--sub);
}

.detail-prompt {
    padding: 12px;
    border-radius: var(--radius-sm);
    background: #fafafa;
    color: var(--content);
    line-height: 1.7;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.detail-error {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--error-weak);
    color: #cf1322;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.media-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fafafa;
}

.media {
    width: 100%;
    max-height: 320px;
    border-radius: 8px;
    background: #000;
    object-fit: contain;
}

.media.is-unavailable {
    display: none;
}

.media-hint {
    padding: 28px 12px;
    border-radius: 8px;
    background: #fff;
    color: var(--sub);
    font-size: 12px;
    text-align: center;
}

.media-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.media-name {
    min-width: 0;
    overflow: hidden;
    color: var(--sub);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 轻提示 */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    z-index: 60;
    max-width: min(520px, calc(100vw - 32px));
    padding: 10px 16px;
    border-radius: 10px;
    background: rgb(23 35 61 / 92%);
    color: #fff;
    font-size: 13px;
    transform: translateX(-50%);
    box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
}

.toast[hidden] {
    display: none;
}

.toast--success {
    background: rgb(56 158 13 / 94%);
}

.toast--error {
    background: rgb(207 19 34 / 94%);
}

@media (max-width: 860px) {
    .topbar-inner {
        flex-wrap: wrap;
        gap: 12px;
    }

    .topbar-inner > #comfy-pill {
        margin-left: 0;
    }

    .form-grid--4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid--2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    .page {
        padding: 12px;
    }

    .card {
        padding: 14px;
    }

    .form-grid--4 {
        grid-template-columns: 1fr;
    }

    .tabs {
        width: 100%;
    }

    .tab {
        flex: 1;
        justify-content: center;
    }
}
