/* ============================================================
   style.css — Стили для Travel MCP Demo
   Светлая тема, интерфейс на русском
   ============================================================ */

/* --- Сброс и базовые стили --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-main: #f0f2f5;
    --bg-chat: #ffffff;
    --bg-logs: #ffffff;
    --bg-user-msg: #0084ff;
    --bg-bot-msg: #f0f0f0;
    --bg-system: #e8e8e8;
    --bg-request: #e6f9e6;
    --bg-response: #fff3e0;
    --bg-error: #ffe0e0;
    --text-main: #1a1a1a;
    --text-secondary: #666;
    --border: #ddd;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height для мобильных */
    overflow: hidden;
}

/* --- Основной layout --- */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    gap: 0;
}

/* --- ЧАТ-ПАНЕЛЬ (30%) --- */
.chat-panel {
    width: 30%;
    min-width: 320px;
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
    min-height: 0; /* Важно для flex-скролла */
}

.chat-header {
    padding: 16px 20px;
    background: #fff;
    border-bottom: 2px solid var(--border);
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* --- Контейнер сообщений --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 0; /* Критично для скролла внутри flex */
}

/* --- Отдельное сообщение --- */
.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    animation: fadeIn 0.2s ease;
}

/* Сообщение пользователя (справа) */
.message.user {
    align-self: flex-end;
    background: var(--bg-user-msg);
    color: #fff;
    border-bottom-right-radius: 2px;
    white-space: pre-wrap;
}

/* Сообщение бота (слева) */
.message.bot {
    align-self: flex-start;
    background: var(--bg-bot-msg);
    color: var(--text-main);
    border-bottom-left-radius: 2px;
    /* Без pre-wrap — renderMarkdown() генерирует HTML */
}

/* Параграфы и заголовки внутри сообщения бота */
.message.bot p {
    margin: 4px 0;
}

.message.bot h3, .message.bot h4 {
    margin: 8px 0 4px 0;
    font-size: 15px;
}

.message.bot a {
    color: #0066cc;
    text-decoration: underline;
}

.message.bot br + br {
    display: block;
    margin-top: 4px;
}

/* Таблицы в сообщениях */
.message.bot table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13px;
}

.message.bot th,
.message.bot td {
    border: 1px solid #ccc;
    padding: 6px 8px;
    text-align: left;
    white-space: nowrap;
}

.message.bot th {
    background: #e0e0e0;
    font-weight: 600;
}

.message.bot tr:nth-child(even) {
    background: #f5f5f5;
}

/* Контейнер с горизонтальным скроллом для таблиц */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 8px 0;
}

/* Изображения отелей и маршрутов */
.message.bot img {
    display: block;
    max-width: 100%;
    max-height: 400px;
    object-fit: cover;
    border-radius: 8px;
    margin: 8px auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Приветственное сообщение */
.message.welcome {
    align-self: flex-start;
    background: #e7f5ff;
    border: 1px solid #b3d7ff;
    color: var(--text-main);
}

/* Индикатор "Думаю..." */
.message.thinking {
    align-self: flex-start;
    background: transparent;
    color: var(--text-secondary);
    font-style: italic;
}

.thinking-dots {
    display: inline-block;
    animation: blink 1.4s infinite;
}

.thinking-dots:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots:nth-child(3) { animation-delay: 0.4s; }

/* --- Область ввода --- */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #fff;
}

#chatInput {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#chatInput:focus {
    border-color: var(--bg-user-msg);
}

#sendBtn {
    padding: 10px 18px;
    background: var(--bg-user-msg);
    color: #fff;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
    white-space: nowrap;
}

#sendBtn:hover {
    background: #0066cc;
}

#sendBtn:disabled {
    background: #aaa;
    cursor: not-allowed;
}

/* --- ПАНЕЛЬ ЛОГОВ (70%) --- */
.logs-panel {
    width: 70%;
    background: var(--bg-logs);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.logs-header {
    padding: 16px 20px;
    background: #fff;
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logs-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.clear-btn {
    padding: 6px 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.clear-btn:hover {
    background: #f5f5f5;
    border-color: #999;
}

/* --- Контейнер логов --- */
.logs-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    min-height: 0;
}

/* --- Отдельная запись лога --- */
.log-entry {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    border-left: 4px solid transparent;
    animation: slideIn 0.2s ease;
    font-family: "SF Mono", Monaco, "Cascadia Code", "Courier New", monospace;
}

/* Цветовая маркировка логов */
.log-entry.request {
    background: var(--bg-request);
    border-left-color: #4caf50;
}

.log-entry.response {
    background: var(--bg-response);
    border-left-color: #ff9800;
}

.log-entry.error {
    background: var(--bg-error);
    border-left-color: #f44336;
}

.log-entry.system {
    background: var(--bg-system);
    border-left-color: #999;
}

.log-entry .log-icon {
    margin-right: 6px;
}

.log-entry .log-time {
    color: var(--text-secondary);
    font-size: 11px;
    margin-left: 8px;
}

.log-entry .log-message {
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- JSON-блок внутри лога --- */
.log-data {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 4px;
    padding: 8px 10px;
    margin-top: 6px;
    font-size: 12px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    font-family: "SF Mono", Monaco, "Cascadia Code", "Courier New", monospace;
    color: #333;
}

/* --- Скроллбары --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateX(12px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; }
    40%           { opacity: 1; }
}

/* ============================================================
   MOBILE ADAPTIVE (для экранов < 768px)
   ============================================================ */
@media (max-width: 767px) {
    /* Вертикальный layout на мобильных */
    .app {
        flex-direction: column;
        height: 100dvh;
    }

    /* Чат занимает 55% высоты, логи 45% */
    .chat-panel {
        width: 100%;
        height: 55%;
        min-height: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .logs-panel {
        width: 100%;
        height: 45%;
        min-height: 0;
    }

    .chat-header, .logs-header {
        padding: 10px 14px;
        flex-shrink: 0; /* Не сжимать заголовок */
    }

    .chat-header h2, .logs-header h2 {
        font-size: 15px;
    }

    .chat-messages {
        padding: 10px;
        gap: 8px;
    }

    .message {
        max-width: 92%;
        font-size: 14px;
        padding: 8px 12px;
    }

    .message.bot table {
        font-size: 11px;
    }

    .message.bot th,
    .message.bot td {
        padding: 4px 6px;
    }

    .chat-input-area {
        padding: 8px 10px;
        flex-shrink: 0; /* Не сжимать поле ввода */
    }

    #chatInput {
        padding: 10px 14px;
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 40px;
    }

    #sendBtn {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 40px;
    }

    .log-entry {
        padding: 6px 10px;
        font-size: 12px;
    }

    .log-data {
        font-size: 11px;
        padding: 5px 8px;
        max-height: 120px;
    }

    .clear-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}
