/* ============================================================
   public/css/components/chatbot.css
   KNEST floating chatbot widget
   Load in app.blade.php after components/*.css
   ============================================================ */

/* ── FAB (Floating Action Button) ────────────────────────────────────── */
.chatbot-fab-wrap {
    position: fixed;
    /* sit above the a11y widget (56px / 3.5rem) + a small gap */
    bottom: calc(clamp(1rem, 3vw, 1.75rem) + 3.5rem + 0.625rem);
    right: clamp(1rem, 3vw, 1.75rem);
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

/* On mobile the nav drawer slides in from the right — move FAB to the left */
@media (max-width: 1499.98px) {
    .chatbot-fab-wrap {
        right: auto;
        left: clamp(1rem, 3vw, 1.75rem);
        align-items: flex-start;
    }
}

.chatbot-fab {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--color-green-bright, #0ca94b) 0%, var(--color-green-deep, #07542b) 100%);
    color: #fff;
    border: 2.5px solid rgba(255 255 255 / 0.9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 1px rgba(7 84 43 / 0.35),
                0 4px 24px rgba(7 84 43 / 0.55),
                inset 0 1px 0 rgba(255 255 255 / 0.25);
    transition: transform 0.2s var(--ease-spring, cubic-bezier(0.34,1.56,0.64,1)),
                background 0.2s, box-shadow 0.2s;
    position: relative;
}

/* Attention ping — ripples outward 3× each burst; triggered via .is-pinging by JS */
.chatbot-fab[aria-expanded="false"]::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2.5px solid var(--color-green-bright, #0ca94b);
    opacity: 0;
    pointer-events: none;
}

.chatbot-fab.is-pinging[aria-expanded="false"]::before {
    animation: fabPing 2.4s ease-out 3;
}

@keyframes fabPing {
    0%   { opacity: 0.85; transform: scale(1); }
    100% { opacity: 0;    transform: scale(1.65); }
}

.chatbot-fab:hover {
    background: linear-gradient(145deg, #22e876 0%, #0a6634 100%);
    transform: scale(1.1);
    box-shadow: 0 0 0 1px rgba(7 84 43 / 0.35),
                0 8px 32px rgba(12 169 75 / 0.6),
                inset 0 1px 0 rgba(255 255 255 / 0.25);
}

.chatbot-fab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(12 169 75 / 0.5),
                0 4px 20px rgba(7 84 43 / 0.4),
                inset 0 1px 0 rgba(255 255 255 / 0.22);
}

.chatbot-fab__icon {
    display: flex;
    transition: opacity 0.15s, transform 0.15s;
}

.chatbot-fab__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--color-orange);
    color: #fff;
    border-radius: 50%;
    font-size: 0.6875rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-surface, #f8f9f5);
}

