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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

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

.header {
    background: white;
    padding: 10px 15px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    max-width: 1600px;
    margin: 0 auto;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.header h1 {
    color: #2c3e50;
    margin: 0;
    font-size: 1.8em;
    font-weight: 500;
    flex-shrink: 0;
}


.add-form {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: flex;
    margin-bottom: 5px;
    font-weight: 500;
    flex-direction: row;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.btn:hover {
    background: #2980b9;
}

/* Стили для индикатора генерации */
.generation-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    background: #e3f2fd;
    border: 1px solid #2196f3;
    border-radius: 4px;
    font-size: 11px;
    color: #1976d2;
    margin-top: 5px;
}

.generation-indicator .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2196f3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 4px;
}

.generation-indicator.completed {
    background: #e8f5e8;
    border-color: #4caf50;
    color: #2e7d32;
}

.generation-indicator.error {
    background: #ffebee;
    border-color: #f44336;
    color: #c62828;
}

/* Стили для индикатора статуса генерации в области названий */
.generation-status-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: #e3f2fd;
    border: 1px solid #bbdefb;
    border-radius: 6px;
    font-size: 14px;
    color: #1976d2;
    min-height: 40px;
    margin: 4px 0;
}

.generation-status-indicator .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2196f3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.generation-status-indicator.completed {
    background: #e8f5e8;
    border-color: #4caf50;
    color: #2e7d32;
}

.generation-status-indicator.error {
    background: #ffebee;
    border-color: #f44336;
    color: #c62828;
}

.generation-progress {
    font-size: 10px;
    margin-top: 2px;
    color: #666;
}

.btn-success {
    background: #27ae60;
}

.btn-success:hover {
    background: #229954;
}

.btn-danger {
    background: #e74c3c;
    width: 100%;
}

.btn-warning {
    background: #f39c12;
    color: white;
}

.btn-priority {
    background: #f39c12;
    color: white;
    width: 100%;
}

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

.btn-secondary:hover {
    background: #5a6268;
}

.btn-tiny {
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 3px;
    display: inline-block;
    margin-left: 4px;
}

/* Стили для чекбокса generate_refence_script */
.checkbox-container {
    display: inline-block;
    margin-left: 4px;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.generate-refence-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin-right: 4px;
}

.checkbox-text {
    font-size: 10px;
    color: #555;
    white-space: nowrap;
}

.checkbox-label:hover .checkbox-text {
    color: #3498db;
}

/* Стили для ссылок-кнопок */
a.btn {
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

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

.btn-warning:hover {
    background: #e67e22;
}

.btn-priority:hover {
    background: #e67e22;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
    text-align: center;
}

.topics-list {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-top: 180px;
}

.topic-item {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    transition: background-color 0.2s;
    min-height: 80px;
}

.topic-metadata-panel {
    width: fit-content;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.metadata-content {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: flex-start;
}

.metadata-regenerate-section {
    margin-top: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: flex-start;
}

.metadata-regenerate-section .btn {
    font-size: 11px;
    padding: 4px 8px;
}

.metadata-images {
    display: flex;
    flex-direction: row;
    gap: 4px;
    width: fit-content;
    justify-content: flex-start;
    align-items: flex-start;
}

.metadata-title-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1.3;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s, opacity 0.3s ease, pointer-events 0.3s ease;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    width: 400px;
    flex-shrink: 0;
}

.metadata-title-item.empty {
    border-color: #e74c3c;
    background: #fdf2f2;
}

.metadata-title-item.empty .metadata-title-text {
    color: #e74c3c;
    font-style: italic;
}

.metadata-title-text {
    flex: 1;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
    min-width: 0;
    max-width: 80ch;
    word-wrap: break-word;
    line-height: 1.3;
}

.metadata-title-edit {
    background: none;
    border: none;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    color: #6c757d;
    transition: all 0.2s;
    flex-shrink: 0;
}

.metadata-title-edit:hover {
    background: #e9ecef;
    color: #495057;
}

.metadata-title-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
}

.metadata-title-delete {
    background: none;
    border: none;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    color: #dc3545;
    transition: all 0.2s;
    flex-shrink: 0;
}

.metadata-title-delete:hover {
    background: #f8d7da;
    color: #721c24;
}

