/* ===== CSS Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #232340;
    --bg-input: #2a2a45;
    --text-primary: #e8e8f0;
    --text-secondary: #9a9abf;
    --text-muted: #6a6a8a;
    --accent: #6c5ce7;
    --accent-hover: #7c6df7;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --success: #00d68f;
    --error: #ff6b6b;
    --border: #2e2e4a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Layout ===== */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 28px;
}

.app-header .logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-header .logo svg { -webkit-text-fill-color: initial; }

.provider-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.provider-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

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

/* ===== Main Grid ===== */
.main-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 28px;
    flex: 1;
}

/* ===== Left Panel ===== */
.input-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 28px;
    height: fit-content;
    position: sticky;
    top: 24px;
}

.input-panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

/* ===== Upload Zone ===== */
.upload-zone {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.05);
}

.upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.1);
    box-shadow: 0 0 24px var(--accent-glow);
}

/* Upload Slots（固定 3 个上传框） */
.upload-slots {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 14px;
}

.upload-slot {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    overflow: hidden;
    user-select: none;
}

.upload-slot:hover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.08);
    color: var(--text-secondary);
}

.upload-slot svg { opacity: 0.5; }

.upload-slot .slot-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.upload-slot .slot-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* 已填充的槽位 */
.upload-slot.filled {
    border-style: solid;
    border-color: var(--accent);
    background: var(--bg-primary);
    cursor: pointer;
}

.upload-slot.filled .slot-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.upload-slot.filled .slot-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    z-index: 1;
}

.upload-slot.filled .slot-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.65);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition);
    z-index: 1;
}

.upload-slot.filled .slot-remove:hover {
    background: var(--error);
}

.upload-slot.filled .slot-replace-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 4px 0;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 11px;
    text-align: center;
    opacity: 0;
    transition: opacity var(--transition);
    z-index: 1;
}

.upload-slot.filled:hover .slot-replace-hint {
    opacity: 1;
}

/* ===== Fixed Prompt Card ===== */
.fixed-prompt-card {
    margin-top: 18px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.fixed-prompt-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.fixed-prompt-text {
    font-size: 13px;
    color: var(--accent);
    line-height: 1.5;
    padding: 8px 12px;
    background: rgba(108, 92, 231, 0.08);
    border-radius: 6px;
    border-left: 3px solid var(--accent);
}

/* ===== Info Note ===== */
.info-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    padding: 10px 14px;
    background: rgba(108, 92, 231, 0.06);
    border: 1px solid rgba(108, 92, 231, 0.15);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.info-note svg {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--accent);
}

/* ===== Generate Button ===== */
.btn-generate {
    width: 100%;
    padding: 14px 24px;
    margin-top: 18px;
    background: linear-gradient(135deg, var(--accent), #8b7cf7);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

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

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

.btn-generate .spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-generate.loading .spinner { display: inline-block; }
.btn-generate.loading .btn-text { display: none; }
.btn-generate.loading .btn-loading-text { display: inline; }
.btn-generate .btn-loading-text { display: none; }

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

/* ===== Result Panel ===== */
.result-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ===== Status Bar ===== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
    min-height: 52px;
}

.status-bar .status-idle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-bar .status-generating {
    display: none;
    align-items: center;
    gap: 10px;
    color: var(--accent);
}

.status-bar .status-done {
    display: none;
    align-items: center;
    gap: 8px;
    color: var(--success);
}

.status-bar.generating .status-idle,
.status-bar.generating .status-done { display: none; }
.status-bar.generating .status-generating { display: flex; }

.status-bar.done .status-idle,
.status-bar.done .status-generating { display: none; }
.status-bar.done .status-done { display: flex; }

/* ===== Gallery ===== */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    flex: 1;
}

.gallery-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 40px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 2px dashed var(--border);
    text-align: center;
    color: var(--text-muted);
    gap: 16px;
}

.gallery-empty svg { opacity: 0.4; }
.gallery-empty h3 { font-size: 18px; color: var(--text-secondary); }
.gallery-empty p { font-size: 14px; max-width: 360px; }

/* ===== Image Card ===== */
.image-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: all var(--transition);
    animation: fadeInUp 0.4s ease-out;
}

.image-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

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

.image-card .image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg-primary);
    overflow: hidden;
}

.image-card .image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.image-card:hover .image-wrapper img { transform: scale(1.03); }

.image-card .card-body {
    padding: 14px 16px;
}

.image-card .card-body .card-prompt {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.image-card .card-body .card-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

.image-card .card-actions {
    display: flex;
    gap: 8px;
    padding: 0 16px 14px;
}

.image-card .card-actions button {
    flex: 1;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}

.image-card .card-actions button:hover {
    background: var(--bg-input);
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== Image Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 40px;
    backdrop-filter: blur(8px);
}

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

.modal-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    animation: zoomIn 0.3s ease-out;
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-overlay .modal-close {
    position: fixed;
    top: 20px;
    right: 28px;
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity var(--transition);
}

.modal-overlay .modal-close:hover { opacity: 1; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    box-shadow: var(--shadow);
    animation: slideInRight 0.3s ease-out;
    min-width: 280px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
.toast .toast-icon { font-size: 18px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--error); }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.removing {
    animation: slideOutRight 0.3s ease-in forwards;
}

@keyframes slideOutRight {
    to { transform: translateX(100%); opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .main-grid { grid-template-columns: 1fr; }
    .input-panel { position: static; }
    .upload-zone { aspect-ratio: auto; min-height: 260px; }
}

@media (max-width: 640px) {
    .app-container { padding: 12px; }
    .app-header { flex-direction: column; gap: 12px; text-align: center; }
    .gallery { grid-template-columns: 1fr; }
}

/* ===== Header 用户区 ===== */
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.user-info .user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a29bfe);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-logout {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-logout:hover {
    border-color: var(--error);
    color: var(--error);
}

@media (max-width: 640px) {
    .header-right { flex-direction: column; width: 100%; }
    .user-info { width: 100%; justify-content: center; }
    .btn-logout { width: 100%; }
}

/* ===== 登录页 ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(108, 92, 231, 0.12), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(108, 92, 231, 0.08), transparent 40%),
        var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    animation: fadeInUp 0.4s ease-out;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo svg {
    color: var(--accent);
    margin-bottom: 8px;
}

.login-logo h1 {
    font-size: 26px;
    font-weight: 700;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-logo p {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 18px;
}

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

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all var(--transition);
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.login-error {
    padding: 10px 14px;
    margin-bottom: 14px;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.35);
    border-radius: var(--radius-sm);
    color: var(--error);
    font-size: 13px;
}

.btn-login {
    width: 100%;
    padding: 13px 24px;
    background: linear-gradient(135deg, var(--accent), #8b7cf7);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-login:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

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

.btn-login .spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-login.loading .spinner { display: inline-block; }
.btn-login.loading .btn-text { opacity: 0.7; }

.login-security {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 22px;
    font-size: 12px;
    color: var(--text-muted);
}

.login-security svg {
    color: var(--success);
    flex-shrink: 0;
}
