/* 基础样式 */
:root {
    --primary-gradient: linear-gradient(135deg, #6e48aa, #9f50ac);
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --border-radius: 12px;
    --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-strong: 0 8px 24px rgba(0, 0, 0, 0.2);
    --transition-default: all 0.3s ease;
}

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

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* 容器布局 */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* 头部样式 */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 6px 12px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    cursor: help;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #888;
}

.api-status.connected .status-indicator {
    background-color: #4CAF50;
}

.api-status.error .status-indicator {
    background-color: #F44336;
}

.api-status.loading .status-indicator {
    background-color: #FFC107;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

h1 {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 28px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

main {
    display: flex;
    flex: 1;
    gap: 24px;
    height: calc(100vh - 100px);
}

/* 输入面板 */
.input-panel {
    width: 35%;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow-soft);
}

textarea {
    flex: 1;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    padding: 16px;
    font-size: 16px;
    resize: none;
    margin-bottom: 16px;
    transition: var(--transition-default);
}

textarea:focus {
    outline: none;
    border-color: transparent;
    box-shadow: 0 0 0 2px rgba(158, 80, 172, 0.5);
    background-color: rgba(255, 255, 255, 0.07);
}

textarea:focus-within {
    border-image: var(--primary-gradient) 1;
}

.controls {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.select-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.select-wrapper label {
    font-size: 14px;
    color: var(--text-secondary);
}

select {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 14px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    padding-right: 32px;
}

select:focus {
    outline: none;
    border-color: rgba(158, 80, 172, 0.5);
}

.primary-btn {
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
    transition: var(--transition-default);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-left: auto;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(158, 80, 172, 0.3);
}

.primary-btn:active {
    transform: translateY(1px);
}

.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;
    display: none;
}

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

.loading .spinner {
    display: block;
}

.loading span {
    display: none;
}

/* 高级选项 */
.advanced-options {
    margin-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 12px;
}

.advanced-options summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    user-select: none;
    outline: none;
}

.advanced-options summary:hover {
    color: var(--text-primary);
}

.advanced-controls {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.checkbox-wrapper input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    position: relative;
}

.checkbox-wrapper input[type="checkbox"]:checked::after {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-primary);
    font-size: 14px;
}

.checkbox-wrapper label {
    cursor: pointer;
    font-size: 14px;
}

.tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    color: var(--text-secondary);
    cursor: help;
}

.tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 12px;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

.range-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.range-wrapper label {
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.range-wrapper input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

.range-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
}

.range-wrapper input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
}

/* 图片展示区 */
.gallery {
    flex: 1;
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    align-content: flex-start;
    position: relative;
}

.placeholder-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-secondary);
    text-align: center;
    width: 100%;
}

.image-card {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    aspect-ratio: 1;
    cursor: pointer;
    transition: var(--transition-default);
}

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

.image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition-default);
}

.image-card .image-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    color: white;
    font-size: 12px;
    opacity: 0;
    transition: var(--transition-default);
    display: flex;
    justify-content: space-between;
}

.image-card:hover .image-info {
    opacity: 1;
}

/* 骨架屏加载效果 */
.image-card.loading {
    background: linear-gradient(110deg, #1e1e1e 8%, #2a2a2a 18%, #1e1e1e 33%);
    background-size: 200% 100%;
    animation: shine 1.5s linear infinite;
}

@keyframes shine {
    to {
        background-position-x: -200%;
    }
}

/* 错误样式 */
.image-card.error {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.error-message {
    color: #F44336;
    text-align: center;
    padding: 20px;
}

/* 历史记录面板 */
.history-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    height: 100vh;
    background-color: var(--bg-card);
    box-shadow: var(--shadow-strong);
    transition: var(--transition-default);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.history-panel.active {
    right: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-header h2 {
    font-family: 'Inter', sans-serif;
    font-size: 20px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-radius: var(--border-radius);
    background-color: rgba(255, 255, 255, 0.05);
    transition: var(--transition-default);
    cursor: pointer;
}

.history-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.history-item img {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
}

.history-item-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.history-item-prompt {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.history-item-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.empty-history {
    color: var(--text-secondary);
    text-align: center;
    margin-top: 40px;
}

/* 图标按钮 */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition-default);
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-default);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-content img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-strong);
}

.modal-content #close-modal {
    position: absolute;
    top: -50px;
    right: -10px;
}

.modal-actions {
    display: flex;
    gap: 16px;
    margin-top: 20px;
}

.action-btn {
    background-color: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition-default);
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* 图片详情 */
.image-details {
    margin-top: 16px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prompt-display {
    font-size: 14px;
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: var(--border-radius);
    max-height: 100px;
    overflow-y: auto;
}

.settings-display {
    font-size: 12px;
    color: var(--text-secondary);
}

/* 淡入动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

/* 响应式设计 */
@media (max-width: 768px) {
    main {
        flex-direction: column;
        height: auto;
    }
   
    .input-panel {
        width: 100%;
        height: 300px;
    }
   
    .gallery {
        margin-top: 20px;
        height: 500px;
    }
   
    .history-panel {
        width: 100%;
        right: -100%;
    }
   
    .controls {
        flex-wrap: wrap;
    }
   
    .select-wrapper {
        width: calc(50% - 6px);
    }
   
    .primary-btn {
        width: 100%;
        margin-top: 12px;
        margin-left: 0;
    }
}

/* 图片保存说明弹窗 */
.tooltip-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.tooltip-overlay.active {
    display: flex;
}

.tooltip-content {
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 24px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-strong);
}

.tooltip-content h3 {
    font-family: 'Inter', sans-serif;
    margin-bottom: 16px;
    color: var(--text-primary);
    font-size: 20px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.tooltip-content p {
    margin-bottom: 12px;
    color: var(--text-primary);
    line-height: 1.5;
}

.tooltip-content .action-btn {
    margin-top: 16px;
    width: 100%;
    justify-content: center;
}

/* 添加删除按钮样式 */
.delete-btn {
    background-color: #f44336;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.3s;
}

.delete-btn:hover {
    background-color: #d32f2f;
}

.delete-btn svg {
    width: 16px;
    height: 16px;
}

.hard-delete {
    background-color: #d32f2f;
}

.hard-delete:hover {
    background-color: #b71c1c;
}