/* ═══════════════════════════════════════════════════════════
 * Advanced FRAAG AI Chat — front.css  v1.0.0
 * Modern bubble chat interface
 * ═══════════════════════════════════════════════════════════ */

:root {
    --afraag-primary:     #5344B7;
    --afraag-user-bubble: #5344B7;
    --afraag-bot-bubble:  #F4F3FF;
    --afraag-dark:        #1a1a2e;
    --afraag-light:       #ffffff;
    --afraag-chat-width:  100%;
    --afraag-chat-height: 420px;
    --afraag-avatar-bg:   #5344B7;
    --afraag-radius:      18px;
    --afraag-shadow:      0 4px 24px rgba(0,0,0,.10);
}

/* ── Widget shell ── */
.afraag-chat {
    width: var(--afraag-chat-width);
    max-width: 100%;
    border: 1px solid rgba(0,0,0,.10);
    border-radius: 16px;
    overflow: hidden;
    background: var(--afraag-light);
    box-shadow: var(--afraag-shadow);
    display: flex;
    flex-direction: column;
    font-family: inherit;
    color: var(--afraag-dark);
}

/* ── Header ── */
.afraag-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--afraag-light);
    border-bottom: 1px solid rgba(0,0,0,.07);
    flex-shrink: 0;
}
.afraag-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--avatar-bg, var(--afraag-avatar-bg));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.afraag-avatar img { width: 100%; height: 100%; object-fit: cover; }
.afraag-avatar span {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .02em;
}
.afraag-header-info { flex: 1; min-width: 0; }
.afraag-bot-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--afraag-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.afraag-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #22c55e;
    margin-top: 1px;
}
.afraag-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
}
.afraag-header-actions { display: flex; gap: 4px; }
.afraag-header-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.10);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--afraag-dark);
    opacity: .6;
    transition: opacity .15s, background .15s;
}
.afraag-header-btn:hover { opacity: 1; background: rgba(0,0,0,.05); }
.afraag-header-btn svg { width: 16px; height: 16px; }
.afraag-voice-toggle.is-active { opacity: 1; color: var(--afraag-primary); border-color: var(--afraag-primary); }

/* ── Messages ── */
.afraag-messages {
    flex: 1;
    height: var(--afraag-chat-height);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    background: #fafafa;
}

/* ── Message rows ── */
.afraag-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: afraagFadeIn .2s ease;
}
.afraag-msg--user { flex-direction: row-reverse; }

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

/* ── Message avatars ── */
.afraag-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--avatar-bg, var(--afraag-avatar-bg));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
}
.afraag-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.afraag-msg--user .afraag-msg-avatar { background: rgba(83,68,183,.3); color: var(--afraag-primary); }

/* ── Bubble container ── */
.afraag-bubble-wrap { max-width: 75%; display: flex; flex-direction: column; }
.afraag-msg--user .afraag-bubble-wrap { align-items: flex-end; }

/* ── Bubble ── */
.afraag-bubble {
    padding: 10px 14px;
    border-radius: var(--afraag-radius);
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
}
.afraag-bubble--bot {
    background: var(--afraag-bot-bubble);
    border-bottom-left-radius: 4px;
    color: var(--afraag-dark);
}
.afraag-bubble--user {
    background: var(--afraag-user-bubble);
    border-bottom-right-radius: 4px;
    color: #fff;
}
/* Markdown content inside bot bubble */
.afraag-bubble--bot p { margin: 0 0 .5em; }
.afraag-bubble--bot p:last-child { margin: 0; }
.afraag-bubble--bot ul, .afraag-bubble--bot ol { margin: .3em 0 .3em 1.2em; padding: 0; }
.afraag-bubble--bot code { background: rgba(0,0,0,.06); border-radius: 3px; padding: .1em .3em; font-size: .9em; }
.afraag-bubble--bot pre { background: rgba(0,0,0,.06); border-radius: 6px; padding: .6em .8em; overflow-x: auto; }

/* ── Bubble meta (time + actions) ── */
.afraag-bubble-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.afraag-msg--user .afraag-bubble-meta { justify-content: flex-end; }
.afraag-msg-time {
    font-size: 10px;
    color: rgba(0,0,0,.4);
    white-space: nowrap;
}
.afraag-msg--user .afraag-msg-time { color: rgba(0,0,0,.35); }

/* ── Per-message action buttons ── */
.afraag-msg-actions { display: flex; gap: 3px; }
.afraag-msg-action {
    background: none;
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 20px;
    padding: 3px 8px;
    font-size: 11px;
    color: rgba(0,0,0,.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background .12s, color .12s;
    white-space: nowrap;
}
.afraag-msg-action:hover { background: rgba(0,0,0,.06); color: var(--afraag-dark); }
.afraag-msg-action.is-selected { color: var(--afraag-primary); border-color: var(--afraag-primary); }
.afraag-msg-action svg { width: 11px; height: 11px; }

/* ── Typing indicator ── */
.afraag-typing { display: flex; align-items: center; gap: 4px; padding: 12px 16px; }
.afraag-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: rgba(83,68,183,.4);
    animation: afraagBounce 1.2s infinite;
    display: inline-block;
}
.afraag-typing span:nth-child(2) { animation-delay: .18s; }
.afraag-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes afraagBounce {
    0%,80%,100% { transform: translateY(0); }
    40%          { transform: translateY(-5px); }
}

