/* style.css */
:root {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --secondary: #f8f9fa;
    --text-dark: #212529;
    --text-light: #6c757d;
    --border: #dee2e6;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
    --user-bubble: #4361ee;
    --assistant-bubble: #f1f3f5;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chat-container {
    width: 100%;
    max-width: 1000px;
    height: 90vh;
    background: white;
    border-radius: 32px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: white;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.chat-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header h1::before {
    content: "🌿";
    font-size: 1.6rem;
}

.chat-header p {
    color: var(--text-light);
    font-size: 0.85rem;
    margin-top: 6px;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #ffffff;
    gap: 8px;                /* уменьшили gap между сообщениями (было 16px) */
}

.message {
    display: flex;
    animation: fadeInUp 0.2s ease-out;
    margin-bottom: 8px;      /* добавили небольшой отступ между сообщениями, вместо gap у родителя */
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.bubble {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 24px;
    line-height: 1.5;
    font-size: 0.95rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.user .bubble {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 6px;
}

.assistant .bubble {
    background: var(--assistant-bubble);
    color: var(--text-dark);
    border-bottom-left-radius: 6px;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 4px;
    margin-left: 12px;
    margin-right: 12px;
}

.input-area {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 12px 20px;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    transition: all 0.2s;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

#sendBtn {
    background: var(--primary);
    border: none;
    border-radius: 40px;
    padding: 0 24px;
    height: 48px;
    color: white;
    font-weight: 500;
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

#sendBtn:hover {
    background: var(--primary-dark);
}

#sendBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 12px 18px;
    background: var(--assistant-bubble);
    border-radius: 24px;
    width: fit-content;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #adb5bd;
    border-radius: 50%;
    animation: pulse 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
    0%, 60%, 100% { transform: scale(0.8); opacity: 0.5; }
    30% { transform: scale(1.2); opacity: 1; }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar */
.messages-area::-webkit-scrollbar {
    width: 6px;
}
.messages-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}
.messages-area::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    border-radius: 32px;
    padding: 24px;
    overflow-y: auto;
    box-shadow: 0 20px 35px -8px rgba(0,0,0,0.2);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-weight: 600;
}

.clinics-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.clinic-card {
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 20px;
    transition: all 0.2s;
}

.clinic-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 20px rgba(0,0,0,0.05);
}

.clinic-card h3 {
    font-size: 1.25rem;
    margin-bottom: 12px;
    color: var(--primary-dark);
}

.clinic-card p {
    margin: 6px 0;
    font-size: 0.9rem;
}

.select-clinic-btn {
    margin-top: 16px;
    background: var(--primary);
    border: none;
    padding: 10px 20px;
    border-radius: 40px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.select-clinic-btn:hover {
    background: var(--primary-dark);
}

.change-clinic-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 40px;
    padding: 8px 16px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.change-clinic-btn:hover {
    background: #f1f3f5;
    border-color: var(--primary);
}

/* Стили для таблиц, сгенерированных AI */
.ai-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.85rem;
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.ai-table thead tr {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.ai-table th {
    padding: 10px 8px;
    font-weight: 600;
    color: #1e293b;
    text-align: left;
    border-bottom: 1px solid #cbd5e1;
}

.ai-table td {
    padding: 8px;
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
}

.ai-table tbody tr:hover {
    background: #f1f5f9;
}

.bubble {
    max-width: 85%;          /* вместо 75% – чуть шире, но не во весь экран */
    padding: 8px 14px;       /* было 12px 18px – уменьшили */
    border-radius: 20px;     /* было 24px – чуть меньше */
    line-height: 1.45;
    font-size: 0.9rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Для сообщений ассистента, чтобы таблицы не вылезали */
.assistant .bubble {
    max-width: 95%;
    overflow-x: auto;
}

.clear-chat-btn {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 40px;
    padding: 8px 16px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.clear-chat-btn:hover {
    background: #dc2626;
}

/* Адаптивность для маленьких экранов – горизонтальный скролл внутри сообщения */
@media (max-width: 640px) {
    .chat-container {
        height: 95vh;
        border-radius: 20px;
    }
    .bubble {
        max-width: 85%;
    }
}