.metadata-title-input {
    flex: 1;
    padding: 4px 6px;
    border: 2px solid #3498db;
    border-radius: 3px;
    font-size: 12px;
    background: white;
    outline: none;
    min-width: 0;
}

.metadata-title-input:focus {
    border-color: #2980b9;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.metadata-title-buttons {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.metadata-title-save, .metadata-title-cancel {
    padding: 2px 6px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
}

.metadata-title-save {
    background: #27ae60;
    color: white;
}

.metadata-title-save:hover {
    background: #229954;
}

.metadata-title-cancel {
    background: #95a5a6;
    color: white;
}

.metadata-title-cancel:hover {
    background: #7f8c8d;
}

.metadata-title-item:hover {
    background: #e9ecef;
    border-color: #dee2e6;
}

/* Простая подсказка для названий */
.metadata-title-item {
    position: relative;
}



.metadata-image-placeholder.deleted {
    border: 2px solid #e74c3c;
    background: #fdf2f2;
    opacity: 0.6;
}

.metadata-image-placeholder.deleted::after {
    content: "УДАЛЕНО";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #e74c3c;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}

.metadata-image-placeholder.loading {
    border: 2px solid #3498db;
    background: #e3f2fd;
}

.metadata-image-placeholder.loading::after {
    content: "ЗАГРУЗКА...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #3498db;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}

.metadata-image-placeholder.has-image {
    border: 2px solid #27ae60;
    background: #e8f5e8;
}

.metadata-image-placeholder.has-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 2px;
}

/* Стили для состояния загрузки */
.metadata-image-placeholder.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border: 2px dashed #6c757d;
    color: #6c757d;
    font-size: 11px;
    text-align: center;
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 4px;
}

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

/* Стили для пустых блоков */
.metadata-image-placeholder.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff5f5;
    border: 2px solid #e74c3c;
    color: #e74c3c;
    font-size: 11px;
    text-align: center;
}

.empty-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.empty-placeholder span:first-child {
    font-size: 16px;
}

.empty-placeholder span:last-child {
    font-size: 10px;
    font-weight: 500;
}

/* Стили для ошибок */
.metadata-image-placeholder.error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fdf2f2;
    border: 2px solid #e74c3c;
    color: #e74c3c;
    font-size: 11px;
    text-align: center;
}

.error-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.error-placeholder span:first-child {
    font-size: 16px;
}

.error-placeholder span:last-child {
    font-size: 10px;
    font-weight: 500;
}

/* Стили для модального окна замены изображения */
.replace-image-modal {
    z-index: 1500;
}

.replace-image-content {
    max-width: 600px;
    width: 90%;
}

.image-upload-area {
    border: 2px dashed #3498db;
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    background: #f8f9fa;
    margin: 20px 0;
    cursor: pointer;
    transition: all 0.3s;
}

.image-upload-area:hover {
    border-color: #2980b9;
    background: #e3f2fd;
}

.image-upload-area.dragover {
    border-color: #27ae60;
    background: #e8f5e8;
}

.upload-icon {
    font-size: 48px;
    color: #3498db;
    margin-bottom: 10px;
}

.upload-text {
    font-size: 16px;
    color: #555;
    margin-bottom: 5px;
}

.upload-hint {
    font-size: 12px;
    color: #999;
}

.image-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin: 20px 0;
    display: none;
}

.image-preview.show {
    display: block;
}

.file-input {
    display: none;
}

.metadata-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    color: #6c757d;
    font-size: 12px;
}

.metadata-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    color: #dc3545;
    font-size: 12px;
}

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

.topic-item:hover {
    background-color: #f8f9fa;
}

.topic-item.used {
    background-color: #f8f9fa;
    opacity: 0.6;
}

.topic-item.used:hover {
    background-color: #e9ecef;
}

.topic-item.manual {
    border-left: 4px solid #f39c12;
    background-color: #fef9e7;
}

.topic-item.manual:hover {
    background-color: #fdf2d9;
}

.topic-item.manual.used {
    background-color: #f8f9fa;
    border-left-color: #e67e22;
}

.topic-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.topic-title {
    font-weight: 500;
    font-size: 0.9em;
    line-height: 1.3;
    margin-bottom: 2px;
}

.title-container {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 4px;
    width: 100%;
}

