/**
 * Forerunner AI Live Chat Pro — Embedded Chat Shortcode Styles
 *
 * Fully scoped under .frai-embed-chat so nothing leaks into the page
 * or collides with the floating widget.
 */

/* ───────────────────────────────────────────────────────────
   Container
   ─────────────────────────────────────────────────────────── */

.frai-embed-chat {
    --frai-e-radius: 16px;
    --frai-e-font: inherit;
    --frai-e-font-size: 15px;
    --frai-e-transition: 0.2s ease;

    display: flex;
    flex-direction: column;
    border-radius: var(--frai-e-radius);
    overflow: hidden;
    font-family: var(--frai-e-font);
    font-size: var(--frai-e-font-size);
    line-height: 1.5;
    position: relative;
    box-sizing: border-box;
}

.frai-embed-chat *,
.frai-embed-chat *::before,
.frai-embed-chat *::after {
    box-sizing: border-box;
}

/* ───────────────────────────────────────────────────────────
   LIGHT theme tokens
   ─────────────────────────────────────────────────────────── */

.frai-embed-light {
    --frai-e-bg: #ffffff;
    --frai-e-bg-secondary: #f7f7f8;
    --frai-e-text: #1a1a1a;
    --frai-e-text-secondary: #6b7280;
    --frai-e-border: #e5e7eb;
    --frai-e-border-light: rgba(0, 0, 0, 0.06);
    --frai-e-accent: #F47F1F;
    --frai-e-accent-hover: #d86d14;
    --frai-e-user-bubble: #1a1a1a;
    --frai-e-user-text: #ffffff;
    --frai-e-bot-bubble: #ffffff;
    --frai-e-bot-bubble-border: #e5e7eb;
    --frai-e-bot-text: #1a1a1a;
    --frai-e-input-bg: #ffffff;
    --frai-e-input-border: #d1d5db;
    --frai-e-input-focus: #1a1a1a;
    --frai-e-action-hover: #f4f4f5;
    --frai-e-action-icon: #6b7280;
    --frai-e-action-icon-hover: #1a1a1a;
    --frai-e-send-btn: #1a1a1a;
    --frai-e-send-btn-hover: #333333;
    --frai-e-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    background: var(--frai-e-bg);
    color: var(--frai-e-text);
    border: 1px solid var(--frai-e-border);
    box-shadow: var(--frai-e-shadow);
}

/* ───────────────────────────────────────────────────────────
   DARK theme tokens
   ─────────────────────────────────────────────────────────── */

.frai-embed-dark {
    --frai-e-bg: #1a1a1a;
    --frai-e-bg-secondary: #262626;
    --frai-e-text: #e5e5e5;
    --frai-e-text-secondary: #9ca3af;
    --frai-e-border: #333333;
    --frai-e-border-light: rgba(255, 255, 255, 0.08);
    --frai-e-accent: #F47F1F;
    --frai-e-accent-hover: #ff9b3e;
    --frai-e-user-bubble: #333333;
    --frai-e-user-text: #ffffff;
    --frai-e-bot-bubble: #262626;
    --frai-e-bot-bubble-border: #404040;
    --frai-e-bot-text: #e5e5e5;
    --frai-e-input-bg: #262626;
    --frai-e-input-border: #404040;
    --frai-e-input-focus: #666666;
    --frai-e-action-hover: #2a2a2a;
    --frai-e-action-icon: #9ca3af;
    --frai-e-action-icon-hover: #e5e5e5;
    --frai-e-send-btn: #333333;
    --frai-e-send-btn-hover: #4a4a4a;
    --frai-e-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    background: var(--frai-e-bg);
    color: var(--frai-e-text);
    border: 1px solid var(--frai-e-border);
    box-shadow: var(--frai-e-shadow);
}

/* ───────────────────────────────────────────────────────────
   Floating actions overlay (top-right reset icon)
   ─────────────────────────────────────────────────────────── */

.frai-embed-header {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    display: flex;
    gap: 4px;
    background: none;
    border: none;
    padding: 0;
}

.frai-embed-header-actions {
    display: flex;
    gap: 4px;
}

