/* ===========================================================
   AI 绘画工作台 · image-gen.css
   =========================================================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: #f4f5f7;
    color: #1a1a2e;
}

/* ─── 密钥弹框 ─── */
.ig-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.ig-modal-overlay.show { display: flex; }

.ig-modal {
    background: #fff;
    border-radius: 18px;
    padding: 36px 32px 28px;
    width: 380px;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    animation: ig-modal-in .3s ease;
}

@keyframes ig-modal-in {
    from { transform: scale(.92) translateY(10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.ig-modal-icon {
    width: 56px; height: 56px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: rgba(124, 58, 237, .1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #7c3aed;
}

.ig-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 6px;
}

.ig-modal-desc {
    font-size: 13px;
    color: #9ca3af;
    margin-bottom: 22px;
}

.ig-modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: #fafafa;
    color: #1f2937;
    transition: border-color .2s, box-shadow .2s;
    text-align: center;
}

.ig-modal-input:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, .12);
    background: #fff;
}

.ig-modal-error {
    color: #ef4444;
    font-size: 12px;
    margin-top: 8px;
}

.ig-modal-btn {
    flex: 1;
    margin-top: 18px;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}

.ig-modal-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(124, 58, 237, .35);
}

.ig-modal-actions {
    display: flex;
    gap: 10px;
}

.ig-modal-cancel {
    flex: 0 0 auto;
    margin-top: 18px;
    padding: 12px 24px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    background: #fff;
    cursor: pointer;
    transition: all .15s;
}

.ig-modal-cancel:hover {
    border-color: #d1d5db;
    color: #374151;
    background: #f9fafb;
}

.ig-key-change {
    margin-left: auto;
    padding: 4px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafafa;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    transition: all .15s;
}

.ig-key-change:hover {
    border-color: #7c3aed;
    color: #7c3aed;
    background: rgba(124, 58, 237, .05);
}

/* ─── 整体布局 ─── */
.ig-page {
    display: flex;
    min-height: 100vh;
}

/* ─── 左侧面板 ─── */
.ig-panel {
    width: 400px;
    min-width: 360px;
    max-width: 440px;
    background: #fff;
    border-right: 1px solid #e8eaed;
    overflow-y: auto;
    flex-shrink: 0;
}

.ig-panel-inner {
    padding: 24px 20px 32px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.ig-panel-title {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ig-panel-title i {
    color: #7c3aed;
    font-size: 16px;
}

/* ─── 剩余次数 ─── */
.ig-quota-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    background: rgba(124, 58, 237, .06);
    border: 1px solid rgba(124, 58, 237, .15);
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 20px;
}

.ig-quota-bar i { color: #7c3aed; font-size: 12px; }
.ig-quota-bar b { color: #7c3aed; font-size: 16px; font-weight: 700; }

/* ─── 字段 ─── */
.ig-field {
    margin-bottom: 20px;
}

.ig-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.ig-label em {
    color: #ef4444;
    font-style: normal;
    margin-left: 2px;
}

.ig-label small {
    font-weight: 400;
    color: #9ca3af;
    font-size: 11px;
    margin-left: 4px;
}

.ig-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ─── 文本域 ─── */
.ig-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    background: #fafafa;
    color: #1f2937;
    line-height: 1.6;
    transition: border-color .2s, box-shadow .2s;
    min-height: 120px;
}

.ig-textarea:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, .12);
    background: #fff;
}

