/* style.css */
* {
    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, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 800px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    padding: 20px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-shrink: 0;
}

header h1 {
    font-size: 24px;
    font-weight: 700;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 5px;
}

.status {
    margin-top: 10px;
    font-size: 13px;
    background: rgba(255,255,255,0.2);
    padding: 5px 12px;
    border-radius: 20px;
    display: inline-block;
}

.ssl-warning {
    display: none;
    background: #ff6b6b;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 13px;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 30px;
    background: #f8f9fa;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.message.user .avatar {
    background: #667eea;
}

.bubble {
    position: relative;
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    background: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    line-height: 1.6;
    word-wrap: break-word;
}

span.timestamp {
    position: absolute;
    left: 0;
    top: -21px;
    font-size: 12px;
    color: grey;
}

.message.user .bubble {
    background: #667eea;
    color: white;
}

.bubble .translation {
    margin-top: 8px;
    font-size: 13px;
    color: #6c757d;
    border-top: 1px solid #e9ecef;
    padding-top: 8px;
}

.message.user .bubble .translation {
    color: rgba(255,255,255,0.8);
    border-top-color: rgba(255,255,255,0.2);
}

/* Контролы */
.controls {
    padding: 20px 30px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.controls .top-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.text-input-group {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 200px;
}

.text-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
    min-width: 100px;
}

.text-input:focus {
    border-color: #667eea;
}

.text-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.mic-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.mic-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.mic-btn:active {
    transform: scale(0.95);
}

.mic-btn.recording {
    background: linear-gradient(135deg, #dc3545 0%, #c0392b 100%);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.mic-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.mic-icon {
    font-size: 20px;
}

.clear-btn, .speak-btn {
    padding: 12px 20px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    color: #495057;
    white-space: nowrap;
}

.clear-btn:hover, .speak-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
}

.clear-btn:active, .speak-btn:active {
    transform: scale(0.95);
}

.clear-btn:disabled, .speak-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.debug-info {
    padding: 10px 30px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    font-size: 12px;
    color: #6c757d;
    flex-shrink: 0;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

/* Scrollbar */
.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        height: 100vh;
        border-radius: 0;
    }
    
    .message .bubble {
        max-width: 85%;
    }
    
    .controls {
        padding: 15px;
    }
    
    .controls .top-row {
        flex-direction: column;
    }
    
    .text-input-group {
        width: 100%;
    }
    
    .mic-btn, .send-btn, .clear-btn, .speak-btn {
        width: 100%;
        justify-content: center;
    }
    
    .debug-info {
        flex-direction: column;
        gap: 5px;
        padding: 10px 15px;
    }
}

/* ===== КНОПКА ТЕСТА ===== */
.test-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.test-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(245, 87, 108, 0.4);
}

.test-btn:active {
    transform: scale(0.95);
}

/* ===== МОДАЛЬНОЕ ОКНО ТЕСТА ===== */
.test-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    animation: modalFadeIn 0.3s ease;
}

.test-modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.test-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.test-modal-content {
    position: relative;
    width: 95%;
    max-width: 1000px;
    height: 90vh;
    max-height: 900px;
    background: var(--bg-secondary, #1a1a2e);
    border-radius: 16px;
    border: 1px solid var(--border-color, #2d2d44);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.test-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-tertiary, #16213e);
    border-bottom: 1px solid var(--border-color, #2d2d44);
    flex-shrink: 0;
}

.test-modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #e6edf3);
}

.test-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary, #8b949e);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.3s;
    line-height: 1;
}

.test-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #e6edf3);
}

.test-modal-body {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.test-modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg-primary, #0d1117);
}

/* ===== АНИМАЦИЯ МОДАЛЬНОГО ОКНА ===== */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    .test-modal-content {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .test-modal-header {
        padding: 12px 16px;
    }
    
    .test-modal-header h2 {
        font-size: 16px;
    }
    
    .test-btn {
        padding: 10px 16px;
        font-size: 13px;
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .controls {
        flex-wrap: wrap;
    }
    
    .test-btn {
        flex: 1;
        min-width: 100px;
    }
}

/* ===== СТИЛИ ДЛЯ ТЕСТА В ЧАТЕ ===== */
.test-audio-btn {
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.test-audio-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.test-answer-btn {
    padding: 10px 24px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    margin: 4px;
}

.test-answer-btn:hover {
    transform: scale(1.05);
}

.test-yes:hover {
    border-color: var(--success);
    background: rgba(63, 185, 80, 0.2);
}

.test-no:hover {
    border-color: var(--danger);
    background: rgba(248, 81, 73, 0.2);
}

.test-matching-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.test-matching-btn {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.test-matching-btn:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
    transform: scale(1.1);
}

.test-skip-btn,
.test-restart-btn,
.test-exit-btn,
.test-select-btn,
.test-close-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s;
    margin: 4px;
}

.test-skip-btn:hover,
.test-restart-btn:hover,
.test-select-btn:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.test-exit-btn:hover,
.test-close-btn:hover {
    border-color: var(--danger);
    background: rgba(248, 81, 73, 0.2);
}

.test-restart-btn {
    border-color: var(--success);
    color: var(--success);
}

.test-select-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin: 6px 0;
    text-align: center;
}

.bubble br {
    display: none;
}

/* ===== КНОПКИ ВЫБОРА ТЕСТА ===== */
.test-select-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 18px;
    margin: 8px 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    position: relative;
    overflow: hidden;
}

.test-select-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.5);
    background: linear-gradient(135deg, #7a8ef0 0%, #8a5cb8 100%);
}

.test-select-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

/* Лёгкий блик при наведении */
.test-select-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
    transition: left 0.5s ease;
}

.test-select-btn:hover::after {
    left: 100%;
}

/* ===== СЕТКА КАРТИНОК ДЛЯ MATCHING ===== */
.matching-images-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 12px 0;
    padding: 12px;
    background: var(--bg-primary, #0d1117);
    border-radius: 12px;
    border: 1px solid var(--border-color, #30363d);
}

.matching-image-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    background: var(--bg-tertiary, #1c2333);
    border-radius: 8px;
    border: 1px solid var(--border-color, #30363d);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.matching-image-item:hover {
    transform: translateY(-2px);
    border-color: var(--accent, #58a6ff);
}

.matching-image-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    background: #fff;
}

.matching-image-letter {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent, #58a6ff);
    background: var(--bg-primary, #0d1117);
    padding: 2px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color, #30363d);
}

/* Адаптив для мобильных */
@media (max-width: 600px) {
    .matching-images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .matching-image-item img {
        height: 90px;
    }
}

/* Метка раздела в меню тестов */
.test-section-label {
    font-size: 13px;
    color: var(--text-secondary, #8b949e);
    margin: 12px 0 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Кнопки ИИ-генерации */
.test-ai-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
    border-left-color: #f5576c !important;
}

.test-ai-btn:hover {
    background: linear-gradient(135deg, #f5a3ff 0%, #ff6b7d 100%) !important;
}

/* ===== ШАПКА С ДЕЙСТВИЯМИ ===== */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

.header-title {
    flex: 1;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.header-title .subtitle {
    font-size: 13px;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.header-actions .clear-btn,
.header-actions .speak-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.header-actions .clear-btn:hover,
.header-actions .speak-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.header-actions .clear-btn:active,
.header-actions .speak-btn:active {
    transform: scale(0.95);
}

/* ===== АДАПТИВ ===== */
@media (max-width: 600px) {
    .header-top {
        flex-direction: column;
        align-items: stretch;
    }
    
    .header-actions {
        justify-content: flex-end;
    }
    
    .header-title h1 {
        font-size: 18px;
    }
}