.frai-embed-header-actions button {
    background: none;
    border: none;
    color: var(--frai-e-text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--frai-e-transition), color var(--frai-e-transition);
}

.frai-embed-header-actions button:hover {
    background: var(--frai-e-action-hover);
    color: var(--frai-e-text);
}

.frai-embed-header-actions button svg {
    width: 20px;
    height: 20px;
}

/* ───────────────────────────────────────────────────────────
   Messages area
   ─────────────────────────────────────────────────────────── */

.frai-embed-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 8px;
    display: flex;
    flex-direction: column;
    background: var(--frai-e-bg);
    scroll-behavior: smooth;
}

/* ───────────────────────────────────────────────────────────
   Welcome / ChatKit landing
   ─────────────────────────────────────────────────────────── */

.frai-embed-welcome {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    flex: 1;
    padding: 0 0 4px;
}

.frai-embed-welcome-heading {
    font-size: 22px;
    font-weight: 700;
    color: var(--frai-e-text);
    margin: 0 0 16px;
    line-height: 1.25;
}

.frai-embed-actions {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.frai-embed-action {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: var(--frai-e-font-size);
    font-weight: 400;
    color: var(--frai-e-text);
    text-align: left;
    transition: background var(--frai-e-transition);
    border-radius: 8px;
    margin-bottom: 0;
}

.frai-embed-action:hover {
    background: var(--frai-e-action-hover);
}

.frai-embed-action-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--frai-e-action-icon);
    transition: color var(--frai-e-transition);
}

.frai-embed-action:hover .frai-embed-action-icon {
    color: var(--frai-e-action-icon-hover);
}

.frai-embed-action-icon svg {
    width: 22px;
    height: 22px;
}

.frai-embed-action-label {
    flex: 1;
}

.frai-embed-action-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--frai-e-transition);
    color: var(--frai-e-text-secondary);
}

.frai-embed-action-arrow svg {
    width: 16px;
    height: 16px;
}

.frai-embed-action:hover .frai-embed-action-arrow {
    opacity: 1;
}

/* ───────────────────────────────────────────────────────────
   Chat messages
   ─────────────────────────────────────────────────────────── */

.frai-embed-msg {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    animation: frai-embed-fadeIn 0.3s ease-out;
}

@keyframes frai-embed-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.frai-embed-msg-user {
    align-items: flex-end;
}

.frai-embed-msg-bot {
    align-items: flex-start;
}

.frai-embed-msg .frai-embed-sender {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--frai-e-text);
}

.frai-embed-msg .frai-embed-bot-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.frai-embed-msg .frai-embed-bot-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.frai-embed-msg .frai-embed-bot-icon-svg {
    background: var(--frai-e-accent);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.frai-embed-msg .frai-embed-bot-icon-svg svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.frai-embed-msg .frai-embed-text {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.45;
    font-size: var(--frai-e-font-size);
}

.frai-embed-msg-user .frai-embed-text {
    background: var(--frai-e-user-bubble);
    color: var(--frai-e-user-text);
    border-bottom-right-radius: 4px;
}

.frai-embed-msg-bot .frai-embed-text {
    background: var(--frai-e-bot-bubble);
    color: var(--frai-e-bot-text);
    border: 1px solid var(--frai-e-bot-bubble-border);
    border-bottom-left-radius: 4px;
}

/* Links inside bot messages */
.frai-embed-msg-bot .frai-embed-text a {
    color: var(--frai-e-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity var(--frai-e-transition);
}

.frai-embed-msg-bot .frai-embed-text a:hover {
    opacity: 0.7;
}

.frai-embed-msg-bot .frai-embed-text strong {
    font-weight: 600;
    color: var(--frai-e-bot-text);
}

/* Markdown tables */
.frai-embed-chat .frai-embed-table-wrap {
    overflow-x: auto;
    margin: 8px 0;
    border-radius: 6px;
    border: 1px solid var(--frai-e-border);
}

.frai-embed-chat .frai-embed-md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.frai-embed-chat .frai-embed-md-table th,
.frai-embed-chat .frai-embed-md-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--frai-e-border);
}

.frai-embed-chat .frai-embed-md-table th {
    background: var(--frai-e-border-light);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--frai-e-text-secondary);
}

