/* ==========================================================================
   Чат-помощник: кнопка «Помощь» и окно чата с ИИ
   ========================================================================== */

.assist-launcher {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 95;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    height: 48px;
    padding: 0 20px 0 18px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: var(--accent-glow), 0 12px 30px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.15s ease, bottom 0.2s ease;
}

.assist-launcher:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.assist-launcher i {
    font-size: 1.1rem;
}

.assist.is-open .assist-launcher {
    display: none;
}

.assist-panel {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 96;
    display: flex;
    flex-direction: column;
    width: 400px;
    height: min(640px, calc(100vh - var(--header-h) - 40px));
    height: min(640px, calc(100dvh - var(--header-h) - 40px));
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface-solid);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: dialog-in 0.18s ease-out;
}

.assist-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px 14px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(120deg, var(--accent-softer), transparent 70%);
}

.assist-head__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    box-shadow: var(--accent-glow);
}

.assist-head strong {
    display: block;
    font-size: 0.95rem;
}

.assist-head .grow span {
    display: block;
    color: var(--text-3);
    font-size: 0.78rem;
}

.assist-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 14px;
    overflow-y: auto;
}

.assist-msg {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 88%;
}

.assist-msg--user {
    align-self: flex-end;
    align-items: flex-end;
}

.assist-msg--bot {
    align-self: flex-start;
    align-items: flex-start;
}

.assist-bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.5;
    word-break: break-word;
}

.assist-msg--user .assist-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.assist-msg--bot .assist-bubble {
    background: var(--surface-2);
    border-bottom-left-radius: 5px;
}

.assist-msg.is-error .assist-bubble {
    background: var(--danger-soft);
    color: var(--danger);
}

.assist-bubble p + p,
.assist-bubble p + ul,
.assist-bubble p + ol,
.assist-bubble ul + p,
.assist-bubble ol + p {
    margin-top: 8px;
}

.assist-bubble ul,
.assist-bubble ol {
    margin: 0;
    padding-left: 20px;
}

.assist-bubble li + li {
    margin-top: 3px;
}

.assist-bubble code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--surface-3);
    font-family: var(--mono);
    font-size: 0.86em;
}

.assist-bubble a {
    color: var(--accent-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.assist-help {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 2px;
    border: 0;
    background: none;
    color: var(--accent-text);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
}

.assist-chips {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.assist-chip {
    padding: 7px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-size: 0.86rem;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.12s ease, background-color 0.12s ease;
}

.assist-chip:hover {
    border-color: var(--accent);
    background: var(--accent-softer);
}

.assist-typing {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
}

.assist-typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: assist-dot 1.2s infinite ease-in-out;
}

.assist-typing i:nth-child(2) {
    animation-delay: 0.15s;
}

.assist-typing i:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes assist-dot {
    0%,
    80%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

.assist-foot {
    flex: none;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--border);
}

.assist-input {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 5px 5px 5px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    background: var(--surface-2);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.assist-input:focus-within {
    border-color: var(--accent);
    box-shadow: var(--focus);
}

.assist-input textarea {
    flex: 1 1 auto;
    min-height: 36px;
    max-height: 140px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    resize: none;
    outline: none;
    overflow-y: hidden;
    font-size: 0.93rem;
    line-height: 1.4;
}

.assist-input textarea:focus-visible {
    box-shadow: none;
}

.assist-send {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    box-shadow: none;
}

.assist-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 8px;
}

.assist-actions button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text-2);
    font-size: 0.82rem;
    cursor: pointer;
}

.assist-actions button:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.assist-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.assist-form h3 {
    font-size: 1rem;
}

.assist-form form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.assist-form .field + .field {
    margin-top: 0;
}

.assist-form .textarea {
    min-height: 90px;
}

.assist-tabs {
    display: flex;
}

.assist-tabs button {
    flex: 1 1 0;
    padding: 0 6px;
    font-size: 0.82rem;
}

.assist-back {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border: 0;
    background: none;
    color: var(--text-2);
    font-size: 0.85rem;
    cursor: pointer;
}

.assist-back:hover {
    color: var(--text);
}

.assist-suggestions {
    margin-top: 6px;
}

.assist-done {
    align-items: center;
    margin: auto 0;
    padding: 20px 10px;
    text-align: center;
}

@media (max-width: 640px) {
    .assist-launcher {
        right: 14px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        width: 54px;
        height: 54px;
        padding: 0;
        justify-content: center;
    }

    .assist-launcher span {
        display: none;
    }

    .assist-launcher i {
        font-size: 1.3rem;
    }

    .assist-panel {
        inset: 0;
        width: auto;
        height: auto;
        border: 0;
        border-radius: 0;
        z-index: 250;
        padding-bottom: env(safe-area-inset-bottom);
        animation: sheet-in 0.22s ease-out;
    }

    body.has-cookie-banner .assist-launcher {
        bottom: calc(150px + env(safe-area-inset-bottom));
    }
}