.ig-textarea::placeholder { color: #b0bac8; font-size: 12px; }

/* ─── 输入框 ─── */
.ig-input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    background: #fafafa;
    color: #1f2937;
    transition: border-color .2s, box-shadow .2s;
}
.ig-input:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, .12);
    background: #fff;
}
.ig-input::placeholder { color: #b0bac8; font-size: 12px; }

/* ─── 下拉框 ─── */
.ig-select {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 9px;
    font-size: 13px;
    font-family: inherit;
    background: #fafafa;
    color: #1f2937;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 32px;
    transition: border-color .2s;
}

.ig-select:focus { outline: none; border-color: #7c3aed; }

/* ─── 尺寸选择 ─── */
.ig-sizes {
    display: flex;
    gap: 8px;
}

.ig-size {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 4px 8px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    background: #fafafa;
    transition: all .2s;
}

.ig-size:hover {
    border-color: #7c3aed;
    background: rgba(124, 58, 237, .04);
}

.ig-size.active {
    border-color: #7c3aed;
    background: rgba(124, 58, 237, .08);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, .1);
}

.ig-size-icon {
    background: transparent;
    border: 1.5px solid #9ca3af;
    border-radius: 3px;
    transition: all .2s;
}

.ig-size.active .ig-size-icon {
    border-color: #7c3aed;
    background: rgba(124, 58, 237, .12);
}

.ig-size span {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
}

.ig-size.active span { color: #7c3aed; }

/* ─── 上传区 ─── */
.ig-upload {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    position: relative;
    background: #fafafa;
    transition: all .25s;
}

.ig-upload:hover, .ig-upload.hover {
    border-color: #7c3aed;
    background: rgba(124, 58, 237, .04);
}

.ig-upload input[type="file"] {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.ig-upload-icon {
    font-size: 26px;
    color: #c4cad4;
    margin-bottom: 6px;
    transition: color .2s;
}

.ig-upload:hover .ig-upload-icon { color: #7c3aed; }

.ig-upload p {
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 2px;
}

.ig-upload span {
    font-size: 11px;
    color: #9ca3af;
}

/* ─── 参考图列表 ─── */
.ig-ref-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.ig-ref-item {
    width: 72px;
    height: 72px;
    border-radius: 9px;
    overflow: hidden;
    position: relative;
    border: 1.5px solid #e5e7eb;
    background: #f3f4f6;
    flex-shrink: 0;
}

.ig-ref-item.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ig-ref-spin {
    width: 20px; height: 20px;
    border: 2.5px solid #7c3aed;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

.ig-ref-item img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}

.ig-ref-del {
    position: absolute;
    top: 3px; right: 3px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: rgba(239, 68, 68, .9);
    color: #fff;
    font-size: 9px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .15s;
}

.ig-ref-item:hover .ig-ref-del { opacity: 1; }

.ig-ref-label {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 2px 4px;
    font-size: 9px;
    font-weight: 600;
    color: #fff;
    text-align: center;
    background: rgba(124, 58, 237, .8);
    line-height: 1.3;
}

/* ─── 生成按钮 ─── */
.ig-gen-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, opacity .2s;
    letter-spacing: .3px;
    margin-top: 4px;
}

.ig-gen-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, .35);
}

.ig-gen-btn:active:not(:disabled) { transform: translateY(0); }

.ig-gen-btn:disabled { opacity: .65; cursor: not-allowed; }

/* ─── 右侧结果区 ─── */
.ig-result {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ─── 状态栏 ─── */
.ig-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

.ig-status.loading { background: rgba(124, 58, 237, .06); color: #7c3aed; border-color: rgba(124, 58, 237, .2); }
.ig-status.success { background: rgba(16, 185, 129, .06); color: #059669; border-color: rgba(16, 185, 129, .2); }
.ig-status.error   { background: rgba(239, 68, 68, .06);  color: #dc2626; border-color: rgba(239, 68, 68, .2); }

.ig-status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #d1d5db;
}

.ig-status-dot.loading {
    background: #7c3aed;
    animation: pulse 1.2s ease-in-out infinite;
}

.ig-status-dot.success { background: #10b981; }
.ig-status-dot.error   { background: #ef4444; }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(1.4); }
}

/* ─── 空态 ─── */
.ig-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #9ca3af;
    text-align: center;
    padding: 40px 20px;
}

.ig-empty-canvas {
    width: 120px; height: 120px;
    border-radius: 24px;
    background: #f3f4f6;
    border: 2px dashed #d1d5db;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: #d1d5db;
    margin-bottom: 4px;
}

.ig-empty p { font-size: 15px; font-weight: 600; color: #6b7280; }
.ig-empty small { font-size: 12px; }

/* ─── 图片画廊 ─── */
.ig-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.ig-img-wrap {
    border-radius: 14px;
    overflow: hidden;
    position: relative;
    background: #1a1a2e;
    box-shadow: 0 4px 20px rgba(0,0,0,.1);
    transition: transform .2s, box-shadow .2s;
}

.ig-img-wrap:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 32px rgba(0,0,0,.18);
}

.ig-img-wrap img {
    width: 100%;
    display: block;
    vertical-align: bottom;
}

.ig-img-actions {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 14px 14px 12px;
    background: linear-gradient(0deg, rgba(0,0,0,.7) 0%, transparent 100%);
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity .2s;
}

.ig-img-wrap:hover .ig-img-actions { opacity: 1; }

.ig-img-btn {
    flex: 1;
    padding: 7px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,.18);
    backdrop-filter: blur(4px);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    border: 1px solid rgba(255,255,255,.25);
    transition: background .15s;
}

.ig-img-btn:hover { background: rgba(255,255,255,.3); }

/* ─── 历史记录 ─── */
.ig-history-section {
    margin-top: 8px;
}

.ig-history-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #374151;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
}

.ig-history-header i { color: #7c3aed; }

.ig-history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ig-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 0;
    margin-top: 4px;
}

.ig-pagination button {
    padding: 4px 14px;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: all .2s;
}

.ig-pagination button:hover:not(:disabled) {
    color: #7c3aed;
    border-color: #7c3aed;
    background: rgba(124, 58, 237, .06);
}

.ig-pagination button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.ig-pagination span {
    font-size: 12px;
    color: #9ca3af;
    min-width: 60px;
    text-align: center;
}

.ig-history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e8eaed;
    transition: border-color .2s, box-shadow .2s;
}

.ig-history-item:hover {
    border-color: #7c3aed;
    box-shadow: 0 2px 10px rgba(124, 58, 237, .08);
}

.ig-history-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
}

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