.chatbot-fab__tooltip {
    position: absolute;
    right: calc(100% + 0.75rem);
    top: 50%;
    transform: translateY(-50%);
    background: var(--color-text, #1a2a1a);
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}

.chatbot-fab__tooltip::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-left-color: var(--color-text, #1a2a1a);
}

/* Tooltip flips to the right when FAB is on the left side */
@media (max-width: 1499.98px) {
    .chatbot-fab__tooltip {
        right: auto;
        left: calc(100% + 0.75rem);
    }
    .chatbot-fab__tooltip::after {
        left: auto;
        right: 100%;
        border-left-color: transparent;
        border-right-color: var(--color-text, #1a2a1a);
    }
}

.chatbot-fab-wrap:hover .chatbot-fab__tooltip,
.chatbot-fab:focus-visible + .chatbot-fab__tooltip {
    opacity: 1;
}

/* ── Chat panel ──────────────────────────────────────────────────────── */
.chatbot-panel {
    position: fixed;
    /* panel anchors above the FAB wrap (FAB height 3.5rem + 0.75rem gap) */
    bottom: calc(clamp(1rem, 3vw, 1.75rem) + 3.5rem + 0.625rem + 3.5rem + 0.75rem);
    right: clamp(1rem, 3vw, 1.75rem);
    width: min(380px, calc(100vw - 2rem));
    max-height: min(560px, calc(100vh - 8rem));
    background: #fff;
    border-radius: 1.5rem;
    box-shadow: 0 20px 64px rgba(0 0 0 / 0.22), 0 4px 12px rgba(0 0 0 / 0.1);
    border: 1px solid rgba(0 0 0 / 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 901;
    transform-origin: bottom right;
    transition: transform 0.28s var(--ease-spring, cubic-bezier(0.34,1.56,0.64,1)),
                opacity 0.2s;
}

@media (max-width: 1499.98px) {
    .chatbot-panel {
        right: auto;
        left: clamp(1rem, 3vw, 1.75rem);
        transform-origin: bottom left;
    }
}

.chatbot-panel[hidden] {
    display: none !important;
}

.chatbot-panel.is-entering {
    animation: chatbotEnter 0.3s var(--ease-spring, cubic-bezier(0.34,1.56,0.64,1)) both;
}

.chatbot-panel.is-leaving {
    animation: chatbotLeave 0.2s ease-in both;
}

@keyframes chatbotEnter {
    from { opacity: 0; transform: scale(0.88) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes chatbotLeave {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.9) translateY(10px); }
}

/* ── Panel header ────────────────────────────────────────────────────── */
.chatbot-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.125rem 1.25rem;
    background: linear-gradient(135deg, #07542b 0%, #0a6e38 60%, #0c8042 100%);
    color: #fff;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Subtle dot texture on header */
.chatbot-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(255,255,255,0.07) 1px, transparent 1px);
    background-size: 18px 18px;
    pointer-events: none;
}

.chatbot-header__avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: rgba(255 255 255 / 0.15);
    border: 1.5px solid rgba(255 255 255 / 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.chatbot-header__info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.chatbot-header__name {
    font-size: 0.9375rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-header__status {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: rgba(255 255 255 / 0.7);
}

.chatbot-header__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-green-bright);
    box-shadow: 0 0 0 0 rgba(12 169 75 / 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(12 169 75 / 0.5); }
    70%  { box-shadow: 0 0 0 6px rgba(12 169 75 / 0); }
    100% { box-shadow: 0 0 0 0 rgba(12 169 75 / 0); }
}

.chatbot-header__actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.chatbot-header__btn {
    background: none;
    border: none;
    color: rgba(255 255 255 / 0.7);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 6px;
    display: flex;
    transition: color 0.15s, background 0.15s;
}

.chatbot-header__btn:hover,
.chatbot-header__btn:focus-visible {
    color: #fff;
    background: rgba(255 255 255 / 0.12);
    outline: none;
}

/* ── Messages area ───────────────────────────────────────────────────── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.125rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    scroll-behavior: smooth;
    background: #f7fbf8;
}

.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(0 0 0 / 0.12);
    border-radius: 4px;
}

/* Bubble base */
.chatbot-bubble {
    max-width: 88%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    line-height: 1.55;
    animation: bubbleIn 0.2s ease both;
}

@keyframes bubbleIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Bot bubble */
.chatbot-bubble--bot {
    align-self: flex-start;
    background: #fff;
    color: var(--color-text, #1a2a1a);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(7 84 43 / 0.1);
    border-left: 3px solid var(--color-green-bright, #0ca94b);
    box-shadow: 0 1px 4px rgba(0 0 0 / 0.06);
}

/* User bubble */
.chatbot-bubble--user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--color-green-bright, #0ca94b) 0%, var(--color-green-deep, #07542b) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(7 84 43 / 0.25);
}

/* List inside bot bubble */
.chatbot-bubble ul {
    padding-inline-start: 1.1rem;
    margin: 0.5rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chatbot-bubble ul li::marker { color: var(--color-green-bright); }

/* "See full FAQ" link inside bubble */
.chatbot-bubble a {
    color: var(--color-green-deep);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-size: 0.8125rem;
    display: inline-block;
    margin-top: 0.5rem;
}

/* Multi-result list */
.chatbot-matches {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.chatbot-match-btn {
    background: rgba(7 84 43 / 0.07);
    border: 1px solid rgba(7 84 43 / 0.12);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-green-deep);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.chatbot-match-btn:hover,
.chatbot-match-btn:focus-visible {
    background: rgba(7 84 43 / 0.13);
    outline: none;
}

/* Typing indicator */
.chatbot-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: var(--color-green-pale, #eef7f1);
    border-radius: 1rem;
    border-bottom-left-radius: 4px;
}

.chatbot-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-green-bright);
    animation: typingDot 1.2s infinite;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.85); }
    30%            { opacity: 1;   transform: scale(1.1); }
}

/* ── Quick-start chips ───────────────────────────────────────────────── */
.chatbot-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.625rem 1.125rem 0.875rem;
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid rgba(7 84 43 / 0.07);
}

.chatbot-chip {
    background: #eef7f1;
    border: 1.5px solid rgba(7 84 43 / 0.18);
    border-radius: 100px;
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-green-deep);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.chatbot-chip:hover,
.chatbot-chip:focus-visible {
    background: #d6f0e0;
    border-color: var(--color-green-bright);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(7 84 43 / 0.12);
    outline: none;
}

/* ── Input row ───────────────────────────────────────────────────────── */
.chatbot-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid rgba(7 84 43 / 0.08);
    background: #fff;
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    background: #f4faf6;
    border: 1.5px solid rgba(7 84 43 / 0.18);
    border-radius: 100px;
    padding: 0.625rem 1rem;
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--color-text, #1a2a1a);
    outline: none;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.chatbot-input:focus-visible {
    background: #fff;
    border-color: var(--color-green-bright);
    box-shadow: 0 0 0 3px rgba(12 169 75 / 0.15);
}

.chatbot-send {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: none;
    background: linear-gradient(145deg, var(--color-green-bright, #0ca94b), var(--color-green-deep, #07542b));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(7 84 43 / 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.chatbot-send:disabled {
    background: rgba(0 0 0 / 0.1);
    box-shadow: none;
    cursor: default;
}

.chatbot-send:not(:disabled):hover {
    transform: scale(1.1);
    box-shadow: 0 4px 14px rgba(7 84 43 / 0.4);
}

.chatbot-send:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(12 169 75 / 0.4);
}

/* ── Reduce motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .chatbot-panel,
    .chatbot-bubble,
    .chatbot-fab,
    .chatbot-fab.is-pinging[aria-expanded="false"]::before,
    .chatbot-panel.is-entering,
    .chatbot-panel.is-leaving {
        animation: none !important;
        transition: none !important;
    }
}
