/* --- 重置 & 全局 --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    background: #f2f6fc;
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    padding: 24px 16px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    color: #1e293b;
}
.container {
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
}

/* --- 头部 --- */
.app-header {
    text-align: center;
    padding: 10px 0 18px;
    opacity: 0;
    transform: translateY(-20px);
}
.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: #0b2b5c;
    letter-spacing: -0.5px;
}
.app-header .sub {
    font-size: 14px;
    color: #64748b;
    margin-top: 4px;
}

/* --- 卡片 --- */
.card {
    background: #ffffff;
    border-radius: 24px;
    padding: 24px 28px;
    margin-bottom: 24px;
    box-shadow: 0 8px 30px rgba(0, 20, 50, 0.06);
    border: 1px solid #e9f0f8;
    opacity: 0;
    transform: translateY(30px);
    transition: box-shadow 0.2s ease;
}
.card:hover {
    box-shadow: 0 12px 40px rgba(0, 20, 50, 0.08);
}

/* --- 选项卡 --- */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: #f0f4fc;
    border-radius: 16px;
    padding: 4px;
}
.tab-btn {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: transparent;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    color: #1e3a8a;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.tab-btn.active {
    background: #ffffff;
    color: #0b2b5c;
    box-shadow: 0 2px 8px rgba(0, 20, 50, 0.06);
}
.tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.4);
}

.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* --- 表单 (生图) --- */
.row {
    margin-bottom: 18px;
}
.row:last-child {
    margin-bottom: 0;
}
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #1e3a8a;
    margin-bottom: 4px;
}
input,
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    background: #f7faff;
    border: 1.5px solid #dde7f3;
    border-radius: 14px;
    font-size: 15px;
    color: #0b2b5c;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
input:focus,
select:focus,
textarea:focus {
    border-color: #4b8bf5;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(75, 139, 245, 0.08);
}
textarea {
    min-height: 72px;
    resize: vertical;
}
.row-duo {
    display: flex;
    gap: 14px;
}
.row-duo>* {
    flex: 1;
}

.hint {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 4px;
}

/* --- 按钮 --- */
.btn {
    background: #1a4c8c;
    border: none;
    color: #fff;
    font-weight: 600;
    padding: 16px;
    border-radius: 18px;
    font-size: 16px;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(26, 76, 140, 0.20);
}
.btn:active {
    transform: scale(0.98);
}
.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
    box-shadow: none;
}
.btn:hover:not(:disabled) {
    background: #0e3d77;
    box-shadow: 0 6px 18px rgba(26, 76, 140, 0.25);
}
.btn-secondary {
    background: #eef4fb;
    color: #1a4c8c;
    box-shadow: none;
    border: 1px solid #d4e2f2;
    margin-top: 10px;
}
.btn-secondary:hover:not(:disabled) {
    background: #e2edfa;
    border-color: #b0cde8;
}

.btn-download {
    display: inline-block;
    margin-top: 14px;
    padding: 12px 28px;
    background: #1a4c8c;
    color: #fff;
    border-radius: 40px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(26, 76, 140, 0.15);
}
.btn-download:active {
    transform: scale(0.95);
}
.btn-download:hover {
    background: #0e3d77;
}

/* --- 生图日志 & 预览 --- */
.log-box {
    background: #f7faff;
    border-radius: 16px;
    padding: 14px 18px;
    min-height: 100px;
    max-height: 180px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.7;
    color: #1e293b;
    white-space: pre-wrap;
    word-break: break-all;
    border: 1px solid #e3ecf6;
}
.log-box .info {
    color: #2563eb;
}
.log-box .success {
    color: #16a34a;
}
.log-box .error {
    color: #dc2626;
}
.log-box .warn {
    color: #d97706;
}

.image-preview {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.img-wrapper {
    background: #fafcff;
    border: 1px solid #e3ecf6;
    border-radius: 18px;
    padding: 12px;
    max-width: 100%;
    text-align: center;
}
.img-wrapper img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    display: block;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: #475569;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 0 2px;
}
.status-bar .active {
    color: #2563eb;
    font-weight: 600;
}
.status-bar .done {
    color: #16a34a;
    font-weight: 600;
}
.status-bar .fail {
    color: #dc2626;
    font-weight: 600;
}

/* --- 聊天专用 --- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 420px;
    /* 固定高度，滚动 */
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid #e3ecf6;
    scroll-behavior: smooth;
}
.chat-message {
    display: flex;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
}
.chat-message .bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}
.chat-message.user .bubble {
    background: #1a4c8c;
    color: #fff;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}
.chat-message.assistant .bubble {
    background: #eef4fb;
    color: #0b2b5c;
    border-bottom-left-radius: 4px;
    margin-right: auto;
}
.chat-message .time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 4px;
    text-align: right;
    opacity: 0.7;
}
.chat-message.user .time {
    color: #cbd5e1;
}

/* 用户消息中的纯文本（不渲染 Markdown，但也可以渲染，但一般用户输入不包含复杂格式） */
.chat-message.user .bubble {
    white-space: pre-wrap;
}

/* --- Markdown 渲染样式 --- */
.bubble pre {
    background: #1e293b;
    color: #f1f5f9;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}
.bubble code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Courier New', monospace;
}
.bubble pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}
.bubble ul, .bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}
.bubble li {
    margin-bottom: 4px;
}
.bubble blockquote {
    border-left: 4px solid #4b8bf5;
    padding-left: 12px;
    margin: 8px 0;
    color: #475569;
    background: #f8fafc;
    border-radius: 0 6px 6px 0;
}
.bubble a {
    color: #2563eb;
    text-decoration: underline;
}
.bubble h1, .bubble h2, .bubble h3 {
    margin: 12px 0 6px;
}
.bubble p {
    margin: 6px 0;
}

/* 用户消息不渲染 Markdown（只显示纯文本） */
.chat-message.user .bubble {
    white-space: pre-wrap;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.chat-input-area textarea {
    flex: 1;
    min-height: 44px;
    max-height: 100px;
    resize: none;
    padding: 10px 14px;
}
.chat-input-area .btn {
    width: auto;
    padding: 12px 20px;
    flex-shrink: 0;
}
.chat-status {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 8px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- 响应式 --- */
@media (max-width: 480px) {
    .card {
        padding: 18px 16px;
    }
    .row-duo {
        flex-direction: column;
        gap: 0;
    }
    .app-header h1 {
        font-size: 24px;
    }
    .chat-container {
        height: 360px;
    }
    .chat-input-area .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
}