/* Explain: Styles for the AI assistant FAB, chat panel, and message bubbles. */
/* Floating AI assistant */

/* Launcher — bottom-right corner so it never overlaps the back-to-top
   control, which sits on the inline-end (left) edge. */
.ai-fab {
    position: fixed;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    right: 1.25rem;
    z-index: 70;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.85rem 1.1rem;
    border-radius: 999px;
    border: 0;
    background: var(--primary-color);
    color: #fff;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 18px 40px -16px rgba(0, 185, 107, 0.85);
    transition: background 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}
.ai-fab:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}
.ai-fab:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 2px;
}
.ai-fab i {
    font-size: 1.2rem;
}
.ai-fab-label {
    display: none;
}
@media (min-width: 640px) {
    .ai-fab-label {
        display: inline;
    }
}

.ai-panel {
    position: fixed;
    bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    right: 1.25rem;
    z-index: 70;
    width: min(22rem, calc(100vw - 2.5rem));
    max-height: min(32rem, calc(100vh - 8rem));
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 1.25rem;
    overflow: hidden;
    box-shadow: 0 30px 60px -25px rgba(13, 27, 36, 0.5);
    animation: ai-pop 0.2s ease;
}
.ai-panel[hidden] {
    display: none;
}
@keyframes ai-pop {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* Header with a clear assistant name + online status */
.ai-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: var(--dark-color);
    color: #fff;
}
.ai-head-id {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}
.ai-avatar {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.85rem;
    background: var(--primary-color);
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.ai-head-text {
    min-width: 0;
}
.ai-head-name {
    margin: 0;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1rem;
    line-height: 1.3;
    color: #fff;
    overflow-wrap: anywhere;
}
.ai-head-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.15rem 0 0;
    font-size: 0.76rem;
    color: rgba(255, 255, 255, 0.78);
}
.ai-head-status i {
    font-size: 0.45rem;
    color: #34d399;
}

/* Visible close button */
.ai-close {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}
.ai-close:hover,
.ai-close:focus-visible {
    background: rgba(255, 255, 255, 0.32);
    border-color: #fff;
    outline: none;
}
.ai-close i {
    font-size: 1rem;
}
@media (max-width: 400px) {
    .ai-close-text {
        display: none;
    }
    .ai-close {
        padding: 0.5rem 0.65rem;
    }
}

.ai-messages {
    flex: 1;
    min-height: 11rem;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--surface-color);
}
.ai-msg {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}
.ai-msg-bot {
    justify-content: flex-start;
}
.ai-msg-user {
    justify-content: flex-end;
}
.ai-bubble {
    max-width: 82%;
    padding: 0.65rem 0.95rem;
    border-radius: 1rem;
    font-size: 0.92rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.ai-msg-bot .ai-bubble {
    background: #fff;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-top-right-radius: 0.25rem;
}
.ai-msg-user .ai-bubble {
    background: var(--primary-color);
    color: #fff;
    border-top-left-radius: 0.25rem;
}

/* Message avatars — visitor vs assistant */
.ai-msg-avatar {
    display: grid;
    place-items: center;
    width: 1.85rem;
    height: 1.85rem;
    flex-shrink: 0;
    border-radius: 0.6rem;
    font-size: 0.8rem;
}
.ai-msg-bot .ai-msg-avatar {
    background: var(--primary-soft);
    color: var(--primary-color);
}
.ai-msg-user .ai-msg-avatar {
    background: var(--dark-color);
    color: #fff;
}

/* Quick-start questions inside the conversation */
.ai-quick-row .ai-bubble {
    max-width: none;
    flex: 1;
}
.ai-quick-label {
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.55rem;
}
.ai-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}
.ai-quick-btn {
    border: 1px solid var(--primary-color);
    background: #fff;
    color: var(--primary-hover);
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.83rem;
    padding: 0.45rem 0.8rem;
    border-radius: 0.75rem;
    cursor: pointer;
    text-align: start;
    transition: all 0.2s ease;
}
.ai-quick-btn:hover {
    background: var(--primary-color);
    color: #fff;
}
.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.ai-typing span {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 999px;
    background: var(--secondary-color);
    animation: ai-blink 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) {
    animation-delay: 0.2s;
}
.ai-typing span:nth-child(3) {
    animation-delay: 0.4s;
}
@keyframes ai-blink {
    0%, 80%, 100% {
        opacity: 0.25;
    }
    40% {
        opacity: 1;
    }
}

.ai-suggestions {
    display: flex;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
    overflow-x: auto;
    border-top: 1px solid var(--border-color);
    background: #fff;
    scrollbar-width: thin;
}
.ai-chip {
    flex: 0 0 auto;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-color);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}
.ai-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-hover);
}

.ai-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.75rem;
    background: #fff;
    border-top: 1px solid var(--border-color);
}
.ai-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 0.6rem 0.9rem;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-color);
    background: var(--surface-color);
}
.ai-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.ai-input::placeholder {
    color: var(--text-muted);
}
.ai-send {
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    flex-shrink: 0;
    border: 0;
    border-radius: 999px;
    background: var(--primary-color);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}
.ai-send:hover {
    background: var(--primary-hover);
}
.ai-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Mobile: comfortable launcher + bottom-sheet panel that leaves room above */
@media (max-width: 639px) {
    .ai-fab {
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        right: 1rem;
        padding: 0.9rem;
    }
    .ai-fab i {
        font-size: 1.3rem;
    }
    .ai-panel {
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
        max-height: min(30rem, calc(100vh - 9rem));
        border-radius: 1.15rem;
    }
    .ai-panel-head {
        padding: 0.85rem 0.9rem;
    }
    .ai-head-name {
        font-size: 0.95rem;
    }
    .ai-messages {
        padding: 0.85rem;
        gap: 0.65rem;
    }
    .ai-bubble {
        max-width: 88%;
    }
    .ai-suggestions {
        padding: 0.5rem 0.65rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-fab,
    .ai-fab:hover {
        transform: none;
    }
    .ai-panel {
        animation: none;
    }
}