/**
 * AI Chat Demo — scoped to .ai-chat-app only (ai.php)
 */

.ai-chat-app {
    --ai-accent: #7c3aed;
    --ai-accent-dark: #6d28d9;
    --ai-accent-soft: #ede9fe;
    --ai-accent-glow: rgba(124, 58, 237, 0.18);
    --ai-user-bg: linear-gradient(135deg, #0055ff 0%, #7c3aed 100%);
    --ai-bot-bg: #f4f4f8;
    --ai-bot-border: #e8e8f0;
    --ai-surface: #ffffff;
    --ai-header-bg: linear-gradient(135deg, #1a0d3b 0%, #4c1d95 55%, #7c3aed 100%);
    --ai-text: #1e1e2e;
    --ai-text-muted: #6b7280;
    --ai-radius: 20px;
    --ai-radius-sm: 14px;
    --ai-h: min(720px, 85vh);
    --ai-shadow: 0 24px 64px rgba(26, 13, 59, 0.14), 0 4px 16px rgba(0, 0, 0, 0.06);
    --ai-font: 'Plus Jakarta Sans', "Tajawal", system-ui, sans-serif;

    font-family: var(--ai-font);
    max-width: 860px;
    margin: 0 auto;
    border-radius: calc(var(--ai-radius) + 4px);
    background: var(--ai-surface);
    border: 1px solid rgba(124, 58, 237, 0.12);
    box-shadow: var(--ai-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: var(--ai-h);
}

/* Header */
.ai-chat-app__header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 22px;
    background: var(--ai-header-bg);
    color: #fff;
    flex-shrink: 0;
}

.ai-chat-app__avatar {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.35), rgba(0, 85, 255, 0.25));
    border: 1px solid rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    backdrop-filter: blur(8px);
    color: #e9d5ff;
}

.ai-chat-app__meta {
    flex: 1;
    min-width: 0;
}

.ai-chat-app__meta h3 {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.ai-chat-app__status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .78rem;
    color: rgba(255, 255, 255, 0.72);
    font-weight: 500;
}

.ai-chat-app__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
    animation: aiChatPulse 2s ease-in-out infinite;
}

@keyframes aiChatPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

.ai-chat-app__badge {
    padding: 5px 10px;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
}

/* Messages area */
.ai-chat-app__body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(124, 58, 237, 0.06), transparent),
        #fafafa;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb {
    background: rgba(124, 58, 237, 0.25);
    border-radius: 999px;
}

/* Welcome state */
.ai-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 12px 16px 8px;
    animation: aiChatFadeIn 0.45s ease;
}

.ai-chat-welcome.is-hidden { display: none; }

.ai-chat-welcome__icon {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--ai-accent-soft), #e0e7ff);
    color: var(--ai-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    margin-bottom: 14px;
}

.ai-chat-welcome p {
    margin: 0 0 18px;
    max-width: 420px;
    font-size: .92rem;
    line-height: 1.65;
    color: var(--ai-text-muted);
}

.ai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
}

.ai-chat-suggest {
    padding: 9px 14px;
    border-radius: 999px;
    border: 1px solid var(--ai-bot-border);
    background: var(--ai-surface);
    color: var(--ai-text);
    font-size: .82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.2s, box-shadow 0.2s;
}

.ai-chat-suggest:hover {
    border-color: rgba(124, 58, 237, 0.35);
    background: var(--ai-accent-soft);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--ai-accent-glow);
}

.ai-chat-caps {
    width: 100%;
    max-width: 420px;
    margin: 0 auto 18px;
    padding: 14px 16px;
    border-radius: var(--ai-radius-sm);
    background: rgba(124, 58, 237, 0.06);
    border: 1px dashed rgba(124, 58, 237, 0.22);
    text-align: start;
}

.ai-chat-caps__title {
    margin: 0 0 10px;
    font-size: .82rem;
    font-weight: 700;
    color: var(--ai-text);
}

.ai-chat-caps__list {
    list-style: none;
    margin: 0 0 10px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chat-caps__list li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: .8rem;
    color: var(--ai-text-muted);
    line-height: 1.5;
}

.ai-chat-caps__list li i {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--ai-accent-soft);
    color: var(--ai-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: .75rem;
}

.ai-chat-caps__note {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    color: var(--ai-accent);
    background: rgba(124, 58, 237, 0.1);
}

/* Message bubbles */
.ai-chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 88%;
    animation: aiChatFadeIn 0.3s ease;
}

