/* ===== Нормализация ===== */
*, *::before, *::after {
    box-sizing: border-box;
}

/* ===== Утилиты ===== */
.is-hidden {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1a1a1a;
    background-color: #f5f5f5;
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== Контейнер ===== */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ===== Шапка ===== */
.header {
    background-color: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.header__logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1a1a1a;
}

.header__logo:hover {
    text-decoration: none;
    color: #2563eb;
}

.header__nav {
    display: flex;
    gap: 16px;
}

.header__link {
    font-size: 0.9rem;
    color: #4b5563;
}

.header__link:hover {
    color: #2563eb;
}

/* ===== Основная область ===== */
.main {
    flex: 1;
    padding: 24px 0;
}

/* ===== Футер ===== */
.footer {
    background-color: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 16px 0;
}

.footer__inner {
    text-align: center;
}

.footer__text {
    margin: 0;
    font-size: 0.85rem;
    color: #9ca3af;
}

/* ===== Чат: страница ===== */
.chat-page {
    display: flex;
    justify-content: center;
}

.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 720px;
    height: calc(100vh - 56px - 24px - 24px - 53px - 32px);
    min-height: 400px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
}

/* ===== История сообщений ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: message-in 0.2s ease-out;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message--system {
    align-self: center;
    max-width: 100%;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 0.9rem;
    text-align: center;
}

.chat-message--user {
    align-self: flex-end;
    background: #2563eb;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-message--bot {
    align-self: flex-start;
    background: #f3f4f6;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}

.chat-message__text {
    white-space: pre-wrap;
}

@media (max-width: 640px) {
    .container {
        padding: 0 12px;
    }

    .header__logo {
        font-size: 1.1rem;
    }

    .main {
        padding: 16px 0;
    }
}
/* ===== Индикатор печати ===== */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: #9ca3af;
}

.chat-typing__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.chat-typing__dot:nth-child(1) { animation-delay: 0s; }
.chat-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.4s; }

.chat-typing__text {
    margin-left: 4px;
}

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ===== Ошибки ===== */
.chat-error {
    margin: 0 16px 8px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 0.9rem;
}

/* ===== Выбор режима ===== */
.chat-mode {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.chat-mode__label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: #4b5563;
    cursor: pointer;
}

.chat-mode__label input[type="radio"] {
    margin: 0;
    accent-color: #2563eb;
}

.chat-clear-btn {
    margin-left: auto;
    align-self: center;
    padding: 5px 14px;
    font-size: 0.85rem;
    font-family: inherit;
    color: #6b7280;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.chat-clear-btn:hover {
    color: #b91c1c;
    border-color: #fca5a5;
    background: #fef2f2;
}

.chat-clear-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* ===== Поле ввода ===== */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.chat-input:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
}

.chat-send-btn {
    align-self: flex-end;
    padding: 10px 20px;
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.chat-send-btn:hover {
    background: #1d4ed8;
}

.chat-send-btn:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.chat-send-btn.is-loading {
    position: relative;
    color: transparent;
    background: #1d4ed8;
}

.chat-send-btn.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: btn-spin 0.8s linear infinite;
}

@keyframes btn-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Адаптив (чат) ===== */
@media (max-width: 640px) {
    .chat-container {
        height: calc(100vh - 56px - 16px - 16px - 53px - 32px);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .chat-message {
        max-width: 92%;
    }

    .chat-input-area {
        flex-direction: column;
    }

    .chat-send-btn {
        align-self: stretch;
    }
}

/* Markdown-таблицы в ответах чата (Block G) */
.chat-render-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
    border-radius: 6px;
    padding: 6px 12px;
    margin-bottom: 10px;
    font-size: 0.85em;
}

.chat-message__text {
    overflow-x: auto;
}

.chat-message__text table {
    border-collapse: collapse;
    margin: 0.5em 0;
    min-width: 40%;
    max-width: 100%;
    font-size: 0.92em;
}

.chat-message__text th,
.chat-message__text td {
    border: 1px solid #cbd5e1;
    padding: 4px 10px;
    text-align: left;
    vertical-align: top;
}

.chat-message__text th {
    background: #f1f5f9;
    font-weight: 600;
}

.chat-message__text code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}
