/*
    المساعد الافتراضي — floating launcher and chat panel (Components/Shared/ChatbotWidget.razor).

    Bottom-right like the ministry portal's launcher; the accessibility and back-to-top
    buttons own the bottom-left. Below 992px it lifts clear of the mobile bottom nav the
    same way those buttons do. Global (not scoped) CSS because chatbot.js builds the
    messages, and script-built elements never carry Blazor's scope attribute.
*/

.ecb {
    --ecb-brand: var(--primary-green, var(--text-primary));
    --ecb-brand-dark: #145f3d;
    --ecb-link: #0a7f73;
    --ecb-surface: var(--background-white);
    --ecb-muted-surface: var(--background-neutral-100);
    --ecb-border: var(--border-neutral-primary);
    --ecb-text: var(--text-default);
    --ecb-muted: #6c737f;
    --ecb-bottom: 24px;
    position: fixed;
    right: 24px;
    bottom: var(--ecb-bottom);
    z-index: 10001; /* over the cookie banner (10000), as on the ministry portal, and the mobile bottom nav */
    font-family: inherit;
    color: var(--ecb-text);
}

.ecb [hidden] {
    display: none !important;
}

/* ---------- launcher ---------- */

.ecb-launcher {
    width: 64px;
    height: 64px;
    border: 0;
    border-radius: 50%;
    background: var(--ecb-brand);
    color: var(--background-white);
    display: grid;
    place-items: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
    cursor: pointer;
    transition: background-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.ecb-launcher:hover {
    background: var(--ecb-brand-dark);
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .25);
}

.ecb-launcher:focus-visible {
    outline: 3px solid rgba(27, 131, 84, .45);
    outline-offset: 3px;
}

.ecb-launcher-close { display: none; }
.ecb-is-open .ecb-launcher-chat { display: none; }
.ecb-is-open .ecb-launcher-close { display: block; }

/* ---------- panel ---------- */

.ecb-panel {
    position: absolute;
    right: 0;
    bottom: 80px;
    width: 380px;
    height: min(600px, calc(100vh - 128px));
    height: min(600px, calc(100dvh - 128px));
    display: flex;
    flex-direction: column;
    background: var(--ecb-surface);
    border: 1px solid var(--ecb-border);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(16, 24, 40, .22);
    overflow: hidden;
    animation: ecb-rise .18s ease-out;
}

@keyframes ecb-rise {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}

.ecb-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    background: var(--ecb-surface);
    border-bottom: 3px solid var(--ecb-brand);
}

.ecb-logo {
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: 10px;
    background: var(--background-white);
    padding: var(--spacing-1);
    object-fit: contain;
    box-shadow: 0 0 0 1px var(--ecb-border);
}

.ecb-heading {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.ecb-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: var(--font-weight-bold);
    line-height: 1.4;
    color: var(--ecb-text);
}

.ecb-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .75rem;
    color: var(--ecb-muted);
}

.ecb-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ecb-brand);
}

.ecb-icon-btn {
    width: 36px;
    height: 36px;
    flex: none;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ecb-muted);
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    cursor: pointer;
}

.ecb-icon-btn:hover:not(:disabled) {
    background: var(--ecb-muted-surface);
    color: var(--ecb-text);
}

.ecb-icon-btn:disabled { opacity: .4; }

.ecb-icon-btn:focus-visible,
.ecb-chip:focus-visible,
.ecb-send:focus-visible,
.ecb-retry:focus-visible,
.ecb-service:focus-visible {
    outline: 2px solid var(--ecb-brand);
    outline-offset: 2px;
}

/* ---------- conversation ---------- */

.ecb-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    background: var(--ecb-muted-surface);
    overscroll-behavior: contain;
}