.title-text-link {
    word-wrap: break-word;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    min-width: 0;
}

.title-text-link:hover {
    color: #3498db;
    text-decoration: underline;
}

.btn-edit-title {
    color: white;
    border: none;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
    flex-shrink: 0;
    margin-left: 2px;
}

.title-input {
    flex: 1;
    padding: 6px 10px;
    border: 2px solid #3498db;
    border-radius: 4px;
    font-size: 0.95em;
    font-weight: 500;
    background: white;
    outline: none;
    min-width: 0;
    width: 100%;
}

.title-input:focus {
    border-color: #2980b9;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.title-edit-buttons {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-save-title, .btn-cancel-title {
    padding: 4px 8px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
}

.btn-save-title {
    background: #27ae60;
    color: white;
}

.btn-save-title:hover {
    background: #229954;
}

.btn-cancel-title {
    background: #95a5a6;
    color: white;
}

.btn-cancel-title:hover {
    background: #7f8c8d;
}

.topic-meta {
    font-size: 0.75em;
    color: #7f8c8d;
    line-height: 1.2;
    margin-bottom: 2px;
}

/* Стили для отображения дат */
.used-info {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.topic-meta .date-info {
    color: #7f8c8d;
    font-weight: 500;
}

.topic-actions {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: flex-start;
    flex-shrink: 0;
    width: 60px;
    margin-left: 10px;
}

.topic-item.used .topic-actions {
    width: 120px;
}

.topic-preview {
    width: 120px;
    height: 90px;
    border-radius: 4px;
    overflow: hidden;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.topic-preview-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-download-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 3px;
    color: white;
    padding: 2px 4px;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.topic-preview-container:hover .preview-download-btn {
    opacity: 1;
}

.preview-download-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.topic-preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.topic-preview-placeholder {
    font-size: 24px;
    color: #bdc3c7;
}

.channel-names {
    display: block;
    margin-bottom: 4px;
}

.channel-name {
    background: #ecf0f1;
    color: #2c3e50;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.75em;
    font-weight: 500;
}

.channel-name.unknown {
    background: #e74c3c;
    color: white;
}

.public-url-link {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.public-url-link:hover {
    color: #2980b9;
    text-decoration: underline;
}

.used-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.used-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}

.used-actions .btn {
    min-width: 90px;
    text-align: center;
    white-space: nowrap;
    padding: 6px 8px;
    font-size: 12px;
}

.topic-project-link {
    margin-top: 0;
    display: flex;
    justify-content: flex-end;
}

.project-btn {
    background: #6c757d;
    color: white;
    text-decoration: none;
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s;
    border: none;
    cursor: pointer;
}

.project-btn:hover {
    background: #5a6268;
    color: white;
    text-decoration: none;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.error {
    background: #e74c3c;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.success {
    background: #27ae60;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.info {
    background: #3498db;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}

#message {
    flex: 1;
    min-width: 200px;
    max-width: 600px;
    margin: 0 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#message .error,
#message .success,
#message .info {
    margin: 0;
    width: 100%;
    text-align: center;
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 4px;
}

.modal-message {
    display: none;
    padding: 10px 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.4;
}

.modal-message.error {
    display: block;
    background: #e74c3c;
    color: #fff;
}

.modal-message.success {
    display: block;
    background: #27ae60;
    color: #fff;
}

.modal-message.info {
    display: block;
    background: #3498db;
    color: #fff;
}

.refresh-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
}

        .refresh-btn:hover {
            background: #2980b9;
        }
        
        /* Стили для блока фильтров */
        .filters-section {
            background: white;
            padding: 15px 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin-bottom: 20px;
            position: fixed;
            top: 60px;
            left: 0;
            right: 0;
            z-index: 999;
            max-width: 1600px;
            margin: 0 auto;
        }
        
        .filters-content {
            display: flex;
            gap: 15px;
            align-items: center;
            flex-wrap: nowrap;
            overflow-x: auto;
        }
        
        .filter-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .filter-group label {
            font-size: 1em;
            font-weight: 500;
            color: #555;
            white-space: nowrap;
        }
        
        .filter-group select {
            padding: 6px 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            min-width: 120px;
        }
        
        .filter-group select:focus {
            outline: none;
            border-color: #3498db;
        }
        
        .signal-counter {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-right: 10px;
            flex-wrap: nowrap;
            white-space: nowrap;
        }
        
        .counter-label {
            font-size: 13px;
            color: #666;
            font-weight: 500;
        }
        
        .counter-value {
            font-size: 13px;
            font-weight: 600;
            color: #27ae60;
            background: #e8f5e8;
            padding: 2px 6px;
            border-radius: 3px;
            min-width: 20px;
            text-align: center;
        }
        
        .counter-details {
            font-size: 12px;
            color: #888;
            font-weight: 400;
            white-space: nowrap;
        }
        
        /* Стили для поиска */
        .search-section {
            margin-top: 12px;
            padding-top: 12px;
            border-top: 1px solid #eee;
        }
        
        .search-group {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .search-group label {
            font-size: 1em;
            font-weight: 500;
            color: #555;
            white-space: nowrap;
        }
        
        .search-input {
            flex: 1;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            min-width: 300px;
        }
        
        .search-input:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
        }
        
        .search-input::placeholder {
            color: #999;
        }
        
        /* Стили для индикатора загрузки дополнительных результатов */
        .load-more-indicator {
            text-align: center;
            padding: 20px;
            margin-top: 20px;
        }
        
        .load-more-content {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .load-more-content .btn {
            min-width: 200px;
        }
        
        /* Стили для отображения канала */
        .channel-name {
            background: #3498db;
            color: white;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 0.75em;
            font-weight: 500;
            display: inline-block;
            margin-right: 8px;
        }
        
.channel-name.unknown {
    background: #95a5a6;
}

/* Компактные стили для каналов с четким разделением */
.channel-name-compact {
    background: #3498db;
    color: white;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.7em;
    font-weight: 500;
    display: inline-block;
    margin-right: 8px;
    margin-bottom: 3px;
    line-height: 1.2;
    transition: background 0.2s;
    white-space: nowrap;
}

.channel-name-compact:hover {
    background: #2980b9;
}

.channel-name-compact.unknown {
    background: #95a5a6;
}

.channel-name-compact.unknown:hover {
    background: #7f8c8d;
}

/* Контейнеры для компактного и развернутого отображения */
.channels-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    align-items: flex-start;
}

.channels-expanded {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    align-items: flex-start;
    margin-top: 4px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.channels-expanded .channel-name-compact {
    background: #27ae60;
    margin-right: 6px;
    margin-bottom: 3px;
}

.channels-expanded .channel-name-compact:hover {
    background: #229954;
}

/* Кнопки развернуть/свернуть */
.channel-more-compact {
    background: #f39c12;
    color: white;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.7em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-block;
    margin-right: 8px;
    margin-bottom: 3px;
    line-height: 1.2;
    white-space: nowrap;
}

.channel-more-compact:hover {
    background: #e67e22;
}

.channel-less-compact {
    background: #e74c3c;
    color: white;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.65em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-block;
    margin-left: 6px;
    margin-bottom: 3px;
    line-height: 1.3;
}

.channel-less-compact:hover {
    background: #c0392b;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow-y: auto;
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    overflow: visible;
}

/* Специальные стили для модального окна метадаты */
#createMetadataModal .modal-content {
    max-height: 85vh;
    max-width: 1000px;
    width: 95%;
}

#createMetadataModal .result-section {
    max-height: none;
    overflow-y: visible;
}

/* Специальные стили для модального окна превью */
#createPreviewModal .modal-content {
    max-width: 1200px;
    width: 95%;
    overflow: visible;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    color: #2c3e50;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #000;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.btn-cancel {
    background: #95a5a6;
}

