/* Интерактивный помощник и раздел «База знаний» (задача №107769). */

/* ==================================================================
   Кнопка-персонаж помощника
   ================================================================== */
.assistant {
    position: fixed;
    right: 16px;
    bottom: 84px;           /* над плавающей кнопкой чата */
    z-index: 1031;
    display: flex;
    align-items: center;
    flex-direction: row-reverse;
    gap: 8px;
}

.assistant-fab {
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    box-shadow: 0 8px 22px rgba(79, 70, 229, .45);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: assistantBob 3.2s ease-in-out infinite;
}
.assistant-fab:active { transform: scale(.94); }
/* Красный счётчик непрочитанных ответов поддержки на помогайке (№183237) */
.assistant-fab { position: relative; }
.assistant-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background-color: #DC4C64; /* как счётчик непрочитанных в чате */
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px #fff;
    animation: assistantBadgePulse 1.6s ease-in-out infinite;
}
.assistant-fab-badge[hidden] { display: none; }
@keyframes assistantBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.18); }
}
@keyframes assistantBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-5px); }
}

/* Персонаж */
.mascot-svg { width: 40px; height: 40px; overflow: visible; }
.m-head { fill: #fff; }
.m-ear  { fill: #c7d2fe; }
.m-eye  { fill: #4338ca; transform-box: fill-box; transform-origin: center; animation: mascotBlink 4s infinite; }
.m-smile { fill: none; stroke: #4338ca; stroke-width: 2; stroke-linecap: round; }
.m-antenna { stroke: #c7d2fe; stroke-width: 2; stroke-linecap: round; }
.m-dot { fill: #fbbf24; animation: mascotPulse 1.6s ease-in-out infinite; }

@keyframes mascotBlink {
    0%, 92%, 100% { transform: scaleY(1); }
    96%           { transform: scaleY(.1); }
}
@keyframes mascotPulse {
    0%, 100% { opacity: 1; r: 2.3px; }
    50%      { opacity: .5; r: 3px; }
}

/* «Живой» приветственный пузырь */
.assistant-hello {
    max-width: 210px;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-radius: 14px 14px 4px 14px;
    padding: 9px 12px;
    font-size: 13px;
    line-height: 1.3;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .14);
    position: relative;
    animation: helloIn .3s ease;
}
@keyframes helloIn {
    from { opacity: 0; transform: translateX(10px) scale(.9); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}
.assistant-hello-x {
    border: 0; background: transparent; color: #9ca3af;
    font-size: 18px; line-height: 1; cursor: pointer;
    position: absolute; top: 2px; right: 6px; padding: 2px;
}

/* На страницах чата помощника прячем (там место занимает поле ввода) */
body[data-route^="chats/"] .assistant { display: none; }

/* ==================================================================
   Панель помощника (нижний лист)
   ================================================================== */
.assistant-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 1055;
    opacity: 0; visibility: hidden;
    transition: opacity .25s;
}
.assistant-backdrop.show { opacity: 1; visibility: visible; }

.assistant-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1056;
    background: #f7f8fa;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .22);
    display: flex;
    flex-direction: column;
    max-height: 82vh;
    transform: translateY(110%);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}
.assistant-panel.open { transform: translateY(0); }
@media (min-width: 620px) {
    .assistant-panel { left: auto; right: 16px; width: 380px; border-radius: 18px; bottom: 16px; }
}

.assistant-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    border-radius: 18px 18px 0 0;
}
.assistant-head-ava {
    width: 40px; height: 40px; flex: 0 0 auto;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    display: flex; align-items: center; justify-content: center;
}
.assistant-head-ava .mascot-svg { width: 30px; height: 30px; animation: none; }
.assistant-head-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.assistant-head-name { font-weight: 700; font-size: 15px; }
.assistant-head-sub { font-size: 12px; opacity: .9; }
.assistant-close {
    border: 0; background: transparent; color: #fff;
    font-size: 20px; cursor: pointer; padding: 6px;
}

.assistant-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 160px;
}

/* Сообщения */
.a-msg {
    max-width: 88%;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    animation: aMsgIn .18s ease;
    word-break: break-word;
}
@keyframes aMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.a-msg.bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #eceef1;
    border-bottom-left-radius: 5px;
    color: #1f2937;
}
.a-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.a-msg.bot a { color: #4f46e5; font-weight: 600; }
.a-msg b { font-weight: 700; }

/* «Печатает…» */
.a-typing { display: inline-flex; gap: 4px; align-items: center; }
.a-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #c7cbd1;
    animation: aTyping 1s infinite;
}
.a-typing span:nth-child(2) { animation-delay: .15s; }
.a-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* Метка ответа специалиста (из Bitrix24) */
.a-op-label {
    font-size: 12px;
    font-weight: 700;
    color: #0369a1;
    margin-bottom: 4px;
}
@media (prefers-color-scheme: dark) { .a-op-label { color: #7dd3fc; } }

/* Подсказки-ссылки внутри ответа */
.a-suggests { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.a-suggest {
    border: 1px solid #d5d9f0;
    background: #eef0ff;
    color: #4338ca;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12.5px;
    cursor: pointer;
    text-align: left;
}
.a-suggest:hover { background: #e0e4ff; }

/* Быстрые действия */
.assistant-quick {
    display: flex; gap: 8px; flex-wrap: wrap;
    padding: 8px 14px 4px;
}
.assistant-chip {
    border: 1px solid #d5d9f0;
    background: #fff;
    color: #4338ca;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.assistant-chip:active { transform: translateY(1px); }

/* Поле ввода */
.assistant-input {
    display: flex; gap: 8px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid #eef0f3;
}
.assistant-input input {
    flex: 1;
    border: 1px solid #e2e5ea;
    border-radius: 999px;
    padding: 11px 14px;
    font-size: 14px;
    outline: none;
}
.assistant-input input:focus { border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.assistant-input button {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border: 0; border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff; font-size: 16px; cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 70, 229, .3);
}

@media (prefers-color-scheme: dark) {
    .assistant-hello { background: #111827; color: #e5e7eb; border-color: #1f2937; }
    .assistant-panel { background: #0b0f19; }
    .a-msg.bot { background: #111827; border-color: #1f2937; color: #e5e7eb; }
    .assistant-chip { background: #111827; border-color: #312e81; color: #c7d2fe; }
    .a-suggest { background: #1e1b4b; border-color: #312e81; color: #c7d2fe; }
    .assistant-input { background: #0b0f19; border-color: #1f2937; }
    .assistant-input input { background: #111827; border-color: #1f2937; color: #e5e7eb; }
}

/* ==================================================================
   Раздел «База знаний»
   ================================================================== */
.kb-search {
    position: relative;
    margin-bottom: 16px;
}
.kb-search i {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: #9ca3af; font-size: 14px;
}
.kb-search input {
    width: 100%;
    padding: 12px 14px 12px 40px;
    border-radius: 12px;
    border: 1px solid #e2e5ea;
    font-size: 15px;
}

.kb-category { margin-bottom: 18px; }
.kb-category-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #6b7280;
    margin-bottom: 8px;
}
.kb-category-title i { color: #4f46e5; margin-right: 4px; }

.kb-item {
    background: #fff;
    border: 1px solid #eef0f3;
    border-radius: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .04);
    overflow: hidden;
}
.kb-question {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 14px;
    font-weight: 600;
    font-size: 14.5px;
    color: #1f2937;
}
.kb-question::-webkit-details-marker { display: none; }
.kb-chevron { color: #9ca3af; font-size: 13px; transition: transform .2s; flex: 0 0 auto; }
.kb-item[open] .kb-chevron { transform: rotate(180deg); }
.kb-item[open] .kb-question { color: #4f46e5; }
.kb-answer {
    padding: 0 14px 14px;
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
}
.kb-answer b { color: #1f2937; }

@media (prefers-color-scheme: dark) {
    .kb-search input { background: #111827; border-color: #1f2937; color: #e5e7eb; }
    .kb-item { background: #0f172a; border-color: #1e293b; }
    .kb-question { color: #e5e7eb; }
    .kb-answer { color: #cbd5e1; }
    .kb-answer b { color: #f1f5f9; }
}