/* Markdown lists */
.frai-embed-chat .frai-embed-md-list {
    margin: 6px 0;
    padding-left: 20px;
}

.frai-embed-chat .frai-embed-md-list li {
    margin: 3px 0;
    line-height: 1.4;
}

/* Code blocks */
.frai-embed-chat .frai-embed-code-block {
    background: #1e1e2e;
    color: #cdd6f4;
    padding: 10px 14px;
    border-radius: 6px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre;
}

.frai-embed-chat .frai-embed-inline-code {
    background: var(--frai-e-border-light);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
}

/* Headings in chat */
.frai-embed-chat .frai-embed-md-heading {
    margin: 10px 0 4px;
    font-weight: 600;
    color: var(--frai-e-text);
    line-height: 1.3;
}

/* ───────────────────────────────────────────────────────────
   Typing indicator
   ─────────────────────────────────────────────────────────── */

.frai-embed-typing {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--frai-e-bot-bubble);
    border: 1px solid var(--frai-e-bot-bubble-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.frai-embed-typing span {
    height: 8px;
    width: 8px;
    background: var(--frai-e-text-secondary);
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: frai-embed-bounce 1.4s infinite ease-in-out both;
}

.frai-embed-typing span:nth-child(2) { animation-delay: -0.8s; }
.frai-embed-typing span:nth-child(3) { animation-delay: -0.4s; }

@keyframes frai-embed-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Streaming cursor */
.frai-embed-streaming::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--frai-e-text-secondary);
    margin-left: 4px;
    vertical-align: middle;
    animation: frai-embed-pulse-dot 1.2s ease-in-out infinite;
}

@keyframes frai-embed-pulse-dot {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1); }
}

/* Stream word reveal */
/* Words are laid out but not displayed until the reveal reaches them, so the
   message grows line by line instead of appearing at full height. An animation
   rather than a transition, because a transition cannot run from display: none. */
.frai-embed-stream-word {
    display: none;
}

.frai-embed-stream-word.frai-embed-visible {
    display: inline;
    animation: frai-embed-word-in 180ms ease both;
}

@keyframes frai-embed-word-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* List items, table rows and code blocks the reveal has not reached yet. */
.frai-embed-stream-block {
    display: none;
}

/* ───────────────────────────────────────────────────────────
   Input area
   ─────────────────────────────────────────────────────────── */

.frai-embed-input-wrap {
    flex-shrink: 0;
    background: var(--frai-e-bg);
    border-top: 1px solid var(--frai-e-border);
}

.frai-embed-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 16px;
}

.frai-embed-input input {
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 18px;
    border: 1px solid var(--frai-e-input-border);
    border-radius: 22px;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    background: var(--frai-e-input-bg);
    color: var(--frai-e-text);
    transition: border-color var(--frai-e-transition);
}

.frai-embed-input input::placeholder {
    color: var(--frai-e-text-secondary);
}

.frai-embed-input input:focus {
    border-color: var(--frai-e-input-focus);
    background: var(--frai-e-input-bg);
    color: var(--frai-e-text);
}

.frai-embed-input input:-webkit-autofill,
.frai-embed-input input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--frai-e-input-bg) inset;
    -webkit-text-fill-color: var(--frai-e-text);
    transition: background-color 5000s ease-in-out 0s;
}

.frai-embed-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--frai-e-send-btn);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--frai-e-transition), transform var(--frai-e-transition);
}

.frai-embed-send-btn:hover:not(:disabled) {
    background: var(--frai-e-send-btn-hover);
    transform: scale(1.05);
}

.frai-embed-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.frai-embed-send-btn.frai-embed-loading {
    cursor: wait;
    transform: none;
}

.frai-embed-send-btn svg {
    width: 18px;
    height: 18px;
}

/* ───────────────────────────────────────────────────────────
   Responsive
   ─────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .frai-embed-welcome-heading {
        font-size: 19px;
    }

    .frai-embed-action {
        padding: 8px 10px;
        gap: 10px;
    }

    .frai-embed-msg .frai-embed-text {
        max-width: 92%;
    }

    .frai-embed-input input {
        font-size: 16px;
    }
}
