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

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg: #0f172a;
    --bg-light: #1e293b;
    --bg-lighter: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --error: #ef4444;
    --sidebar-width: 280px;
}

/* Alpine.js cloak */
[x-cloak] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-light);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

.balance {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-lighter);
    border-radius: 0.5rem;
}

.balance-label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.balance-value {
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--success);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem;
}

.nav-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

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

.nav-item.active {
    background: var(--primary);
    border-color: var(--primary);
}

.nav-item .icon {
    font-size: 1.5rem;
}

.nav-item small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.nav-item.active small {
    color: rgba(255, 255, 255, 0.8);
}

.history-btn {
    margin-top: auto;
    background: var(--bg-lighter);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
}

.model-section {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
}

.model-section h2 {
    margin-bottom: 1.5rem;
    font-size: 1.75rem;
}

/* Forms */
.generation-form {
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="file"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group input:disabled,
.form-group textarea:disabled,
.form-group select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.upload-preview {
    margin-top: 1rem;
    max-width: 300px;
}

.upload-preview img {
    width: 100%;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

/* Buttons */
.btn-primary {
    padding: 0.875rem 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

/* Mode Selector (Veo) */
.mode-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.mode-btn {
    flex: 1;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    border-color: var(--primary);
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

/* Result Section */
.result-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.result-section h3 {
    margin-bottom: 1rem;
}

.result-content {
    background: var(--bg);
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.result-content img,
.result-content video {
    max-width: 100%;
    border-radius: 0.5rem;
    display: block;
}

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

.modal-content {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 1rem;
    max-width: 1000px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-header h2 {
    font-size: 1.5rem;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
}

.close-btn:hover {
    color: var(--text);
}

/* History Grid */
.history-grid {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.history-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.history-thumbnail {
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
    background: var(--bg-lighter);
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-info {
    padding: 1rem;
}

.history-prompt {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-info small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Error Message */
.error-message {
    position: fixed;
    top: 2rem;
    right: 2rem;
    background: var(--error);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 2000;
    max-width: 400px;
}

/* Progress Indicator */
.progress-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    text-align: center;
    z-index: 1500;
}

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

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: relative;
        height: auto;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .history-grid {
        grid-template-columns: 1fr;
    }
}

/* Dropzone styles */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    background: var(--bg);
    transition: all 0.3s;
    cursor: pointer;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dropzone:hover {
    border-color: var(--primary);
    background: var(--bg-lighter);
}

.dropzone.has-file {
    padding: 0;
    min-height: auto;
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.dropzone-icon {
    font-size: 3rem;
}

.dropzone-text {
    font-size: 1.125rem;
    color: var(--text);
    margin: 0;
}

.dropzone-subtext {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
}

.dropzone-button {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
    font-weight: 600;
}

.dropzone-button:hover {
    background: var(--primary-hover);
}

.dropzone-preview {
    position: relative;
    width: 100%;
}

.dropzone-preview img {
    width: 100%;
    height: auto;
    border-radius: 0.5rem;
    display: block;
}

.preview-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--error);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.preview-remove:hover {
    transform: scale(1.1);
}