/* ── Suggestions chips ── */
.afraag-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px;
    background: #fafafa;
    border-top: 1px solid rgba(0,0,0,.06);
    transition: opacity .2s;
}
.afraag-suggestions.is-hidden { display: none; }
.afraag-chip {
    background: var(--afraag-light);
    border: 1.5px solid var(--afraag-primary);
    color: var(--afraag-primary);
    border-radius: 999px;
    padding: 5px 13px;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.afraag-chip:hover { background: var(--afraag-primary); color: #fff; }

/* ── Input area ── */
.afraag-input-area {
    background: var(--afraag-light);
    border-top: 1px solid rgba(0,0,0,.07);
    padding: 10px 12px;
    flex-shrink: 0;
}
.afraag-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f4f4f8;
    border: 1.5px solid rgba(0,0,0,.10);
    border-radius: 24px;
    padding: 5px 5px 5px 14px;
    transition: border-color .15s;
}
.afraag-input-row:focus-within { border-color: var(--afraag-primary); }
.afraag-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--afraag-dark);
    outline: none;
    min-width: 0;
}
.afraag-input::placeholder { color: rgba(0,0,0,.35); }

/* ── Mic button ── */
.afraag-mic-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0,0,0,.4);
    flex-shrink: 0;
    transition: color .15s, background .15s;
}
.afraag-mic-btn:hover { background: rgba(0,0,0,.06); color: var(--afraag-dark); }
.afraag-mic-btn svg { width: 17px; height: 17px; }
.afraag-mic-btn.is-recording {
    background: #ef4444;
    color: #fff;
    animation: afraagPulse 1s infinite;
}
@keyframes afraagPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); }
    50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ── Send button ── */
.afraag-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--afraag-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity .15s, transform .1s;
}
.afraag-send-btn:disabled { opacity: .35; cursor: default; }
.afraag-send-btn:not(:disabled):hover { opacity: .9; }
.afraag-send-btn:not(:disabled):active { transform: scale(.95); }
.afraag-send-btn svg { width: 16px; height: 16px; }

/* ── Recording bar ── */
.afraag-recording-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 5px 14px;
    background: #fef2f2;
    border-radius: 8px;
    font-size: 12px;
    color: #dc2626;
}
.afraag-recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #dc2626;
    animation: afraagBlink .8s infinite;
    flex-shrink: 0;
}
@keyframes afraagBlink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Info modal ── */
.afraag-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 14px;
    padding: 1.2rem 1.5rem;
    background: var(--afraag-light);
    box-shadow: 0 8px 32px rgba(0,0,0,.16);
    max-width: 320px;
    font-size: .9rem;
    line-height: 1.55;
    animation: afraagFadeIn .15s ease;
}
.afraag-modal--open { display: block; }
.afraag-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    z-index: 99998;
}
.afraag-modal-backdrop--open { display: block; }
.afraag-modal-close {
    position: absolute;
    top: .5rem; right: .6rem;
    background: none; border: none;
    cursor: pointer;
    color: var(--afraag-dark);
    opacity: .45;
    display: flex;
    align-items: center;
    padding: .1rem;
}
.afraag-modal-close:hover { opacity: 1; }
.afraag-modal-close svg { width: 16px; height: 16px; }
.afraag-modal-title { font-weight: 700; font-size: 1rem; padding-right: 1.2rem; margin-bottom: .5rem; }
.afraag-modal ul { margin: .4rem 0 0 1.1rem; padding: 0; }
.afraag-modal li { margin-bottom: .2rem; }

/* ── Debug panel ── */
.afraag-debug {
    margin-top: 8px;
    border: 2px solid #ea580c;
    border-radius: 8px;
    background: #1e1e2e;
    color: #cdd6f4;
    font-family: monospace;
    font-size: 11px;
    overflow: hidden;
}
.afraag-debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ea580c;
    color: #fff;
    padding: 5px 10px;
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
    user-select: none;
}
.afraag-debug-body {
    padding: 6px;
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.afraag-debug-body.is-collapsed { display: none; }
.afraag-debug-line { display: flex; gap: 6px; line-height: 1.5; padding: 2px 3px; }
.afraag-debug-ts { color: #a6adc8; white-space: nowrap; flex-shrink: 0; font-size: 10px; }
.afraag-debug-badge {
    flex-shrink: 0; padding: 0 5px; border-radius: 3px;
    font-size: 10px; font-weight: 700; text-transform: uppercase; line-height: 1.6;
}
.afraag-debug-badge--info  { background: #89b4fa; color: #1e1e2e; }
.afraag-debug-badge--ok    { background: #a6e3a1; color: #1e1e2e; }
.afraag-debug-badge--warn  { background: #f9e2af; color: #1e1e2e; }
.afraag-debug-badge--error { background: #f38ba8; color: #1e1e2e; }
.afraag-debug-badge--send  { background: #cba6f7; color: #1e1e2e; }
.afraag-debug-badge--recv  { background: #89dceb; color: #1e1e2e; }
.afraag-debug-badge--voice { background: #f38ba8; color: #1e1e2e; }
.afraag-debug-text { flex: 1; word-break: break-all; white-space: pre-wrap; }
.afraag-debug-text strong { color: #f5c2e7; }
.afraag-debug-footer {
    border-top: 1px solid #313244;
    padding: 4px 8px;
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #a6adc8;
}
.afraag-debug-clear {
    background: none; border: 1px solid #585b70;
    color: #a6adc8; padding: 1px 7px; border-radius: 3px; cursor: pointer; font-size: 10px;
}
.afraag-debug-clear:hover { background: #313244; }

/* ── Utilities ── */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
