/*
 * /assets/css/consultant.css
 *
 * Виджет чата с нейроконсультантом: плавающая кнопка + панель чата.
 * Подключается глобально из views/partials/footer.php (через consultant-widget.php).
 *
 * main.css НЕ трогаем: всё живёт здесь. Токены — из :root main.css.
 */

/* ---------- Плавающая кнопка ---------- */

.consultant-launcher {
    position: fixed;
    z-index: 55;
    right: 22px;
    bottom: 22px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 13px 19px 13px 15px;
    border: 2px solid var(--ink);
    border-radius: 999px;
    background: var(--acid);
    color: var(--ink);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 800;
    letter-spacing: -.01em;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(24, 24, 24, .16);
    transition: box-shadow .14s;
}

.consultant-launcher:hover {
    /* Без сдвига: по правилу владельца наведение не смещает объект. */
    box-shadow: 0 12px 26px rgba(24, 24, 24, .2);
}

.consultant-launcher:focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 3px;
}

.consultant-launcher__icon {
    display: grid;
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    background: var(--ink);
    color: var(--acid);
    font-family: "DM Mono", monospace;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.consultant-launcher__dot {
    position: absolute;
    top: 7px;
    right: 9px;
    width: 8px;
    height: 8px;
    border: 2px solid var(--acid);
    border-radius: 50%;
    background: var(--coral);
}

.consultant-launcher[hidden] {
    display: none;
}

/* ---------- Панель чата ---------- */

.consultant-panel {
    position: fixed;
    z-index: 56;
    right: 22px;
    bottom: 22px;
    display: flex;
    width: min(392px, calc(100vw - 44px));
    max-height: min(620px, calc(100vh - 44px));
    flex-direction: column;
    overflow: hidden;
    border: 2px solid var(--ink);
    border-radius: var(--radius-lg, 28px);
    background: var(--white);
    box-shadow: 0 18px 48px rgba(24, 24, 24, .22);
    animation: consultant-rise .18s ease-out;
}

.consultant-panel[hidden] {
    display: none;
}

@keyframes consultant-rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Шапка */

.consultant-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 15px 16px;
    border-bottom: 2px solid var(--ink);
    background: var(--acid);
}

.consultant-head__avatar {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    place-items: center;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--white);
    font-family: "DM Mono", monospace;
    font-size: 14px;
    font-weight: 700;
}

.consultant-head__body {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 1px;
}

.consultant-head__title {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -.02em;
}

.consultant-head__status {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #4b5020;
    font-family: "DM Mono", monospace;
    font-size: 10px;
    letter-spacing: .04em;
}

.consultant-head__status i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4b5020;
}

.consultant-head__close {
    display: grid;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    place-items: center;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--white);
    color: var(--ink);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.consultant-head__close:hover {
    background: var(--paper);
}

/* Лента сообщений */

.consultant-log {
    display: flex;
    min-height: 180px;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 16px;
    background: var(--paper);
    overscroll-behavior: contain;
}

.consultant-msg {
    display: flex;
    max-width: 88%;
    flex-direction: column;
    gap: 3px;
}

.consultant-msg--ai {
    align-self: flex-start;
}

.consultant-msg--me {
    align-self: flex-end;
    align-items: flex-end;
}

.consultant-msg__bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.consultant-msg--ai .consultant-msg__bubble {
    border: 1px solid var(--line);
    border-bottom-left-radius: 5px;
    background: var(--white);
}

.consultant-msg--me .consultant-msg__bubble {
    border: 1px solid var(--ink);
    border-bottom-right-radius: 5px;
    background: var(--ink);
    color: var(--white);
}

.consultant-msg--system .consultant-msg__bubble {
    border: 1px dashed var(--line);
    background: var(--white);
    color: var(--muted);
    font-size: 12px;
}

.consultant-msg--system {
    align-self: center;
    max-width: 100%;
    text-align: center;
}

.consultant-msg__time {
    padding: 0 4px;
    color: var(--muted);
    font-family: "DM Mono", monospace;
    font-size: 9px;
    letter-spacing: .04em;
}

/* Индикатор «печатает» */

.consultant-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 16px;
    border-bottom-left-radius: 5px;
    background: var(--white);
}

.consultant-typing[hidden] {
    display: none;
}

.consultant-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink);
    opacity: .35;
    animation: consultant-blink 1.1s infinite;
}

.consultant-typing i:nth-child(2) {
    animation-delay: .16s;
}

.consultant-typing i:nth-child(3) {
    animation-delay: .32s;
}

.consultant-typing span {
    color: var(--muted);
    font-size: 11px;
}

@keyframes consultant-blink {
    0%, 70%, 100% {
        opacity: .3;
        transform: translateY(0);
    }

    35% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

/* Быстрые вопросы (подсказки на старте) */

.consultant-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 16px 12px;
    background: var(--paper);
}

.consultant-quick[hidden] {
    display: none;
}

.consultant-quick button {
    padding: 7px 12px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--white);
    color: var(--ink);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background .14s;
}

.consultant-quick button:hover {
    background: var(--acid);
}

/* Поле ввода */

.consultant-compose {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
    background: var(--white);
}

.consultant-compose textarea {
    min-height: 44px;
    max-height: 110px;
    flex: 1 1 auto;
    resize: none;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.45;
}

.consultant-compose textarea:focus {
    border-color: var(--ink);
    background: var(--white);
    outline: none;
}

.consultant-compose textarea::placeholder {
    color: var(--muted);
}

.consultant-send {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    place-items: center;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--ink);
    color: var(--acid);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: opacity .14s;
}

.consultant-send:hover:not(:disabled) {
    opacity: .82;
}

.consultant-send:disabled {
    opacity: .45;
    cursor: default;
}

/* Подвал панели: эскалация */

.consultant-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 14px 11px;
    border-top: 1px dashed var(--line);
    background: var(--white);
}

.consultant-foot__hint {
    margin: 0;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.35;
}

.consultant-human {
    flex: 0 0 auto;
    padding: 8px 13px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 800;
    cursor: pointer;
    transition: background .14s;
}

.consultant-human:hover:not(:disabled) {
    background: var(--yellow);
}

.consultant-human:disabled {
    opacity: .5;
    cursor: default;
}

/* Ошибка */

.consultant-error {
    margin: 0;
    padding: 10px 13px;
    border-radius: 12px;
    background: rgba(255, 113, 95, .16);
    color: #a8341f;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.45;
}

.consultant-error[hidden] {
    display: none;
}

/* ---------- Мобильный: панель на весь экран ---------- */

@media (max-width: 720px) {
    .consultant-launcher {
        right: 14px;
        bottom: 14px;
        padding: 12px 16px 12px 13px;
        font-size: 12.5px;
    }

    .consultant-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        height: 100vh;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .consultant-log {
        padding: 14px;
        /* Панель на весь экран: при малом числе сообщений прижимаем их к низу,
           иначе между приветствием и полем ввода зияет пустота. */
        justify-content: flex-end;
    }

    .consultant-msg {
        max-width: 92%;
    }

    /* На весь экран шапку чуть выше: палец не должен попадать в крестик */
    .consultant-head {
        padding: 14px 15px;
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .consultant-compose {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* Уважаем системную настройку «меньше движения» */
@media (prefers-reduced-motion: reduce) {
    .consultant-panel,
    .consultant-launcher,
    .consultant-send {
        animation: none;
        transition: none;
    }

    .consultant-typing i {
        animation: none;
        opacity: .7;
    }
}