.btn-cancel:hover {
    background: #7f8c8d;
}

/* Возврат использованных сигналов */
#returnSignalsChannels {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.channels-group {
    border: 1px solid #e1e6ef;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fafcff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.group-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.group-title {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
}

.group-count {
    font-weight: 600;
    font-size: 13px;
    color: #1d6fd3;
}

.group-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.btn-compact {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
    line-height: 1.2;
}

.group-body {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.return-channel-item {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    gap: 12px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    border: 1px solid transparent;
    background: #ffffff;
    justify-content: space-between;
}

.return-channel-item:hover {
    background-color: #eef3ff;
    border-color: #d5e2ff;
}

.return-channel-checkbox {
    width: 18px !important;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.return-channel-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #2c3e50;
    font-weight: 500;
}

.channel-name-label {
    flex: 1;
}

.channel-used-count {
    font-weight: 600;
    font-size: 12px;
    color: #7f8c9a;
}

.return-channel-item input:checked + .return-channel-info {
    color: #1d6fd3;
}

.return-channel-item input:checked + .return-channel-info .channel-used-count {
    color: #1d6fd3;
}

/* Переключатель */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    margin-bottom: 5px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #3498db;
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.toggle-label {
    font-size: 12px;
    color: #7f8c8d;
    margin-left: 5px;
}

/* Горизонтальная компоновка для формы */
.form-group-horizontal {
    display: flex;
    gap: 20px;
    align-items: flex-end;
}

.form-field {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-field label {
    margin-bottom: 5px;
    font-weight: 500;
}

/* Уменьшенный переключатель */
.toggle-switch-small {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    margin-bottom: 5px;
}

.toggle-switch-small input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider-small {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.toggle-slider-small:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider-small {
    background-color: #3498db;
}

input:checked + .toggle-slider-small:before {
    transform: translateX(20px);
}

.toggle-label-small {
    font-size: 12px;
    color: #7f8c8d;
    margin-left: 8px;
    white-space: nowrap;
}

.toggle-container {
    display: flex;
    align-items: center;
}

/* Вторичные элементы формы */
.secondary-label {
    color: #95a5a6 !important;
    font-weight: 400 !important;
}

.secondary-input {
    border-color: #e0e0e0 !important;
    background-color: #fafafa !important;
}

.secondary-input:focus {
    border-color: #bdc3c7 !important;
    background-color: #ffffff !important;
}

/* Стили для чекбоксов каналов */
.channels-checkbox-container {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 6px;
    background-color: #fafafa;
}

.channel-checkbox-item {
    margin-bottom: 2px;
}

.channel-checkbox-item:last-child {
    margin-bottom: 0;
}

.channel-checkbox-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 3px;
    transition: background-color 0.2s;
    font-size: 13px;
    min-height: 24px;
    width: 100%;
}

.channel-checkbox-label:hover {
    background-color: #e9ecef;
}

.channel-checkbox {
    margin-left: auto !important;
    transform: scale(1.0);
    cursor: pointer;
    width: auto !important;
    flex-shrink: 0;
    margin-right: 0 !important;
}

.channel-checkbox-text {
    color: #2c3e50;
    font-weight: 500;
    user-select: none;
    flex: 1;
}

.channel-checkbox:checked + .channel-checkbox-text {
    color: #3498db;
    font-weight: 600;
}

.channel-checkbox-label:has(.channel-checkbox:checked) {
    background-color: #e3f2fd;
    border: 1px solid #bbdefb;
}

.form-help {
    font-size: 0.8em;
    color: #7f8c8d;
    margin-top: 4px;
    font-style: italic;
}

/* Стили для результатов превью */
.preview-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.preview-item {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
    overflow: visible;
}

.preview-images-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
    padding: 10px;
    overflow: visible;
}

.reference-image-section,
.generated-image-section {
    text-align: center;
    overflow: visible;
}

.reference-image-section h4,
.generated-image-section h4 {
    margin: 0 0 10px 0;
    font-size: 0.9em;
    color: #555;
    font-weight: 500;
}

.reference-image-section h4 {
    color: #e74c3c;
}

.generated-image-section h4 {
    color: #27ae60;
}

.preview-image {
    width: 100%;
    max-width: 300px;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.preview-image.clickable-image {
    cursor: pointer;
}

.preview-image.clickable-image:hover {
    transform: scale(1.8);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    z-index: 9999;
    position: relative;
}

.reference-image {
    border: 2px solid #e74c3c;
}

.generated-image {
    border: 2px solid #27ae60;
}

.similarity-info {
    margin: 15px 0;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.similarity-percentage {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.similarity-label {
    font-weight: 500;
    color: #555;
}

.similarity-value {
    font-weight: bold;
    font-size: 1.1em;
    padding: 4px 8px;
    border-radius: 4px;
}

.similarity-high {
    background: #d4edda;
    color: #155724;
}

.similarity-medium {
    background: #fff3cd;
    color: #856404;
}

.similarity-low {
    background: #f8d7da;
    color: #721c24;
}

.similarity-very-low {
    background: #f5c6cb;
    color: #721c24;
}

.preview-description {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
    cursor: pointer;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    transition: background-color 0.2s;
}

.preview-description:hover {
    background: #e9ecef;
}

.preview-description.expanded {
    background: white;
    border: 1px solid #dee2e6;
}

.preview-prompt {
    font-size: 0.8em;
    color: #999;
    font-style: italic;
    cursor: pointer;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    transition: background-color 0.2s;
}

.preview-prompt:hover {
    background: #e9ecef;
}

.preview-prompt.expanded {
    background: white;
    border: 1px solid #dee2e6;
}

.preview-text-content {
    display: none;
    margin-top: 8px;
    padding: 10px;
    background: white;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    text-align: left;
    font-size: 0.85em;
    line-height: 1.4;
}

.preview-text-content.show {
    display: block;
}

.preview-toggle-icon {
    float: right;
    font-weight: bold;
    color: #6c757d;
}

/* Спиннер загрузки */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 10px;
}

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

.loading {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Секция результатов */
.result-section {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.result-section h4 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 1.1em;
}

.result-content {
    font-size: 0.9em;
    line-height: 1.5;
}

.result-content .metadata-item {
    margin-bottom: 10px;
    padding: 8px;
    background: white;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

.result-content .metadata-label {
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 5px;
}

.result-content .metadata-value {
    color: #555;
}

/* JSON стили */
.json-display {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 15px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 250px;
    overflow-y: auto;
}

/* Стили для модального окна просмотра изображений */
.image-viewer-modal {
    z-index: 2000;
}

.image-viewer-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    margin: 2.5vh auto;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.image-viewer-close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.image-viewer-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

.viewer-image {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.image-viewer-info {
    margin-top: 15px;
    text-align: center;
    color: white;
    max-width: 80%;
}

.viewer-image-title {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 8px;
    color: #3498db;
}

.viewer-image-description {
    font-size: 0.9em;
    line-height: 1.4;
    color: #ecf0f1;
    opacity: 0.9;
}

/* Адаптивность */
@media (max-width: 768px) {
    .container {
        padding: 8px;
    }
    
    .form-group-horizontal {
        flex-direction: column;
        gap: 15px;
    }
    
    .form-field {
        width: 100%;
    }
    
    .header {
        padding: 8px 12px;
        margin-bottom: 10px;
        flex-direction: column;
        gap: 8px;
    }
    
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .header h1 {
        font-size: 1.2em;
    }
    
    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 10px;
    }
    
    .stat-card {
        padding: 8px;
    }
    
    .stat-number {
        font-size: 1.2em;
    }
    
    .stat-label {
        font-size: 0.7em;
    }
    
    .topic-item {
        padding: 8px 12px;
        gap: 8px;
        min-height: 70px;
    }
    
    .topic-preview {
        width: 80px;
        height: 60px;
    }
    
    .topic-metadata-panel {
        display: none;
    }
    
    .topic-actions {
        width: 50px;
        margin-left: 5px;
    }
    
    .topic-item.used .topic-actions {
        width: 90px;
    }
    
    .used-actions .btn {
        min-width: 80px;
        font-size: 11px;
        padding: 5px 6px;
    }
    
    .title-container {
        gap: 2px;
    }
    
    .title-input {
        min-width: 0;
        width: 100%;
    }
    
    .modal-content {
        margin: 5% auto;
        width: 95%;
        padding: 12px;
    }
    
    .preview-images-container {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .preview-image {
        max-width: 250px;
    }
    
    .preview-image.clickable-image:hover {
        transform: scale(1.5);
    }
    
    .image-viewer-content {
        margin: 1vh auto;
        padding: 10px;
    }
    
    .viewer-image {
        max-width: 98vw;
        max-height: 90vh;
    }
    
    .image-viewer-info {
        max-width: 95%;
    }
    
    .viewer-image-title {
        font-size: 1em;
    }
    
    .viewer-image-description {
        font-size: 0.8em;
    }
    
    .channels-checkbox-container {
        max-height: 120px;
        padding: 4px;
    }
    
    .channel-checkbox-label {
        padding: 3px 4px;
        font-size: 12px;
        min-height: 20px;
    }
    
    .channel-checkbox {
        transform: scale(0.9);
    }
}

@media (max-width: 480px) {
    .header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        padding: 10px;
    }
}

/* Стили для кнопок группировки каналов по base_id */
.select-all-container {
    margin-bottom: 6px;
    padding: 6px 8px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
}

.select-all-container:last-of-type {
    margin-bottom: 8px;
}

.select-all-checkbox-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 13px;
    color: #495057;
    font-weight: 500;
    width: 100%;
}

.select-all-checkbox {
    margin-left: 8px;
    width: 16px !important;
    height: 16px;
    cursor: pointer;
}

.select-all-text {
    user-select: none;
}

.select-all-checkbox:indeterminate {
    background-color: #007bff;
    border-color: #007bff;
}

.select-all-checkbox:indeterminate::before {
    content: '';
    display: block;
    width: 8px;
    height: 2px;
    background-color: white;
    margin: 6px auto;
}

/* Стили для блоков изображений в стиле блоков названий */
.metadata-image-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 0;
    font-size: 12px;
    line-height: 1.3;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    position: relative;
    /* Размеры контейнера под пропорцию 16:9 (160x90 = 16:9) */
    width: 160px;
    height: 90px;
    flex-shrink: 0;
    /* Фиксируем размеры для правильной пропорции 16:9 */
    min-width: 160px;
    max-width: 160px;
    min-height: 90px;
    max-height: 90px;
    /* Пропорция 16:9 для современных браузеров */
    aspect-ratio: 16 / 9;
}

.metadata-image-content {
    width: 100%;
    height: 100%;
    position: relative;
    /* Убираем flex, чтобы placeholder занимал всё место */
}

.metadata-image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    font-size: 16px;
    overflow: hidden;
    /* Контейнер уже имеет пропорцию 16:9 (160x90px) */
}

.metadata-image-placeholder img {
    width: 100%;
    height: 100%;
    /* Используем cover чтобы заполнить контейнер 16:9, обрезая края если нужно */
    object-fit: cover;
    object-position: center;
    border-radius: 2px;
    cursor: pointer;
    /* Оптимизация для миниатюр - плавная загрузка */
    transition: opacity 0.2s ease;
    /* Улучшенное качество отображения миниатюр */
    display: block;
}

.metadata-image-item.empty {
    border-color: #e74c3c;
    background: #fdf2f2;
}

.metadata-image-item:hover .metadata-image-actions {
    display: flex !important;
}

.metadata-image-content:hover .metadata-image-actions {
    display: flex !important;
}

.metadata-image-actions {
    display: none;
    gap: 2px;
    flex-shrink: 0;
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
    flex-direction: row;
}

.metadata-image-delete, .metadata-image-replace, .metadata-image-regenerate, .metadata-image-download {
    background: none;
    border: none;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    color: #6c757d;
    transition: all 0.2s;
}

.metadata-image-delete:hover {
    background: #e74c3c;
    color: white;
}

.metadata-image-replace:hover {
    background: #3498db;
    color: white;
}

.metadata-image-regenerate:hover {
    background: #f39c12;
    color: white;
}

.metadata-image-download:hover {
    background: #27ae60;
    color: white;
}

.metadata-image-item:hover {
    background: #e9ecef;
    border-color: #dee2e6;
}

/* Стили для состояния перегенерации */
.metadata-image-container.regenerating {
    border: 2px solid #3498db;
    background: #e3f2fd;
}

.metadata-image-container.regenerating .metadata-image-placeholder {
    background: #e3f2fd;
}

/* Стили для индикаторов статуса перегенерации */
.regeneration-status {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    z-index: 10;
    font-size: 12px;
    text-align: center;
    padding: 8px;
}

.status-message {
    margin-bottom: 8px;
    font-weight: 500;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.regeneration-status.status-regenerating {
    background: rgba(52, 152, 219, 0.9);
}

.regeneration-status.status-completed {
    background: rgba(46, 204, 113, 0.9);
}

.regeneration-status.status-error {
    background: rgba(231, 76, 60, 0.9);
}

.regeneration-status.status-pending {
    background: rgba(241, 196, 15, 0.9);
}