/* Floating AI assistant (layouts/ai_assistant.blade.php).
   Colours come from foundation.css tokens, so dark theme works as-is.
   Sits below the mobile drawer (1040/1045) and Bootstrap modals (1050). */

.ai-fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 1030;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-contrast);
    font-size: 1.35rem;
    box-shadow: 0 8px 24px rgba(8, 127, 121, 0.35);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.ai-fab:hover { background: var(--primary-hover); transform: translateY(-2px); }
.ai-fab:focus-visible { outline: 3px solid var(--input-glow); outline-offset: 2px; }
.ai-fab[aria-expanded="true"] { display: none; }

.ai-panel {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 1035;
    display: flex;
    flex-direction: column;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 40px));
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
    overflow: hidden;
}

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

.ai-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
}

.ai-panel__title { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.ai-panel__title strong { display: block; font-size: 0.95rem; }
.ai-panel__title small { display: block; color: var(--text-muted); font-size: 0.78rem; }

.ai-panel__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
}

.ai-panel__actions { display: flex; gap: 0.25rem; }

.ai-icon-btn {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.ai-icon-btn:hover { background: var(--surface-selected); color: var(--text-primary); }

.ai-panel__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-welcome p { margin: 0 0 0.75rem; color: var(--text-muted); }

.ai-suggestions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.ai-suggestions button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
}

.ai-suggestions button:hover { border-color: var(--primary); background: var(--primary-soft); }

.ai-msg {
    max-width: 92%;
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.ai-msg--user {
    align-self: flex-end;
    background: var(--primary);
    color: var(--primary-contrast);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.ai-msg--assistant {
    align-self: flex-start;
    background: var(--surface-alt);
    border-bottom-left-radius: 4px;
}

.ai-msg--error {
    align-self: flex-start;
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

.ai-msg p { margin: 0 0 0.5rem; }
.ai-msg p:last-child, .ai-msg ul:last-child, .ai-msg ol:last-child, .ai-msg .ai-table-wrap:last-child { margin-bottom: 0; }
.ai-msg ul, .ai-msg ol { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.ai-msg h4 { font-size: 0.95rem; font-weight: 600; margin: 0.25rem 0 0.4rem; }
.ai-msg code { font-size: 0.82rem; padding: 0.05rem 0.3rem; border-radius: 4px; background: var(--surface); color: inherit; }

.ai-table-wrap { overflow-x: auto; margin: 0 0 0.5rem; }
.ai-msg table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.ai-msg th, .ai-msg td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.ai-msg th { font-weight: 600; }

.ai-msg__meta { margin-top: 0.4rem; font-size: 0.72rem; color: var(--text-subtle); }

.ai-typing { display: inline-flex; gap: 4px; padding: 0.2rem 0; }
.ai-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-subtle); animation: ai-bounce 1.2s infinite ease-in-out; }
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-5px); opacity: 1; }
}

.ai-panel__composer {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.ai-panel__composer textarea {
    flex: 1 1 auto;
    resize: none;
    max-height: 140px;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--input-text);
    font-size: 0.9rem;
    line-height: 1.4;
}

.ai-panel__composer textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--input-glow); }

.ai-send {
    flex: 0 0 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: var(--primary-contrast);
    cursor: pointer;
}

.ai-send:disabled { opacity: 0.55; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
    .ai-fab, .ai-typing span { transition: none; animation: none; }
}

/* Phones: full-screen sheet. */
@media (max-width: 575.98px) {
    .ai-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }

    .ai-panel {
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    .ai-panel__composer { padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)); }
    /* 16px stops iOS zooming into the field on focus. */
    .ai-panel__composer textarea { font-size: 16px; }
}
