:root {
    --sidebar-bg: #ffffff; --sidebar-hover: #f1f3f5; --sidebar-border: #e0e6ed; --sidebar-text: #495057;
    --sidebar-header-text: #212529; --sidebar-active-bg: #e7f1ff; --sidebar-active-text: #0d6efd;
    --profile-bg: #f8f9fa; --chat-bg: #f4f5f7; --panel-bg: #ffffff; --border-color: #e0e6ed;
    --msg-ai-bg: #ffffff; --msg-user-bg: #e3f2fd; --msg-user-border: #bbdefb; --msg-user-text: #0d47a1;
    --text-main: #313435;
}
[data-bs-theme="dark"] {
    --sidebar-bg: #1d2531; --sidebar-hover: #28313f; --sidebar-border: rgba(255,255,255,0.05); --sidebar-text: #8a909d;
    --sidebar-header-text: #ffffff; --sidebar-active-bg: #2196f3; --sidebar-active-text: #ffffff;
    --profile-bg: rgba(0,0,0,0.2); --chat-bg: #121212; --panel-bg: #1e1e1e; --border-color: #2d3238;
    --msg-ai-bg: #252b32; --msg-user-bg: #0d2c4a; --msg-user-border: #154370; --msg-user-text: #e3f2fd;
    --text-main: #e0e0e0;
}

body { background-color: var(--chat-bg); color: var(--text-main); height: 100dvh; overflow: hidden; display: flex; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; transition: background-color 0.3s, color 0.3s; }

.sidebar-desktop { width: 260px; min-width: 260px; flex-shrink: 0; background-color: var(--sidebar-bg); color: var(--sidebar-text); border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column; height: 100dvh; z-index: 10; transition: background-color 0.3s, border-color 0.3s; }
.sidebar-header { padding: 15px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 1.2rem; font-weight: bold; color: var(--sidebar-header-text); border-bottom: 1px solid var(--sidebar-border); letter-spacing: normal; }
.sidebar-nav { display: flex; justify-content: space-around; padding: 10px; border-bottom: 1px solid var(--sidebar-border); background-color: var(--profile-bg); }
.sidebar-nav a { color: var(--sidebar-text); font-size: 1.2rem; padding: 6px 16px; border-radius: 8px; transition: 0.2s; text-decoration: none; display: block;}
.sidebar-nav a:hover { background-color: var(--sidebar-hover); color: var(--sidebar-header-text); }
.sidebar-nav a.active { background-color: var(--sidebar-active-bg); color: var(--sidebar-active-text); }

.chat-list { flex-grow: 1; overflow-y: auto; overflow-x: hidden; padding-top: 10px; }
.chat-item { cursor: pointer; padding: 8px 12px; border-radius: 4px; margin: 2px 10px; transition: all 0.2s; display: flex; justify-content: space-between; align-items: center; color: var(--sidebar-text); font-size: 0.9rem; }
.chat-item:hover { background-color: var(--sidebar-hover); color: var(--sidebar-header-text); }
.chat-item.active { background-color: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 500; }
.chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-grow: 1; margin-right: 10px; }

.profile-block { padding: 12px; border-top: 1px solid var(--sidebar-border); background-color: var(--profile-bg); transition: background-color 0.3s; }
.profile-stats { font-size: 0.75rem; color: var(--sidebar-text); margin-top: 4px; }

.theme-toggle-btn { background: none; border: none; color: inherit; cursor: pointer; padding: 0 5px; opacity: 0.7; transition: 0.2s; }
.theme-toggle-btn:hover { opacity: 1; }
.offcanvas { background-color: var(--sidebar-bg) !important; color: var(--sidebar-text) !important; border-right: 1px solid var(--sidebar-border); }
.offcanvas-header { border-bottom: 1px solid var(--sidebar-border); }
.offcanvas-title { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 1.2rem; font-weight: bold; color: var(--sidebar-header-text); letter-spacing: normal; }
.modal-content { background-color: var(--panel-bg); color: var(--text-main); border-color: var(--border-color); }

