/* AI-консультант Limenet — стилі віджета. Максимально ізольовано від бутстрапу сайту.
 *
 * Кольори взяті з css/public.css сайту: #74b64a — фірмовий лайм, #3b5b25 — темний
 * відтінок того самого зеленого. Основні площини (шапка, бульбашка користувача,
 * кнопка "надіслати") зроблені на темному: на світлому лаймі білий текст має
 * контраст близько 2.4:1 і читається погано. Лайм лишається акцентом —
 * фокус, ховер, підсвітки.
 *
 * Шрифти — ті самі Roboto/Montserrat, що вже підключені на сайті; якщо їх
 * не завантажено, працює системний fallback.
 */

#lm-ai-widget {
    all: initial;
    font-family: 'Roboto', -apple-system, "Segoe UI", Arial, sans-serif;
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 99998;
}

#lm-ai-widget * {
    box-sizing: border-box;
    font-family: inherit;
}

#lm-ai-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(155deg, #6aa843 0%, #33501f 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(38, 64, 22, 0.35);
    border: none;
    transition: transform .15s ease, box-shadow .15s ease;
}

#lm-ai-toggle:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 24px rgba(38, 64, 22, 0.45);
}

#lm-ai-toggle:active {
    transform: scale(0.98);
}

#lm-ai-toggle svg {
    width: 28px;
    height: 28px;
    display: block;
}

#lm-ai-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #d52f5b;
    color: #fff;
    font-size: 11px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 999px;
    font-weight: 600;
    display: none;
}

#lm-ai-panel {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: 74px;
    right: 0;
    width: 368px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(38, 64, 22, 0.26), 0 2px 8px rgba(38, 64, 22, 0.12);
    overflow: hidden;
    animation: lm-panel-in .18s ease;
}

@keyframes lm-panel-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

#lm-ai-widget.lm-open #lm-ai-panel {
    display: flex;
}

#lm-ai-header {
    background: linear-gradient(155deg, #4a8a2a 0%, #33501f 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#lm-ai-header-title {
    font-family: 'Montserrat', 'Roboto', -apple-system, "Segoe UI", Arial, sans-serif;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.3;
}

#lm-ai-header-sub {
    font-size: 11px;
    opacity: .75;
    font-weight: 400;
    margin-top: 2px;
}

#lm-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

#lm-ai-reset,
#lm-ai-close {
    background: none;
    border: none;
    color: #fff;
    opacity: .75;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    transition: opacity .15s ease, background .15s ease;
    flex-shrink: 0;
}

#lm-ai-reset svg,
#lm-ai-close svg {
    width: 16px;
    height: 16px;
    display: block;
}

#lm-ai-reset:hover,
#lm-ai-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.14);
}

#lm-ai-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f5f7f3;
    scrollbar-width: thin;
    scrollbar-color: #cdd8c4 transparent;
}

#lm-ai-messages::-webkit-scrollbar {
    width: 6px;
}

#lm-ai-messages::-webkit-scrollbar-thumb {
    background: #cdd8c4;
    border-radius: 999px;
}

.lm-msg {
    max-width: 85%;
    padding: 9px 12px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
    animation: lm-msg-in .16s ease;
}

@keyframes lm-msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.lm-msg-user {
    align-self: flex-end;
    background: #3b5b25;
    color: #fff;
    border-bottom-right-radius: 3px;
}

.lm-msg-assistant {
    align-self: flex-start;
    background: #fff;
    color: #1c1c1c;
    border: 1px solid #e3e8dd;
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 2px rgba(38, 64, 22, 0.05);
    white-space: normal;
}

/* Мінімальна типографіка для markdown-контенту з renderMarkdownSafe() */
.lm-msg-assistant p,
.lm-msg-assistant h4,
.lm-msg-assistant ul,
.lm-msg-assistant ol {
    margin: 0 0 8px;
}
/* Перший/останній блок у бульбашці не повинен додавати зайвий відступ до padding —
   інакше зверху й знизу виходить по-різному залежно від того, чим закінчується текст. */
.lm-msg-assistant > *:first-child {
    margin-top: 0;
}
.lm-msg-assistant > *:last-child {
    margin-bottom: 0;
}
.lm-msg-assistant h4 {
    font-family: 'Montserrat', 'Roboto', -apple-system, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #33501f;
}
.lm-msg-assistant ul,
.lm-msg-assistant ol {
    padding-left: 20px;
}
.lm-msg-assistant li {
    margin-bottom: 3px;
}
.lm-msg-assistant li:last-child {
    margin-bottom: 0;
}
.lm-msg-assistant code {
    background: #eef3ea;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
}
.lm-msg-assistant a {
    color: #417a22;
    word-break: break-word;
}

.lm-msg-system {
    align-self: center;
    background: transparent;
    color: #7d8a75;
    font-size: 12px;
    text-align: center;
}

.lm-msg-error {
    align-self: center;
    background: #fdecea;
    color: #a94442;
    border: 1px solid #f5c6cb;
    font-size: 12.5px;
}

#lm-ai-typing {
    align-self: flex-start;
    display: none;
    gap: 4px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e3e8dd;
    border-radius: 12px;
    border-bottom-left-radius: 3px;
}

#lm-ai-typing.lm-visible {
    display: flex;
}

#lm-ai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9aac90;
    animation: lm-blink 1.2s infinite ease-in-out;
}

#lm-ai-typing span:nth-child(2) { animation-delay: .2s; }
#lm-ai-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes lm-blink {
    0%, 80%, 100% { opacity: .25; }
    40% { opacity: 1; }
}

#lm-ai-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #e3e8dd;
    background: #fff;
    flex-shrink: 0;
}

#lm-ai-input {
    flex: 1;
    resize: none;
    border: 1px solid #d5ddcd;
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 13.5px;
    max-height: 90px;
    line-height: 1.4;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

#lm-ai-input:focus {
    border-color: #74b64a;
    box-shadow: 0 0 0 3px rgba(116, 182, 74, 0.22);
}

#lm-ai-send {
    background: #3b5b25;
    color: #fff;
    border: none;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, transform .1s ease;
}

#lm-ai-send:hover:not(:disabled) {
    background: #4d7431;
}

#lm-ai-send:active:not(:disabled) {
    transform: scale(0.94);
}

#lm-ai-send:disabled {
    opacity: .5;
    cursor: default;
}

#lm-ai-send svg {
    width: 18px;
    height: 18px;
    display: block;
}

#lm-ai-disclaimer {
    font-size: 10.5px;
    color: #9aac90;
    text-align: center;
    padding: 0 10px 8px;
    background: #fff;
}

/* Телефони: панель на весь екран. Півекранна панель на 360px завширшки лишає
   смужку сайту збоку, по якій легко промахнутись повз поле вводу. */
@media (max-width: 480px) {
    #lm-ai-widget {
        right: 12px;
        bottom: 12px;
    }

    #lm-ai-widget.lm-open #lm-ai-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    /* Кнопку виклику ховаємо, поки панель відкрита на весь екран:
       вона висіла б поверх поля вводу. Закриття — хрестиком у шапці. */
    #lm-ai-widget.lm-open #lm-ai-toggle {
        display: none;
    }

    /* 16px — межа, нижче якої iOS Safari зумить сторінку при фокусі в полі */
    #lm-ai-input {
        font-size: 16px;
    }
}
