/* ==================== БАЗОВЫЕ СТИЛИ ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== ШАПКА ==================== */
.header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header h1 {
    font-size: 1.5rem;
    color: #333;
    margin: 0;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

/* ==================== КНОПКИ ==================== */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    display: inline-block;
    font-size: 0.9rem;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.btn-download {
    background: none;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-download:hover {
    text-decoration: underline;
}

/* ==================== ОСНОВНОЙ КОНТЕНТ ==================== */
main {
    flex: 1;
    padding: 2rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* ==================== КАРТОЧКИ (ОБЩИЕ) ==================== */
.card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
}

.card-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 1.5rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
}

/* ==================== КАРТОЧКИ ГЕНЕРАЦИЙ ==================== */
.generations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.generation-card {
    background: white;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    position: relative;
}

.generation-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

.card-preview {
    height: 200px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-preview .no-image {
    text-align: center;
    color: #999;
    font-size: 3rem;
}

.card-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    z-index: 2;
}

.badge-completed { background: #28a745; }
.badge-processing { background: #17a2b8; }
.badge-pending { background: #ffc107; color: #333; }
.badge-failed { background: #dc3545; }

.card-content {
    padding: 1rem;
    position: relative;
    z-index: 0;
}

.card-title {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.5rem;
    font-family: monospace;
}

.card-prompt {
    font-size: 0.95rem;
    color: #333;
    margin-bottom: 0.75rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.8rem;
    color: #999;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid #e0e0e0;
    padding-top: 1rem;
    position: relative;
    z-index: 3;
}

.delete-btn {
    position: relative;
    z-index: 4;
}

/* ==================== СТРАНИЦА РЕЗУЛЬТАТА ==================== */
.result-container {
    max-width: 1000px;
    margin: 0 auto;
}

.status-badge {
    display: inline-block;
    padding: 0.35rem 1rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-completed { background: #28a745; color: white; }
.status-processing { background: #17a2b8; color: white; }
.status-pending { background: #ffc107; color: #333; }
.status-failed { background: #dc3545; color: white; }

/* Компактная секция промта */
.prompt-section {
    background: #f8f9fa;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    max-height: 150px;
    overflow-y: auto;
}

.prompt-section h5 {
    margin-bottom: 0.5rem;
    color: #667eea;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.prompt-text {
    font-family: monospace;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85rem;
    line-height: 1.4;
}

.prompt-item {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed #e0e0e0;
}

.prompt-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.prompt-label {
    display: inline-block;
    background: #e3f2fd;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #1976d2;
    margin-right: 0.5rem;
}

/* Крупная картинка результата */
.result-image {
    margin: 1.5rem 0;
    text-align: center;
    background: #f5f5f5;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: pointer;
}

.result-image img {
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
    transition: transform 0.2s;
}

.result-image img:hover {
    transform: scale(1.02);
}

.result-caption {
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.05);
    font-size: 0.85rem;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Сетка изображений */
.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.image-card {
    background: white;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

.image-card .image-actions {
    padding: 0.75rem;
    text-align: center;
    border-top: 1px solid #e0e0e0;
}

/* Входные изображения */
.input-images {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e0e0e0;
}

.input-images h5 {
    margin-bottom: 1rem;
    color: #6c757d;
    font-size: 1rem;
}

.input-thumbnails {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.input-thumb {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.input-thumb:hover {
    transform: scale(1.05);
}

/* Спиннер загрузки */
.loading-spinner {
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Сообщения об ошибках */
.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid #dc3545;
}

.workflow-info {
    background: #e3f2fd;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: #1976d2;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==================== КАРТОЧКИ КОНТАКТОВ ==================== */
.contact-card-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            padding: 20px;
        }

.contact-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: transform 0.3s ease;
}

.contact-card .card-media {
    height: 60%;
    background-size: cover;
    background-position: center;
}

.contact-card .card-content {
    padding: 1rem;
    background: white;
}

.contact-card .card-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.add-card {
    aspect-ratio: 1 / 1;
    border: 2px dashed #ccc;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    text-decoration: none;
    background: white;
    transition: all 0.3s;
}

.add-card:hover {
    border-color: #667eea;
    color: #667eea;
    transform: scale(1.05);
}

/* ==================== ФОРМЫ (ДИНАМИЧЕСКИЕ) ==================== */
.dynamic-fields-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
}

.image-preview {
    max-width: 150px;
    margin-top: 0.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
}

.image-preview img {
    width: 100%;
    height: auto;
}

/* ==================== СТРАНИЦЫ АВТОРИЗАЦИИ ==================== */
.auth-body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    justify-content: center;
    align-items: center;
}

.auth-container {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    margin: 1rem;
}

.auth-container h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #333;
}

/* ==================== ФОРМЫ ==================== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.help-text {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.errorlist {
    color: #dc3545;
    list-style: none;
    padding: 0;
    margin-top: 0.25rem;
}

/* ==================== СООБЩЕНИЯ ==================== */
.messages {
    padding: 1rem;
    margin: 1rem 2rem;
    border-radius: 0.5rem;
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.messages.error {
    background: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

/* ==================== СЕТКА ==================== */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: -0.5rem;
}

.col {
    flex: 1;
    padding: 0.5rem;
}

.col-6 {
    width: 50%;
    padding: 0.5rem;
}

.col-12 {
    width: 100%;
    padding: 0.5rem;
}

/* ==================== УТИЛИТЫ ==================== */
.text-center { text-align: center; }
.text-muted { color: #6c757d; }
.mt-3 { margin-top: 1rem; }
.mb-3 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1.5rem; }
.py-5 { padding-top: 3rem; padding-bottom: 3rem; }

/* ==================== МОДАЛЬНОЕ ОКНО ==================== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.modal-content img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 90vh;
}

.modal-caption {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: white;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
}

.close-modal:hover {
    color: #bbb;
}

/* ==================== АДАПТИВНОСТЬ ==================== */
@media (max-width: 768px) {
    .result-image img {
        max-height: 50vh;
    }
    
    .prompt-section {
        max-height: 120px;
    }
    
    .header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    /* Если кнопки все еще не помещаются, делаем их на всю ширину */
    .btn {
        flex: 1;
        min-width: 120px;
        text-align: center;
    }
    
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}