/* ═══════════════════════════════════════════════════════
   MC.ru Catalog Chat — CSS (полная перезапись)
   Принцип: максимальный контраст, читаемость, ничего не обрезается
═══════════════════════════════════════════════════════ */

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

:root {
    /* Сайдбар — тёмный */
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-text: #e2e8f0;
    --sidebar-text-dim: #94a3b8;

    /* Чат — светлый */
    --chat-bg: #f1f5f9;
    --chat-header-bg: #ffffff;

    /* Сообщения */
    --user-msg-bg: #1e40af;
    --user-msg-text: #ffffff;
    --bot-msg-bg: #ffffff;
    --bot-msg-text: #0f172a;
    --bot-msg-border: #cbd5e1;

    /* Акцент */
    --accent: #dc2626;
    --accent-hover: #ef4444;

    /* Таблицы */
    --table-header-bg: #1e293b;
    --table-header-text: #ffffff;
    --table-border: #94a3b8;
    --table-row-alt: #f8fafc;
    --table-row-hover: #e2e8f0;

    /* Code */
    --code-bg: #0f172a;
    --code-text: #93c5fd;

    --radius: 8px;
    --sidebar-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--sidebar-bg);
    height: 100vh;
    overflow: hidden;
}

.app { display: flex; height: 100vh; }

/* ─── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid #334155;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid #334155;
}

.btn-new-chat {
    width: 100%;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.btn-new-chat:hover { background: var(--accent-hover); }

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-chats::-webkit-scrollbar { width: 4px; }
.sidebar-chats::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.chat-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--sidebar-text-dim);
    transition: background 0.15s, color 0.15s;
}

.chat-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.chat-item.active { background: var(--sidebar-hover); color: var(--sidebar-text); }

.chat-item .chat-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item .btn-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity 0.15s;
}

.chat-item:hover .btn-delete { opacity: 0.7; }
.chat-item .btn-delete:hover { opacity: 1; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid #334155;
}

.stats {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--sidebar-text-dim);
}

.stats-value { font-weight: 600; color: var(--accent); }

/* ─── Chat Area ───────────────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    min-width: 0;  /* критично для flex */
}

.chat-header {
    padding: 14px 24px;
    background: var(--chat-header-bg);
    border-bottom: 1px solid var(--bot-msg-border);
}

.chat-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h1 {
    font-size: 17px;
    color: var(--bot-msg-text);
    font-weight: 600;
}

.chat-seq-header {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent);
    font-family: monospace;
    letter-spacing: 1px;
}

.chat-seq {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    font-family: monospace;
    margin-right: 4px;
    flex-shrink: 0;
}

.chat-subtitle { font-size: 13px; color: #64748b; }

/* ─── Messages Container ─────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }

/* ─── Welcome Screen ──────────────────────────────────── */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #64748b;
}

.welcome-icon { margin-bottom: 16px; opacity: 0.3; }

.welcome-screen h2 {
    font-size: 22px;
    color: var(--bot-msg-text);
    margin-bottom: 8px;
    font-weight: 500;
}

.welcome-screen p { font-size: 14px; margin-bottom: 24px; }

.welcome-instructions {
    max-width: 560px;
    text-align: left;
    font-size: 14px;
    line-height: 1.8;
    color: #334155;
}

.welcome-instructions ol {
    padding-left: 20px;
    margin: 12px 0;
}

.welcome-instructions li {
    margin: 10px 0;
}

.welcome-instructions code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
    color: #0f172a;
}

.welcome-instructions em {
    color: #1e40af;
    font-style: normal;
    font-weight: 500;
}

.welcome-hint {
    margin-top: 16px !important;
    font-size: 13px !important;
    color: #64748b;
    font-style: italic;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 500px;
}

.suggestion {
    padding: 8px 16px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    color: var(--bot-msg-text);
    transition: background 0.15s, color 0.15s;
}

.suggestion:hover {
    background: #1e293b;
    color: white;
    border-color: #1e293b;
}

/* ─── Messages ────────────────────────────────────────── */
.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: var(--user-msg-bg);
    color: var(--user-msg-text);
    border-bottom-right-radius: 2px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bot-msg-bg);
    color: var(--bot-msg-text);
    border: 1px solid var(--bot-msg-border);
    border-bottom-left-radius: 2px;
    /* НЕ overflow: hidden — пусть контент дышит */
}

.message-time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 6px;
}

.message.user .message-time { color: rgba(255,255,255,0.6); }

/* ─── Markdown: заголовки ─────────────────────────────── */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
    font-weight: 700;
    margin: 10px 0 6px;
    color: #0f172a;
}
.message.assistant h1 { font-size: 18px; }
.message.assistant h2 { font-size: 16px; }
.message.assistant h3 { font-size: 15px; }
.message.assistant h4 { font-size: 14px; }

