/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette */
    --bg-primary: #0a0a0f;
    --bg-card: #15151f;
    --bg-hover: #1f1f2e;
    --border-color: #27272a;
    --accent-primary: #00d4ff;
    --accent-secondary: #7c3aed;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #00d4ff 0%, #7c3aed 100%);
    --gradient-hover: linear-gradient(135deg, #00b8e6 0%, #6d28d9 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(0, 212, 255, 0.3);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-hover);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: var(--transition-fast);
}

.status-indicator.connected {
    background: var(--success);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.status-indicator.error {
    background: var(--error);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

.status-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 2rem;
    padding: 2rem;
    flex: 1;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Control Panel */
.control-panel {
    background: var(--bg-card);
    border-radius: 1rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    height: fit-content;
    position: sticky;
    top: 6rem;
}

.section {
    margin-bottom: 2rem;
}

.section:last-child {
    margin-bottom: 0;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

/* Navigation Tabs */
.nav-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.nav-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-normal);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
}

.nav-tab:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
}

.nav-tab.active {
    background: var(--gradient-primary);
    border-color: transparent;
    color: white;
    box-shadow: var(--shadow-glow);
}

.tab-icon {
    font-size: 1rem;
}

.tab-content {
    animation: fadeIn 0.3s ease;
}

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

/* Mode Buttons */
.mode-buttons {
    display: grid;
    gap: 0.75rem;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-normal);
    font-family: inherit;
    font-size: 0.875rem;
}

.mode-btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: var(--gradient-primary);
    border-color: transparent;
    color: white;
    box-shadow: var(--shadow-glow);
}

.mode-icon {
    font-size: 1.25rem;
}

.mode-label {
    font-weight: 500;
}

/* Upload Section */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 0.75rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-normal);
    background: var(--bg-hover);
}

.upload-area:hover {
    border-color: var(--accent-primary);
    background: var(--bg-primary);
}

.upload-area.dragover {
    border-color: var(--accent-primary);
    background: var(--bg-primary);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.1);
}

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

.upload-text {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.upload-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.uploaded-image {
    position: relative;
    border-radius: 0.75rem;
    overflow: hidden;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
}

.uploaded-image img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.remove-image {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    transition: var(--transition-fast);
}

.remove-image:hover {
    background: var(--error);
}

/* Prompt Input */
.prompt-input {
    width: 100%;
    padding: 1rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    resize: vertical;
    min-height: 100px;
    transition: var(--transition-fast);
}

.prompt-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

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

/* Model Buttons */
.model-buttons {
    display: grid;
    gap: 0.75rem;
}

.model-btn {
    padding: 1rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: var(--transition-normal);
    font-family: inherit;
    text-align: left;
}

.model-btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.model-btn.active {
    background: var(--gradient-primary);
    border-color: transparent;
    color: white;
    box-shadow: var(--shadow-glow);
}

.model-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.model-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.model-desc {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Count Buttons */
.count-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.count-btn {
    padding: 0.75rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-normal);
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
}

.count-btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.count-btn.active {
    background: var(--gradient-primary);
    border-color: transparent;
    color: white;
    box-shadow: var(--shadow-glow);
}

/* Generate Button */
.generate-btn {
    width: 100%;
    padding: 1rem 1.5rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: 0.75rem;
    color: white;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-glow);
}

.generate-btn:hover {
    background: var(--gradient-hover);
    transform: translateY(-2px);
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.4);
}

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

.generate-btn:disabled:hover {
    transform: none;
    box-shadow: var(--shadow-glow);
}

/* Results Panel */
.results-panel {
    background: var(--bg-card);
    border-radius: 1rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    position: relative;
    min-height: 600px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.results-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.clear-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    font-family: inherit;
    font-size: 0.875rem;
}

.clear-btn:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    min-height: 400px;
}

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-text {
    font-size: 1.125rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.empty-hint {
    font-size: 0.875rem;
    max-width: 300px;
}

/* Image Card */
.image-card {
    background: var(--bg-hover);
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
    transition: var(--transition-normal);
    cursor: pointer;
}

.image-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.image-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.image-card-footer {
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.image-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.download-icon {
    color: var(--accent-primary);
    font-size: 1rem;
    transition: var(--transition-fast);
}

.image-card:hover .download-icon {
    transform: scale(1.2);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 15, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 1rem;
    z-index: 10;
}

.loading-content {
    text-align: center;
    color: var(--text-primary);
}

.loading-spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    animation: modalEnter 0.3s ease;
}

@keyframes modalEnter {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.modal-close:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.modal-body {
    padding: 1.5rem;
    text-align: center;
}

.modal-body img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
}

.download-btn {
    padding: 0.75rem 1.5rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: 0.5rem;
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.download-btn:hover {
    background: var(--gradient-hover);
    transform: translateY(-2px);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .control-panel {
        position: static;
    }
    
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

@media (max-width: 640px) {
    .header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .main-content {
        padding: 1rem;
        gap: 1rem;
    }
    
    .control-panel,
    .results-panel {
        padding: 1rem;
    }
    
    .results-grid {
        grid-template-columns: 1fr;
    }
    
    .modal {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-body img {
        max-height: 60vh;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Selection Styling */
::selection {
    background: var(--accent-primary);
    color: white;
}

/* Focus Styles */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* History Section */
.history-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: var(--bg-hover);
}

.history-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition-fast);
}

.history-item:last-child {
    border-bottom: none;
}

.history-item:hover {
    background: var(--bg-primary);
}

.history-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 0.5rem;
    object-fit: cover;
    border: 1px solid var(--border-color);
}

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

.history-prompt {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-meta {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.history-date,
.history-model {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.loading-state,
.empty-history {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.loading-spinner-small {
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 0.5rem;
}

.empty-history {
    padding: 3rem 2rem;
}

.empty-history-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}