:root {
    --bg-color: #0f172a;
    --sidebar-bg: rgba(30, 41, 59, 0.7);
    --card-bg: rgba(51, 65, 85, 0.5);
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: rgba(148, 163, 184, 0.1);
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans SC', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    border-right: var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: relative;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 3rem;
    color: var(--accent-color);
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-links li {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-links li.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.settings-trigger {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    margin-top: auto;
    border-top: var(--glass-border);
    padding-top: 1.5rem;
}

.settings-trigger:hover {
    color: var(--text-primary);
}

/* Sidebar Bottom — Status + Debug */
.sidebar-bottom {
    margin-top: auto;
    border-top: var(--glass-border);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sidebar-status .status-dot {
    width: 8px;
    height: 8px;
    min-width: 8px;
    border-radius: 50%;
    background: #ef4444;
    transition: all 0.3s;
}

.sidebar-status .status-dot.connected {
    background: #22c55e;
    box-shadow: 0 0 6px #22c55e;
}

.debug-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.375rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.debug-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.debug-toggle-btn.active {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

/* Debug Section (Tab Content) */
.debug-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid rgba(239, 68, 68, 0.2);
    background: rgba(10, 10, 20, 0.6);
}

.debug-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.08);
    border-bottom: 1px solid rgba(239, 68, 68, 0.15);
}

.debug-title {
    font-size: 0.85rem;
    color: #f87171;
    font-weight: 500;
}

.debug-actions {
    display: flex;
    gap: 0.5rem;
}

.debug-action-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.3rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.debug-action-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

.debug-log-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    font-size: 0.72rem;
    font-family: 'Consolas', 'Fira Code', monospace;
    color: #a5f3a5;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    min-height: 300px;
}

/* Main Content */
.content-area {
    flex: 1;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

/* API Key Bar */
.api-key-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
}

.api-key-bar .status-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    border-radius: 50%;
    background-color: #ef4444;
    transition: all 0.3s ease;
}

.api-key-bar .status-dot.connected {
    background-color: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

.api-key-bar input[type="password"] {
    width: 220px;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.375rem;
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.api-key-bar input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-color);
}

.key-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.key-save-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    border: none;
    border-radius: 0.375rem;
    color: white;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    transition: transform 0.1s, box-shadow 0.2s;
}

.key-save-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.key-save-btn:active {
    transform: translateY(0);
}

/* Tabs */
.tab-content {
    display: none;
    /* Hidden by default */
    flex: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Generation Container Layout */
.generation-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 2rem;
    height: 100%;
}

.controls-panel {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    padding: 1.5rem;
    border-radius: 1rem;
    border: var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: fit-content;
}

/* Inputs */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

textarea,
select,
input[type="text"],
input[type="password"] {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    padding: 0.75rem;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
}

textarea {
    height: 120px;
}

textarea:focus,
input:focus,
select:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    border: none;
    padding: 0.875rem;
    border-radius: 0.5rem;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

.primary-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Preview Panel */
.preview-panel {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 1rem;
    border: 2px dashed rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    min-height: 400px;
}

.preview-panel img,
.preview-panel video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.placeholder i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* File Upload */
.file-upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.file-upload-zone:hover {
    border-color: var(--accent-color);
    background: rgba(59, 130, 246, 0.05);
}

.file-upload-zone img {
    max-width: 100%;
    max-height: 200px;
    display: none;
    margin-top: 1rem;
    border-radius: 0.25rem;
}

.file-upload-zone img.visible {
    display: block;
}



/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: #1e293b;
    width: 500px;
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
    border: var(--glass-border);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 1rem 1rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
}

.close-btn:hover {
    color: white;
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    padding-bottom: 2rem;
}

.gallery-item {
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    border: var(--glass-border);
    cursor: zoom-in;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.gallery-item:hover img {
    transform: scale(1.05);
}

/* Gallery Overlay (prompt + model info on hover) */
.gallery-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    padding: 2.5rem 0.75rem 0.75rem;
    opacity: 0;
    transition: opacity 0.25s ease;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.gallery-item:hover .gallery-overlay {
    opacity: 1;
}

.gallery-prompt {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.gallery-model {
    font-size: 0.6rem;
    color: var(--accent-color);
    opacity: 0.8;
}

/* Gallery Delete Button */
.gallery-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: rgba(239, 68, 68, 0.85);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

.gallery-item:hover .gallery-delete-btn {
    opacity: 1;
}

.gallery-delete-btn:hover {
    transform: scale(1.15);
    background: #ef4444;
}

/* Gallery Empty State */
.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.gallery-empty i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.gallery-empty p {
    font-size: 0.95rem;
}

/* Lightbox */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    animation: fadeIn 0.2s ease;
    cursor: zoom-out;
}

.lightbox-overlay.hidden {
    display: none;
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 75vh;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    cursor: default;
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.lightbox-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 90vw;
}

.lightbox-info p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    max-width: 600px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lightbox-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    color: white;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s;
}

.lightbox-download-btn:hover {
    background: var(--accent-hover);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    border: var(--glass-border);
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideInRight 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.success {
    border-left-color: #22c55e;
}

.toast i {
    font-size: 1.25rem;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        border-right: none;
        border-top: var(--glass-border);
        padding: 0.5rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        background: rgba(15, 23, 42, 0.95);
    }

    .logo {
        display: none;
    }

    .nav-links {
        display: flex;
        justify-content: space-around;
        width: 100%;
        margin: 0;
    }

    .nav-links li {
        flex-direction: column;
        gap: 0.25rem;
        font-size: 0.75rem;
        padding: 0.5rem;
        margin: 0;
        border-radius: 0.5rem;
    }

    .nav-links li i {
        font-size: 1.25rem;
    }

    .settings-trigger {
        display: none;
        /* Accessible via other means or simplify for mobile */
        /* For now, maybe add settings as a tab or keep hidden on mobile MVP */
    }

    /* Add a Settings icon to the nav for mobile if needed, 
       but for now let's make the last item Settings or keep it simple.
       Actually, let's keep Settings Trigger but move it into the flex row */

    .settings-trigger {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        font-size: 0.75rem;
        padding: 0.5rem;
        margin: 0;
        border-top: none;
        align-items: center;
    }

    .content-area {
        padding: 1rem;
        padding-bottom: 80px;
        /* Space for bottom nav */
        overflow-y: auto;
    }

    .generation-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .preview-panel {
        min-height: 300px;
        order: -1;
        /* Preview on top for mobile? Or keep bottom? Standard is controls top. Keep default order. */
    }

    .modal {
        width: 90%;
    }
}

/* Multi-Image Upload Grid */
.multi-upload-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
}

.image-grid-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 2px solid var(--border-color);
    transition: all 0.2s ease;
}

.image-grid-item:hover {
    border-color: var(--accent-color);
}

.image-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-grid-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(239, 68, 68, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.image-grid-item:hover .remove-btn {
    opacity: 1;
}

.add-image-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--card-bg);
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-image-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.add-image-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}