.ai-chat-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-chat-msg--bot {
    align-self: flex-start;
}

.ai-chat-msg__avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .78rem;
    flex-shrink: 0;
}

.ai-chat-msg__avatar--bot {
    background: linear-gradient(135deg, var(--ai-accent-soft), #e0e7ff);
    color: var(--ai-accent);
}

.ai-chat-msg__avatar--user {
    background: #e0e7ff;
    color: #0055ff;
}

.ai-chat-msg__bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: .92rem;
    line-height: 1.75;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.ai-chat-msg--bot .ai-chat-msg__bubble {
    background: var(--ai-bot-bg);
    border: 1px solid var(--ai-bot-border);
    color: var(--ai-text);
    border-end-start-radius: 6px;
}

.ai-chat-msg--user .ai-chat-msg__bubble {
    background: var(--ai-user-bg);
    color: #fff;
    border-end-end-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 85, 255, 0.22);
}

.ai-chat-msg__bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: .85em;
}

.ai-chat-msg--user .ai-chat-msg__bubble code {
    background: rgba(255, 255, 255, 0.18);
}

.ai-chat-msg__bubble h3,
.ai-chat-msg__bubble h4 {
    margin: 0 0 6px;
    font-size: 1em;
}

.ai-chat-msg__bubble .ai-chat-para {
    margin: 0 0 10px;
}

.ai-chat-msg__bubble .ai-chat-para:last-child {
    margin-bottom: 0;
}

.ai-chat-list {
    margin: 0 0 12px;
    padding-inline-start: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chat-list li {
    line-height: 1.65;
}

.ai-chat-list li::marker {
    color: var(--ai-accent);
}

.ai-chat-heading {
    margin: 0 0 8px;
    font-size: .95rem;
    font-weight: 700;
}

/* Typing */
.ai-chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.ai-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ai-accent);
    opacity: 0.35;
    animation: aiChatBounce 1.2s ease-in-out infinite;
}

.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aiChatBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30% { transform: translateY(-5px); opacity: 1; }
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-inline-start: 2px;
    vertical-align: text-bottom;
    background: var(--ai-accent);
    animation: aiChatBlink 0.9s step-end infinite;
}

@keyframes aiChatBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes aiChatFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* Composer */
.ai-chat-app__composer {
    flex-shrink: 0;
    padding: 14px 16px 16px;
    background: var(--ai-surface);
    border-top: 1px solid var(--ai-bot-border);
}

#input-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 14px;
    background: #f8f8fc;
    border: 1.5px solid var(--ai-bot-border);
    border-radius: var(--ai-radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-chat-input-wrap:focus-within {
    border-color: rgba(124, 58, 237, 0.45);
    box-shadow: 0 0 0 4px var(--ai-accent-glow);
    background: #fff;
}

#user-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 6px 0;
    font-family: inherit;
    font-size: .92rem;
    line-height: 1.5;
    color: var(--ai-text);
    outline: none;
}

#user-input::placeholder { color: #9ca3af; }

.ai-chat-input-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.ai-chat-btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--ai-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s, color 0.2s;
}

.ai-chat-btn-icon:hover {
    background: var(--ai-accent-soft);
    color: var(--ai-accent);
}

.ai-chat-btn-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: var(--ai-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 14px var(--ai-accent-glow);
}

.ai-chat-btn-send:hover:not(:disabled) {
    background: var(--ai-accent-dark);
    transform: scale(1.04);
}

.ai-chat-btn-send.is-stop {
    background: #ef4444;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.28);
}

.ai-chat-btn-send.is-stop:hover:not(:disabled) {
    background: #dc2626;
}

.ai-chat-btn-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

/* RTL */
body[dir="rtl"] .ai-chat-msg--bot .ai-chat-msg__bubble {
    border-end-start-radius: 18px;
    border-end-end-radius: 6px;
}

body[dir="rtl"] .ai-chat-msg--user .ai-chat-msg__bubble {
    border-end-end-radius: 18px;
    border-end-start-radius: 6px;
}

@media (max-width: 640px) {
    .ai-chat-app {
        --ai-h: min(700px, 88vh);
        border-radius: var(--ai-radius);
    }

    .ai-chat-app__header { padding: 14px 16px; }
    .ai-chat-app__badge { display: none; }
    #messages { padding: 16px 14px; }
    .ai-chat-msg { max-width: 94%; }
    .ai-chat-suggest { font-size: .78rem; padding: 8px 12px; }
}