.ig-history-info {
    flex: 1;
    min-width: 0;
}

.ig-history-prompt {
    font-size: 12px;
    font-weight: 500;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}

.ig-history-meta {
    font-size: 10px;
    color: #9ca3af;
}

.ig-history-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.ig-history-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    background: #fafafa;
    color: #6b7280;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}

.ig-history-btn:hover {
    border-color: #7c3aed;
    color: #7c3aed;
    background: rgba(124, 58, 237, .05);
}

/* ─── 响应式 ─── */

/* ─── 图片预览弹框 ─── */
.ig-preview-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: pointer;
}

.ig-preview-overlay.show { display: flex; }

.ig-preview-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
}

/* ─── 提示弹框 ─── */
.ig-toast-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    backdrop-filter: blur(2px);
}

.ig-toast-overlay.show {
    display: flex;
    animation: igToastFade .2s ease;
}

@keyframes igToastFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ig-toast {
    background: #fff;
    border-radius: 20px;
    padding: 36px 32px 28px;
    max-width: 340px;
    width: 90%;
    text-align: center;
    box-shadow: 0 12px 48px rgba(0,0,0,.15);
    animation: igToastUp .3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes igToastUp {
    from { transform: scale(.85) translateY(10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.ig-toast-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(124,58,237,.12), rgba(124,58,237,.04));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
}

.ig-toast-icon i {
    font-size: 26px;
    color: #7c3aed;
}

.ig-toast-title {
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 8px;
}

.ig-toast-desc {
    font-size: 14px;
    color: #6b7280;
    line-height: 1.6;
    margin: 0 0 24px;
}

.ig-toast-btn {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #7c3aed, #9d5cff);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all .2s;
}

.ig-toast-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(124,58,237,.35);
}

.ig-toast-btn:active {
    transform: translateY(0);
}

/* ─── 响应式 ─── */
@media (max-width: 768px) {
    .ig-page { flex-direction: column; }
    .ig-panel { width: 100%; max-width: 100%; border-right: none; border-bottom: 1px solid #e8eaed; }
    .ig-result { padding: 20px 16px; }
    .ig-gallery { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .ig-gallery { grid-template-columns: 1fr; }
}