.ecb-thread {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.ecb-thread:empty { display: none; }

.ecb-msg {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    max-width: 100%;
}

/* The assistant's bubbles sit on the start side of their own language (each reply
   carries its own dir); the visitor's sit on the far side. */
.ecb-user { align-self: flex-end; }

.ecb-avatar {
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: 50%;
    background: var(--background-white);
    padding: var(--spacing-0-5);
    object-fit: contain;
    box-shadow: 0 0 0 1px var(--ecb-border);
}

.ecb-stack {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    min-width: 0;
    max-width: calc(100% - 36px);
}

.ecb-bubble {
    padding: .6rem .85rem;
    border-radius: 14px;
    font-size: .9rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.ecb-bot .ecb-bubble {
    background: var(--ecb-surface);
    color: var(--ecb-text);
    border: 1px solid var(--ecb-border);
    border-end-start-radius: 4px;
}

.ecb-user .ecb-bubble {
    max-width: 85%;
    margin-inline-start: auto;
    background: var(--ecb-brand);
    color: var(--background-white);
    border-end-end-radius: 4px;
}

.ecb-bubble a {
    color: var(--ecb-link);
    text-decoration: underline;
    word-break: break-all;
}

.ecb-user .ecb-bubble a { color: var(--background-white); }

.ecb-error .ecb-bubble {
    background: var(--colors-red-50);
    border-color: var(--colors-red-200);
    color: var(--colors-red-800);
}

.ecb-retry {
    align-self: flex-start;
    border: 1px solid var(--ecb-border);
    background: var(--ecb-surface);
    color: var(--ecb-text);
    border-radius: 999px;
    padding: .25rem .85rem;
    font-size: .8rem;
    cursor: pointer;
}

.ecb-retry:hover:not(:disabled) {
    border-color: var(--ecb-brand);
    color: var(--ecb-brand);
}

/* ---------- service cards ---------- */

.ecb-services {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.ecb-service {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .55rem .8rem;
    border: 1px solid #a6d2bb;
    border-radius: 10px;
    background: var(--ecb-surface);
    color: var(--ecb-brand);
    font-size: .85rem;
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
    transition: background-color .15s ease;
}

.ecb-service:hover {
    background: #eef7f2;
    color: var(--ecb-brand-dark);
}

/* ---------- typing indicator ---------- */

.ecb-typing {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-1);
    padding: .8rem .95rem;
    width: fit-content;
}

.ecb-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ecb-muted);
    animation: ecb-blink 1.2s infinite ease-in-out;
}

.ecb-typing span:nth-child(2) { animation-delay: .2s; }
.ecb-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes ecb-blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* A cold model can take up to a minute; say so only once the wait is noticeable. */
.ecb-slow {
    font-size: .75rem;
    color: var(--ecb-muted);
    opacity: 0;
    animation: ecb-appear .3s ease 6s forwards;
}

@keyframes ecb-appear {
    to { opacity: 1; }
}

/* ---------- quick replies ---------- */

.ecb-quick {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.ecb-chip {
    border: 1px solid #a6d2bb;
    background: var(--ecb-surface);
    color: var(--ecb-brand);
    border-radius: 999px;
    padding: .35rem .85rem;
    font-size: .8rem;
    line-height: 1.5;
    text-align: start;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.ecb-chip:hover {
    background: var(--ecb-brand);
    color: var(--background-white);
}

/* ---------- composer ---------- */

.ecb-composer {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .65rem .75rem;
    border-top: 1px solid var(--ecb-border);
    background: var(--ecb-surface);
    margin: 0;
}

.ecb-input {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    overflow-y: hidden;
    padding: .55rem .75rem;
    border: 1px solid var(--ecb-border);
    border-radius: 10px;
    background: var(--ecb-surface);
    color: var(--ecb-text);
    font: inherit;
    font-size: .9rem;
    line-height: 1.5;
}

.ecb-input:focus {
    outline: none;
    border-color: var(--ecb-brand);
    box-shadow: 0 0 0 3px rgba(27, 131, 84, .2);
}

.ecb-send {
    width: 42px;
    height: 42px;
    flex: none;
    border: 0;
    border-radius: 10px;
    background: var(--ecb-brand);
    color: var(--background-white);
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    cursor: pointer;
}

/* The paper plane points right; flip it so it points the way Arabic text runs. */
.ecb[dir="rtl"] .ecb-send i { transform: scaleX(-1); }

.ecb-send:hover:not(:disabled) { background: var(--ecb-brand-dark); }
.ecb-send:disabled { opacity: .45; cursor: default; }

.ecb-footnote {
    margin: 0;
    padding: 0 .75rem .55rem;
    background: var(--ecb-surface);
    font-size: .7rem;
    color: var(--ecb-muted);
    text-align: center;
}

/* ---------- smaller screens ---------- */

/* Same breakpoint as the portal's bottom nav: sit above it like .scroll-top does. */
@media (max-width: 991.98px) {
    .ecb {
        --ecb-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
}

@media (max-width: 480px) {
    .ecb-launcher {
        width: 56px;
        height: 56px;
    }

    .ecb-panel {
        position: fixed;
        top: 8px;
        right: 8px;
        left: 8px;
        bottom: calc(var(--ecb-bottom) + 64px);
        width: auto;
        height: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ecb-panel,
    .ecb-typing span,
    .ecb-launcher {
        animation: none;
        transition: none;
    }

    .ecb-slow { animation-duration: 0s; }
}

@media print {
    .ecb { display: none; }
}
