* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4285f4;
    --primary-hover: #3367d6;
    --danger-color: #ea4335;
    --danger-hover: #c5221f;
    --success-color: #34a853;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #202124;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-hover:
        0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
    --radius: 12px;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 30px 0;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #4285f4, #ea4335, #fbbc05, #34a853);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

/* 配置区域 */
.config-section {
    padding: 0;
    overflow: hidden;
}

.config-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.config-toggle:hover {
    background: var(--bg-color);
}

.toggle-icon {
    transition: transform 0.3s;
}

.toggle-icon.open {
    transform: rotate(180deg);
}

.config-content {
    display: none;
    padding: 0 24px 24px;
    border-top: 1px solid var(--border-color);
}

.config-content.show {
    display: block;
    padding-top: 20px;
}

/* 表单元素 */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.2);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* 参考图片上传区域 */
.reference-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 16px;
    transition:
        border-color 0.2s,
        background 0.2s;
}

.reference-upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(66, 133, 244, 0.05);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: pointer;
    color: var(--text-secondary);
}

.upload-placeholder.hidden {
    display: none;
}

.upload-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.reference-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.reference-preview:empty {
    display: none;
}

.reference-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
}

.reference-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reference-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.reference-item:hover .remove-btn {
    opacity: 1;
}

.add-more-btn {
    width: 80px;
    height: 80px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--text-secondary);
    transition:
        border-color 0.2s,
        color 0.2s;
}

.add-more-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.875rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 按钮内的 spinner */
.btn .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

/* 结果区域 */
.result-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.result-image {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.result-image:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 历史记录 - 网格样式 */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.history-header h2 {
    font-size: 1.25rem;
}

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

.history-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.history-thumb:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-hover);
}

.history-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-thumb .thumb-count {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
}

.history-thumb .thumb-date {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
    color: white;
    font-size: 10px;
    padding: 4px 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-thumb:hover .thumb-date {
    opacity: 1;
}

/* 历史详情弹窗 */
.history-detail {
    max-height: 70vh;
    overflow-y: auto;
}

.history-detail-prompt {
    background: var(--bg-color);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.history-detail-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.history-detail-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.history-detail-images img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.history-detail-images img:hover {
    transform: scale(1.02);
}

.history-detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.empty-tip {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
    grid-column: 1 / -1;
}

/* 弹窗 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}

.modal-large {
    width: 90%;
    max-width: 700px;
    text-align: left;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
    z-index: 10;
}

.modal-close:hover {
    color: var(--text-color);
}

#modalImage {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
}

.modal-actions {
    margin-top: 16px;
}

.modal-actions .btn {
    width: auto;
}

/* 加载动画遮罩 */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.loading-overlay.show {
    display: flex;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner-large {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.loading-text {
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.loading-hint {
    font-size: 0.9rem;
    opacity: 0.7;
}

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

/* 错误提示 */
.error-message {
    background: #fce8e6;
    color: var(--danger-color);
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 16px;
}

/* 响应式 */
@media (max-width: 600px) {
    .container {
        padding: 12px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    section {
        padding: 16px;
    }

    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    }

    .reference-item,
    .add-more-btn {
        width: 60px;
        height: 60px;
    }
}

footer {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
