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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --dark: #1f2937;
    --dark-bg: #111827;
    --light: #f9fafb;
    --gray: #6b7280;
    --gray-light: #e5e7eb;
    --white: #ffffff;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

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

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
}

/* ==================== HEADER ==================== */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.header p {
    color: var(--gray);
    font-size: 1rem;
}

/* ==================== STATUS CARDS ==================== */
.status-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.status-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.status-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.status-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray);
    margin-bottom: 12px;
}

.status-card .value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* ==================== LIMIT WARNING ==================== */
.limit-warning {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    border-left: 4px solid var(--warning);
}

.limit-warning .message {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    color: #92400e;
}

.watch-ad-btn {
    background: var(--warning);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.watch-ad-btn:hover {
    background: #d97706;
    transform: translateY(-1px);
}

/* ==================== AD BLOCKS ==================== */
.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.ad-block {
    background: #f8fafc;
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: center;
    border: 1px solid var(--border);
}

.ad-bottom {
    margin-top: 24px;
    padding: 20px;
    background: #f8fafc;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--border);
}

.ad-title {
    font-size: 0.75rem;
    color: var(--gray);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ad-container {
    min-height: 90px;
    background: rgba(0,0,0,0.02);
    border-radius: var(--radius-sm);
}

/* ==================== TABS ==================== */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    background: var(--white);
    padding: 8px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius-lg);
    color: var(--gray);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: var(--light);
    color: var(--dark);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

/* ==================== TAB CONTENT ==================== */
.tab-content {
    display: none;
    background: var(--white);
    border-radius: var(--radius-xl);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

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

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

/* ==================== CHAT ==================== */
.chat-container {
    height: 500px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    background: var(--light);
}

.message {
    margin-bottom: 16px;
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.message-content {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 20px;
    line-height: 1.5;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--white);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* ==================== INPUT AREA ==================== */
.input-area {
    display: flex;
    gap: 12px;
}

.input-area input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    transition: all 0.2s;
}

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

/* ==================== ТЕКСТОВЫЕ ПОЛЯ (ДИНАМИЧНЫЕ) ==================== */
textarea {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s;
    resize: vertical;
}

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

/* Генерация изображений - большое поле */
#image-prompt {
    min-height: 150px;
    font-size: 1rem;
}

/* Редактирование - поле инструкции */
#edit-instruction {
    min-height: 120px;
    font-size: 1rem;
}

/* Генерация кода */
#code-description {
    min-height: 120px;
    font-size: 1rem;
}

/* ==================== SELECT (ВЫПАДАЮЩИЕ СПИСКИ) ==================== */
select {
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ==================== LABELS ==================== */
label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: var(--dark);
}

/* Контейнер для настроек */
.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin: 20px 0;
    padding: 16px;
    background: var(--light);
    border-radius: var(--radius-lg);
}

/* ==================== BUTTONS ==================== */
.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary {
    background: var(--gray);
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
}

/* ==================== LOADING ==================== */
.loading {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==================== FILE UPLOAD ==================== */
.file-upload {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--light);
}

.file-upload:hover {
    border-color: var(--primary);
    background: #eff6ff;
}

/* ==================== IMAGE RESULTS ==================== */
.image-result {
    margin-top: 24px;
}

.image-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: white;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.image-card img {
    width: 100%;
    height: auto;
    display: block;
}

.prompt-text {
    padding: 16px;
    background: var(--light);
    font-size: 0.875rem;
    color: var(--gray);
    border-top: 1px solid var(--border);
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

/* ==================== CODE BLOCK ==================== */
.code-block {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 20px;
    border-radius: var(--radius-lg);
    overflow-x: auto;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    margin-top: 20px;
}

.code-block pre {
    margin: 0;
}

/* ==================== MODAL ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius-xl);
    padding: 32px;
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 12px;
    color: var(--dark);
}

.modal-content p {
    color: var(--gray);
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 16px;
    margin-top: 24px;
    justify-content: center;
}

#timer-countdown {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary);
}

/* ==================== PREVIEW ==================== */
#edit-preview img,
#analyze-preview img {
    max-width: 100%;
    max-height: 350px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .tab-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
    
    .tab-content {
        padding: 20px;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .input-area {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .settings-row {
        flex-direction: column;
    }
    
    select {
        width: 100%;
    }
    
    .image-grid {
        grid-template-columns: 1fr;
    }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--gray);
    border-radius: 10px;
}

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