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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

/* Header */
header {
    background: #2c3e50;
    color: white;
    padding: 25px;
    text-align: center;
}

header h1 {
    margin-bottom: 10px;
    font-size: 2.2em;
    font-weight: 600;
}

header p {
    font-size: 1.1em;
    opacity: 0.9;
}

/* Главная страница с чатами */
.chats-container {
    padding: 30px;
    min-height: 400px;
}

.new-chat-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px dashed #3498db;
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 30px;
    text-align: center;
    transition: all 0.3s ease;
}

.new-chat-card:hover {
    border-color: #2980b9;
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.2);
}

.new-chat-card h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.new-chat-form {
    display: flex;
    gap: 12px;
    margin-top: 15px;
    align-items: center;
}

.new-chat-form input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

.new-chat-form input:focus {
    border-color: #3498db;
}

.new-chat-form button {
    padding: 14px 30px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: background 0.3s;
    white-space: nowrap;
}

.new-chat-form button:hover {
    background: #2980b9;
}

.new-chat-form button:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

/* Список чатов */
.chats-list {
    display: grid;
    gap: 20px;
}

.chat-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.chat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #3498db;
    opacity: 0;
    transition: opacity 0.3s;
}

.chat-card:hover {
    border-color: #3498db;
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.15);
    transform: translateY(-2px);
}

.chat-card:hover::before {
    opacity: 1;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.chat-header h4 {
    margin: 0;
    color: #2c3e50;
    flex: 1;
    font-size: 1.1em;
    font-weight: 600;
    line-height: 1.4;
}

.message-count {
    background: #ecf0f1;
    color: #7f8c8d;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.chat-date {
    color: #95a5a6;
    font-size: 13px;
    font-weight: 500;
}

.no-chats {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.no-chats p {
    margin: 10px 0;
    font-size: 1.1em;
}

/* Настройки скорости */
.speed-controls {
    padding: 25px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

.speed-controls h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 1.2em;
    text-align: center;
}

.speed-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.speed-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    background: #3498db;
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    white-space: nowrap;
}

.speed-buttons button:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.speed-buttons span {
    color: #2c3e50;
    font-weight: 600;
    margin-left: 10px;
}

#current-speed {
    color: #e74c3c;
    font-weight: 700;
}

/* Страница чата */
.chat-header-page {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    background: #2c3e50;
    color: white;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.back-button {
    color: white;
    text-decoration: none;
    padding: 8px 15px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    transition: all 0.3s;
    font-size: 14px;
    font-weight: 500;
}

.back-button:hover {
    background: rgba(255,255,255,0.1);
    transform: translateX(-2px);
}

.header-left h1 {
    margin: 0;
    font-size: 1.4em;
    font-weight: 600;
}

.delete-chat {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
}

.delete-chat:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

/* Контейнер чата */
.chat-container {
    height: 65vh;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: #f8f9fa;
}

.message {
    margin-bottom: 20px;
    display: flex;
    animation: messageAppear 0.3s ease-out;
}

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

.bot-message {
    justify-content: flex-start;
}

.message-content {
    max-width: 85%;
    padding: 16px 22px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.user-message .message-content {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border-bottom-right-radius: 5px;
}

.bot-message .message-content {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 5px;
}

/* Стили для Markdown */
.bot-message .message-content h1,
.bot-message .message-content h2,
.bot-message .message-content h3 {
    margin: 15px 0 10px 0;
    color: #2c3e50;
}

.bot-message .message-content h1 {
    font-size: 1.4em;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
}

.bot-message .message-content h2 {
    font-size: 1.2em;
}

.bot-message .message-content h3 {
    font-size: 1.1em;
}

.bot-message .message-content p {
    margin: 12px 0;
}

.bot-message .message-content ul,
.bot-message .message-content ol {
    margin: 12px 0;
    padding-left: 25px;
}

.bot-message .message-content li {
    margin: 6px 0;
}

.bot-message .message-content code {
    background: #f4f4f4;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    border: 1px solid #ddd;
}

.bot-message .message-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 18px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 15px 0;
    border: 1px solid #444;
}

.bot-message .message-content pre code {
    background: none;
    padding: 0;
    border: none;
    color: inherit;
    font-size: 0.9em;
}

.bot-message .message-content blockquote {
    border-left: 4px solid #3498db;
    padding-left: 18px;
    margin: 15px 0;
    color: #555;
    font-style: italic;
    background: #f8f9fa;
    padding: 12px 20px;
    border-radius: 0 8px 8px 0;
}

.bot-message .message-content strong {
    font-weight: bold;
    color: #2c3e50;
}

.bot-message .message-content em {
    font-style: italic;
}

.bot-message .message-content a {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
}

.bot-message .message-content a:hover {
    text-decoration: underline;
}

/* Область ввода */
.input-area {
    padding: 20px 25px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.typing-indicator {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    color: #666;
    font-size: 0.9em;
    font-weight: 500;
}

.typing-dots {
    display: flex;
    margin-right: 12px;
}

.typing-dots span {
    height: 8px;
    width: 8px;
    margin: 0 3px;
    background: #666;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.chat-form {
    display: flex;
    gap: 12px;
}

#user-input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

#user-input:focus {
    border-color: #007bff;
}

.chat-form button {
    padding: 14px 28px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: background 0.3s;
    white-space: nowrap;
}

.chat-form button:hover {
    background: #0056b3;
}

.chat-form button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* Анимации */
@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Полосы прокрутки */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Сообщения об ошибках */
.error {
    color: #e74c3c;
    text-align: center;
    padding: 20px;
    background: #fdf2f2;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    margin: 10px 0;
}

/* Адаптивность */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        border-radius: 10px;
    }
    
    .chats-container {
        padding: 20px;
    }
    
    .new-chat-form {
        flex-direction: column;
    }
    
    .new-chat-form button {
        width: 100%;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .message-count {
        align-self: flex-start;
    }
    
    .speed-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .speed-buttons span {
        margin-left: 0;
        margin-top: 10px;
    }
    
    .chat-header-page {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }
    
    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .message-content {
        max-width: 95%;
    }
    
    .chat-form {
        flex-direction: column;
    }
    
    .chat-form button {
        width: 100%;
    }
}