:root {
    --primary-color: #2563eb;
    --secondary-color: #7c3aed;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
}

/* Light theme (fallback) */
:root[data-theme="light"] {
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --container-bg: #ffffff;
    --header-bg-start: #111827;
    --header-bg-end: #1f2937;
    --section-bg: #ffffff;
    --section-alt-bg: #f9fafb;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --input-bg: #ffffff;
    --input-border: #e5e7eb;
    --upload-bg: #f9fafb;
    --upload-hover-bg: #eff6ff;
    --checkbox-hover-bg: #f9fafb;
    --result-card-bg: #ffffff;
}

/* Dark theme (default) */
:root,
:root[data-theme="dark"] {
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e293b;
    --container-bg: #1e293b;
    --header-bg-start: #0f172a;
    --header-bg-end: #1e293b;
    --section-bg: #1e293b;
    --section-alt-bg: #334155;
    --border-color: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --input-bg: #334155;
    --input-border: #475569;
    --upload-bg: #334155;
    --upload-hover-bg: #475569;
    --checkbox-hover-bg: #334155;
    --result-card-bg: #334155;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--container-bg);
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, var(--header-bg-start) 0%, var(--header-bg-end) 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    position: relative;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.tagline {
    color: #9ca3af;
    font-size: 1.1rem;
}

section {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
}

section:last-of-type {
    border-bottom: none;
}

h2 {
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

h3 {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

/* Upload Zone */
.upload-zone {
    border: 3px dashed var(--border-color);
    border-radius: 0.5rem;
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--upload-bg);
}

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

.upload-zone.drag-over {
    border-color: var(--primary-color);
    background: var(--upload-hover-bg);
    opacity: 0.8;
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.upload-zone p {
    color: var(--text-primary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.upload-zone small {
    color: var(--text-secondary);
}

.file-info {
    margin-top: 1rem;
    padding: 1rem;
    background: #ecfdf5;
    border-left: 4px solid var(--success-color);
    border-radius: 0.25rem;
}

.file-info p {
    margin: 0.5rem 0;
    color: var(--text-primary);
}

/* Options */
.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.option-group {
    display: flex;
    flex-direction: column;
}

.option-group.full-width {
    grid-column: 1 / -1;
}

.option-group label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.option-group input,
.option-group select {
    padding: 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 0.375rem;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.2s;
}

.option-group input:focus,
.option-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Checkboxes */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.checkbox-label {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.checkbox-label:hover {
    border-color: var(--primary-color);
    background: var(--checkbox-hover-bg);
}

.checkbox-label input[type="checkbox"] {
    margin-right: 0.5rem;
}

.checkbox-label span {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.checkbox-label small {
    color: var(--text-secondary);
    margin-left: 1.5rem;
}

.checkbox-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.checkbox-inline label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.action-section {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 200px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-save {
    background: linear-gradient(135deg, var(--success-color) 0%, #059669 100%);
    color: white;
}

.btn-save:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
}

.btn-save:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-picture {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.btn-picture:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(245, 158, 11, 0.3);
}

.btn-picture:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Packet Picture Section */
.packet-picture-section {
    background: var(--section-bg);
    border-top: 3px solid var(--primary-color);
}

.packet-picture-info {
    text-align: center;
    margin-bottom: 2rem;
}

.picture-desc {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.picture-credits {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.credits-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--success-color) 0%, #059669 100%);
    border-radius: 1rem;
    color: white;
}

.credits-count {
    font-size: 1.5rem;
    font-weight: 700;
}

.credits-label {
    font-size: 0.85rem;
    opacity: 0.9;
}

.pricing-info {
    padding: 0.75rem 1.25rem;
    background: var(--section-alt-bg);
    border-radius: 0.5rem;
    border-left: 4px solid var(--warning-color);
    color: var(--text-primary);
}

.packet-picture-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.generated-image {
    max-width: 100%;
    border-radius: 1rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border: 4px solid var(--border-color);
}

.picture-prompt {
    background: var(--section-alt-bg);
    padding: 1.5rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--primary-color);
    width: 100%;
    max-width: 800px;
}

.picture-prompt h4 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.picture-prompt p {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.95rem;
}

.loading {
    padding: 3rem;
    text-align: center;
    font-size: 1.5rem;
    color: var(--text-secondary);
    animation: pulse 2s ease-in-out infinite;
}

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

.credits-paid {
    background: linear-gradient(135deg, var(--warning-color) 0%, #d97706 100%);
}

/* Responsive Packet Picture */
@media (max-width: 768px) {
    .picture-credits {
        flex-direction: column;
        gap: 1rem;
    }

    .generated-image {
        max-width: 100%;
    }
}

/* Progress */
.progress-section {
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 2rem;
    background: var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    width: 0%;
    transition: width 0.3s;
}

#progressText {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Results */
.results-section {
    background: var(--section-alt-bg);
}

#resultsContent {
    background: var(--section-bg);
    border-radius: 0.5rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

.result-card {
    background: var(--result-card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.result-card h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.stat {
    padding: 1rem;
    background: var(--section-alt-bg);
    border-radius: 0.375rem;
    border-left: 4px solid var(--primary-color);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.stat-value {
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 700;
}

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 1rem 0;
}

.alert-danger {
    background: #fee2e2;
    border-left: 4px solid var(--danger-color);
    color: #991b1b;
}

.alert-warning {
    background: #fef3c7;
    border-left: 4px solid var(--warning-color);
    color: #92400e;
}

.alert-success {
    background: #d1fae5;
    border-left: 4px solid var(--success-color);
    color: #065f46;
}

.finding-list {
    list-style: none;
    padding: 0;
}

.finding-item {
    padding: 0.75rem;
    background: var(--section-alt-bg);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

.finding-item strong {
    color: var(--danger-color);
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 2rem;
    right: 2rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 2rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    font-weight: 600;
    transition: all 0.3s;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

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

/* Auth Section */
.auth-section {
    position: absolute;
    top: 2rem;
    left: 2rem;
}

.auth-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 2rem;
    padding: 0.5rem 1.25rem;
    cursor: pointer;
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s;
}

.auth-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: white;
    font-weight: 600;
}

.auth-btn-small {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 1rem;
    padding: 0.25rem 0.75rem;
    cursor: pointer;
    color: white;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.auth-btn-small:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Filter Sections */
.filter-section {
    margin-bottom: 1.5rem;
}

.filter-examples a {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
    padding: 0.25rem;
}

.filter-examples a:hover {
    text-decoration: underline;
}

textarea {
    padding: 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 0.375rem;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-primary);
    width: 100%;
    font-family: monospace;
    transition: all 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Footer */
footer {
    background: var(--header-bg-end);
    color: white;
    text-align: center;
    padding: 2rem;
}

footer small {
    color: #9ca3af;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .options-grid {
        grid-template-columns: 1fr;
    }

    .checkbox-grid {
        grid-template-columns: 1fr;
    }

    .action-section {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}