/* ─── Markdown: параграфы ─────────────────────────────── */
.message.assistant p { margin: 6px 0; }

/* ─── Markdown: жирный/курсив ──────────────────────────── */
.message.assistant strong { font-weight: 700; color: #0f172a; }
.message.assistant em { font-style: italic; }

/* ─── Markdown: списки ────────────────────────────────── */
.message.assistant ul,
.message.assistant ol {
    margin: 6px 0;
    padding-left: 22px;
}

.message.assistant li { margin: 3px 0; }

/* ─── Markdown: ТАБЛИЦЫ (главное!) ─────────────────────── */
.message.assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
    background: white;
}

.message.assistant thead { background: var(--table-header-bg); }

.message.assistant th {
    border: 1px solid var(--table-header-bg);
    padding: 8px 10px;
    text-align: left;
    font-weight: 700;
    color: var(--table-header-text);
    white-space: nowrap;
}

.message.assistant td {
    border: 1px solid var(--table-border);
    padding: 6px 10px;
    text-align: left;
    color: var(--bot-msg-text);
    word-break: break-word;
    overflow-wrap: break-word;
}

.message.assistant tr:nth-child(even) td { background: var(--table-row-alt); }
.message.assistant tr:hover td { background: var(--table-row-hover); }

/* ─── Markdown: code ──────────────────────────────────── */
.message.assistant code {
    background: #e2e8f0;
    color: #0f172a;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'SF Mono', Consolas, 'Liberation Mono', monospace;
}

.message.assistant pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    overflow-x: auto;
    margin: 8px 0;
    line-height: 1.5;
}

.message.assistant pre code {
    background: none;
    color: inherit;
    padding: 0;
}

/* ─── Markdown: прочее ────────────────────────────────── */
.message.assistant hr {
    border: none;
    border-top: 2px solid #e2e8f0;
    margin: 12px 0;
}

.message.assistant blockquote {
    border-left: 4px solid #1e40af;
    padding: 4px 12px;
    margin: 6px 0;
    background: #f1f5f9;
    color: #475569;
    border-radius: 0 4px 4px 0;
}

.message.assistant a {
    color: #1e40af;
    text-decoration: underline;
}

/* ─── Progress indicator ──────────────────────────────── */
.progress-indicator {
    border: 1px dashed #94a3b8 !important;
    background: #f8fafc !important;
    padding: 14px 18px !important;
}

.progress-step {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.progress-action {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
}

.progress-detail {
    font-size: 13px;
    color: #64748b;
}

.progress-next {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 2px;
}

/* Анимация — пульсирующая точка */
.progress-action::before {
    content: '●';
    display: inline-block;
    margin-right: 6px;
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Loading dot в сайдбаре */
.loading-dot {
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
    margin-right: 6px;
    font-size: 10px;
}

.chat-item.loading .chat-title {
    color: var(--accent);
    font-style: italic;
}

/* ─── Input Area ──────────────────────────────────────── */
.chat-input-area {
    padding: 16px 24px;
    background: var(--chat-header-bg);
    border-top: 1px solid var(--bot-msg-border);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: white;
    border: 2px solid #cbd5e1;
    border-radius: var(--radius);
    padding: 8px;
    transition: border-color 0.15s;
}

.chat-input-wrapper:focus-within {
    border-color: #1e40af;
    box-shadow: 0 0 0 3px rgba(30,64,175,0.1);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    padding: 8px 4px;
    max-height: 120px;
    line-height: 1.4;
    color: var(--bot-msg-text);
    background: white;
}

.btn-attach, .btn-send {
    background: none;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-attach { color: #64748b; }
.btn-attach:hover { background: #f1f5f9; color: #0f172a; }
.btn-send { color: var(--accent); }
.btn-send:hover { background: rgba(220,38,38,0.1); }

/* ─── File indicator (прикреплённый файл) ─────────────── */
.file-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #e2e8f0;
    border-radius: 4px;
    font-size: 12px;
    color: #475569;
    margin-right: 4px;
}

.file-indicator .file-name { font-weight: 500; }
.file-indicator .btn-remove-file {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--accent);
    padding: 0;
    font-size: 14px;
}

/* ─── Action buttons (над полем ввода) ────────────────── */
.action-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.action-buttons:empty { display: none; }

.action-btn {
    padding: 8px 16px;
    border: 2px solid #1e40af;
    background: white;
    color: #1e40af;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.action-btn:hover {
    background: #1e40af;
    color: white;
}

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { position: absolute; z-index: 100; height: 100%; transform: translateX(-100%); transition: transform 0.2s; }
    .sidebar.open { transform: translateX(0); }
    .chat-area { width: 100%; }
    .message { max-width: 95%; }
}