/* Assistant HEOP public: widget HTMX mobile-first, reutilisable par surface. */
.assistant-widget {
    position: fixed;
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(82px + env(safe-area-inset-bottom));
    z-index: 190;
    color: var(--text);
    user-select: none;
}

.assistant-widget.is-hidden {
    display: none;
}

.assistant-widget__toggle {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 8px;
    padding: 0 14px 0 10px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent);
    color: var(--cream);
    font-weight: 850;
    box-shadow: 0 12px 28px color-mix(in srgb, var(--accent-strong) 24%, transparent);
    touch-action: none;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.assistant-widget__toggle:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--cream);
    text-decoration: none;
}

.assistant-widget.is-dragging .assistant-widget__toggle {
    cursor: grabbing;
    transform: scale(.98);
    box-shadow: 0 18px 34px color-mix(in srgb, var(--accent-strong) 30%, transparent);
}

.assistant-widget__dismiss {
    position: absolute;
    top: -8px;
    right: -7px;
    z-index: 3;
    width: 24px;
    min-width: 24px;
    min-height: 24px;
    padding: 0;
    border: 1px solid rgba(223, 212, 195, .86);
    border-radius: 999px;
    background: rgba(255, 253, 247, .94);
    color: var(--muted);
    box-shadow: 0 8px 18px color-mix(in srgb, var(--text) 10%, transparent);
}

.assistant-widget__dismiss:hover {
    color: var(--accent);
    background: var(--surface);
}

.assistant-widget__toggle-icon {
    display: inline-grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 999px;
    background: var(--cream);
    color: var(--brand);
}

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

.assistant-panel {
    position: absolute;
    right: 0;
    bottom: 56px;
    display: grid;
    width: min(348px, calc(100vw - 28px));
    max-height: min(600px, calc(100svh - 120px));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 22px 58px color-mix(in srgb, var(--text) 20%, transparent);
}

.assistant-widget.is-left-side .assistant-panel {
    right: auto;
    left: 0;
}

.assistant-widget.is-top-side .assistant-panel {
    top: 56px;
    bottom: auto;
}

.assistant-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--line);
    background:
        linear-gradient(135deg, var(--surface) 0%, var(--accent-soft) 56%, var(--brand-soft) 100%);
}

.assistant-panel__brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    color: var(--brand-strong);
    font-size: .78rem;
    font-weight: 850;
}

.assistant-panel__brand .heop-logo {
    width: 72px;
}

.assistant-panel__close {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border-color: var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
}

.assistant-thread {
    display: grid;
    gap: 10px;
    max-height: min(360px, calc(100svh - 280px));
    overflow: hidden auto;
    padding: 12px;
    background:
        linear-gradient(180deg, var(--surface) 0%, var(--accent-soft) 100%);
    scroll-behavior: smooth;
}

.assistant-message {
    display: flex;
}

.assistant-message--user {
    justify-content: flex-end;
}

.assistant-message__bubble {
    display: grid;
    gap: 6px;
    max-width: 88%;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--text) 7%, transparent);
}

.assistant-message--user .assistant-message__bubble {
    border-color: var(--brand);
    background: var(--brand);
    color: var(--cream);
}

.assistant-message__title {
    color: var(--brand-strong);
    font-size: .9rem;
    line-height: 1.2;
}

.assistant-message--user .assistant-message__title {
    color: var(--cream);
}

.assistant-message__bubble p {
    margin: 0;
    font-size: .86rem;
    line-height: 1.36;
}

.assistant-message__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 2px;
}

.assistant-message__action {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    padding: 0 10px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent);
    color: var(--cream);
    font-size: .78rem;
    font-weight: 800;
}

.assistant-message__action:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--cream);
    text-decoration: none;
}

.assistant-message__resources {
    display: grid;
    gap: 6px;
    padding-top: 2px;
}

.assistant-resource {
    display: grid;
    gap: 2px;
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--text);
}

.assistant-resource:hover {
    border-color: var(--accent);
    color: var(--brand-strong);
    text-decoration: none;
}

.assistant-resource__title {
    font-size: .8rem;
    font-weight: 850;
    line-height: 1.2;
}

.assistant-resource__subtitle {
    color: var(--muted);
    font-size: .72rem;
    font-weight: 650;
    line-height: 1.25;
}

.assistant-suggestions {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.assistant-suggestion {
    min-height: 34px;
    padding: 0 10px;
    border-color: var(--line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--brand-strong);
    font-size: .76rem;
    font-weight: 760;
}

.assistant-form {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.assistant-form__input {
    width: 100%;
    min-height: 38px;
    max-height: 92px;
    resize: none;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: .86rem;
    line-height: 1.25;
}

.assistant-form__input::placeholder {
    color: var(--muted);
}

.assistant-form__submit {
    width: 38px;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    border-color: var(--brand);
    border-radius: 999px;
    background: var(--brand);
    color: var(--cream);
}

.assistant-form__indicator {
    position: absolute;
    right: 60px;
    bottom: 24px;
    width: 14px;
    height: 14px;
    border: 2px solid color-mix(in srgb, var(--accent) 18%, transparent);
    border-top-color: var(--accent);
    border-radius: 999px;
    opacity: 0;
}

.assistant-form.htmx-request .assistant-form__indicator {
    opacity: 1;
    animation: assistant-spin 700ms linear infinite;
}

@keyframes assistant-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-height: 430px) and (orientation: landscape) {
    .assistant-widget {
        bottom: max(12px, env(safe-area-inset-bottom));
    }

    .assistant-panel {
        bottom: 52px;
        max-height: calc(100svh - 68px);
    }

    .assistant-widget.is-top-side .assistant-panel {
        top: 52px;
        bottom: auto;
    }

    .assistant-thread {
        max-height: calc(100svh - 218px);
    }

    .assistant-panel__header,
    .assistant-suggestions,
    .assistant-form {
        padding-block: 7px;
    }
}

@media (max-width: 759px) {
    .assistant-widget__toggle {
        width: 46px;
        min-width: 46px;
        min-height: 46px;
        justify-content: center;
        padding: 0;
    }

    .assistant-widget__toggle-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

@media (min-width: 760px) {
    .assistant-widget {
        right: max(24px, env(safe-area-inset-right));
        bottom: max(24px, env(safe-area-inset-bottom));
    }

    .assistant-panel {
        bottom: 58px;
        width: 372px;
        max-height: min(620px, calc(100svh - 92px));
    }

    .assistant-thread {
        max-height: 390px;
    }
}