/* Force dropdowns and menus to follow theme (fix for browsers that render white backgrounds)
   Use variables defined above and increase specificity to override Bootstrap / UA styles. */
:root { color-scheme: light dark; }
.dropdown-menu,
.dropdown-menu.show,
.dropdown-menu .dropdown-item,
.btn-group .dropdown-menu,
.dropdown-menu .form-select,
.dropdown-menu .form-control,
.dropdown,
.dropdown-menu .dropdown-header {
    background-color: var(--panel-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    box-shadow: 0 .25rem .5rem rgba(0,0,0,0.08);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    forced-color-adjust: none;
}

.dropdown-item {
    color: var(--text-main) !important;
}

.dropdown-item:focus,
.dropdown-item:active,
.dropdown-item:hover {
    background-color: rgba(0,0,0,0.06) !important;
}

/* Native selects inside dropdowns (best-effort) */
.dropdown-menu select,
select.form-select {
    background-color: var(--panel-bg) !important;
    color: var(--text-main) !important;
}

/* Prevent white flash when opening */
.dropdown-toggle::after { color: inherit; }

[data-bs-theme="dark"] .dropdown-item:focus,
[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:active {
    background-color: rgba(255,255,255,0.06) !important;
}

/* Tariff card adjustments: reduced spacing and scaled "Выберите тариф" font */
.tariff-card { padding: 16px; }
.tariff-title { margin-bottom: 0.25rem; font-size: 1.05rem; }
.tariff-amount { margin-bottom: 0.5rem; font-size: 1.25rem; }

/* Reduce size of 'Выберите тариф' label where used (20% smaller) */
label.small.fw-bold.text-primary { font-size: 0.8rem; }

/* Make same compact spacing for mobile */
@media (max-width: 768px) {
    .tariff-card { padding: 12px; }
    .tariff-title { font-size: 1rem; }
    .tariff-amount { font-size: 1.125rem; }
    label.small.fw-bold.text-primary { font-size: 0.8rem; margin-bottom: 0.25rem; }
}

.modal-header { border-bottom-color: var(--border-color); }
.modal-footer { border-top-color: var(--border-color); }

/* Стили для форматирования Markdown */
.msg-bubble p { margin-bottom: 0.8rem; }
.msg-bubble p:last-child { margin-bottom: 0; }

/* Инлайн код (однострочный) */
.msg-bubble code:not(.hljs) {
    font-family: Consolas, Monaco, monospace;
    background: rgba(128, 128, 128, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    color: #d63384;
    font-size: 0.9em;
}
[data-bs-theme="dark"] .msg-bubble code:not(.hljs) { color: #ff79c6; }

.sidebar-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; margin-right: 5px; border: 1px solid var(--border-color); }

/* Блоки кода */
.code-container {
    margin: 12px 0;
    border-radius: 8px;
    background: #282c34; /* Темный фон всегда для кода */
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.2);
}
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #1c1e22;
    color: #abb2bf;
    font-size: 0.75rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border-bottom: 1px solid #000;
}
.copy-code-btn {
    background: transparent;
    border: none;
    color: #abb2bf;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 6px;
    border-radius: 4px;
}
.copy-code-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.code-container pre {
    margin: 0;
    padding: 12px;
    max-height: 350px; /* Ограничение высоты кода */
    overflow-y: auto;
}
.code-container pre::-webkit-scrollbar { width: 8px; height: 8px; }
.code-container pre::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.2); border-radius: 4px; }
.code-container code {
    font-family: Consolas, Monaco, monospace;
    font-size: 0.85rem;
    background: transparent !important;
    padding: 0;
    color: #abb2bf;
}

/* Таблицы */
.msg-bubble table {
    width: 100%;
    margin: 1rem 0;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.msg-bubble th, .msg-bubble td {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
}
.msg-bubble th { background-color: rgba(0,0,0,0.03); font-weight: bold; }
[data-bs-theme="dark"] .msg-bubble th { background-color: rgba(255,255,255,0.05); }