/* ============================================================
   chat.alxfff.com — ALX FFF AI Chat
   Visual identity: identical tokens to the main website (alxfff.com)
   Mobile-first · RTL-ready · CSP-safe (no inline styles)
   ============================================================ */

:root {
    /* Brand tokens — copied from the main website */
    --bg-dark: #050A14;
    --bg-card: #0C1015;
    --bg-alt: #0A0F1A;
    --primary: #00D2FF;
    --secondary: #B026FF;
    --text-light: #FFFFFF;
    --text-gray: #AAAAAA;
    --border: #2A3645;
    /* Chat-specific tokens */
    --text-body: #D7DEE8;
    --ok-green: #22DD88;
    --danger: #FF5252;
    --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Outfit', 'Noto Sans Arabic', system-ui, sans-serif; }

html, body { height: 100%; overflow: hidden; }
body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    max-width: 100%;
}
a { text-decoration: none; }
button { font-family: inherit; }
textarea { font-family: inherit; }

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* ===== Top bar (compact brand header) ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: rgba(5, 10, 20, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.logo { color: var(--text-light); font-size: 1.25rem; font-weight: 800; white-space: nowrap; letter-spacing: 0.5px; }
.logo span { color: var(--primary); }
.title-block { flex: 1; min-width: 0; }
.title-block h1 { font-size: 1.02rem; font-weight: 600; line-height: 1.25; }
.status-line { display: flex; align-items: center; gap: 6px; color: var(--text-gray); font-size: 0.74rem; margin-top: 1px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok-green); box-shadow: 0 0 8px rgba(34, 221, 136, 0.7); flex-shrink: 0; animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 40px; padding: 0 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-gray);
    cursor: pointer;
    transition: 0.25s;
    font-size: 0.9rem;
    font-weight: 600;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--primary); border-color: var(--primary); box-shadow: 0 0 12px rgba(0, 210, 255, 0.25); }

/* ===== Conversation scroll area ===== */
.chat-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background:
        radial-gradient(1200px 500px at 50% -10%, rgba(0, 210, 255, 0.05), transparent 60%),
        radial-gradient(900px 400px at 90% 110%, rgba(176, 38, 255, 0.05), transparent 60%);
    scroll-behavior: smooth;
}
.messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 820px;
    margin: 0 auto;
    padding: 20px 14px 10px;
}

/* Message bubbles — dir="auto" per bubble handles mixed-language chats */
.msg {
    max-width: 88%;
    padding: 11px 15px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.msg.user {
    align-self: flex-end;
    background: linear-gradient(145deg, rgba(0, 210, 255, 0.14), rgba(176, 38, 255, 0.10));
    border: 1px solid rgba(0, 210, 255, 0.35);
    color: var(--text-light);
    border-bottom-right-radius: 4px;
}
.msg.bot {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-body);
    border-bottom-left-radius: 4px;
}
[dir="rtl"] .msg.user { border-bottom-right-radius: var(--radius); border-bottom-left-radius: 4px; }
[dir="rtl"] .msg.bot { border-bottom-left-radius: var(--radius); border-bottom-right-radius: 4px; }

.msg.error {
    align-self: stretch;
    background: rgba(255, 82, 82, 0.08);
    border: 1px solid rgba(255, 82, 82, 0.45);
    color: #FFB4AB;
    font-size: 0.9rem;
}

/* Streaming caret */
.msg.bot.streaming::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 15px;
    margin-inline-start: 4px;
    vertical-align: -2px;
    background: var(--primary);
    border-radius: 2px;
    animation: blink 0.9s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Typing indicator (three dots) */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); opacity: 0.4; animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; background: #587CFF; }
.typing span:nth-child(3) { animation-delay: 0.3s; background: var(--secondary); }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ===== Quick prompt chips ===== */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 820px;
    margin: 0 auto;
    padding: 6px 14px 18px;
}
.chips[hidden] { display: none; }
.chip {
    background: rgba(0, 210, 255, 0.06);
    border: 1px solid rgba(0, 210, 255, 0.3);
    color: #9FE9F7;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.25s;
}
.chip:hover { background: rgba(0, 210, 255, 0.12); box-shadow: 0 0 14px rgba(0, 210, 255, 0.25); transform: translateY(-1px); }

/* ===== Composer ===== */
.composer-wrap {
    flex-shrink: 0;
    background: var(--bg-alt);
    border-top: 1px solid var(--border);
    padding: 10px 12px calc(8px + env(safe-area-inset-bottom));
}
#composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 820px;
    margin: 0 auto;
}
#input {
    flex: 1;
    resize: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-light);
    font-size: 16px; /* 16px+ prevents iOS zoom-on-focus */
    line-height: 1.5;
    padding: 11px 14px;
    min-height: 46px;
    max-height: 132px;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
}
#input::placeholder { color: #6B7787; }
#input:focus { border-color: var(--primary); box-shadow: 0 0 12px rgba(0, 210, 255, 0.2); }
#sendBtn {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #0091B8);
    color: #001018;
    cursor: pointer;
    transition: 0.25s;
}
#sendBtn svg { width: 20px; height: 20px; }
/* Icon swap is class-driven: SVG elements ignore the hidden attribute/property */
#stopIcon { display: none; }
#sendBtn.stopping #stopIcon { display: block; }
#sendBtn.stopping #sendIcon { display: none; }
#sendBtn:hover { box-shadow: 0 0 16px rgba(0, 210, 255, 0.5); }
#sendBtn:disabled { background: var(--bg-card); color: #55606E; cursor: not-allowed; box-shadow: none; border: 1px solid var(--border); }
#sendBtn.stopping { background: linear-gradient(135deg, var(--secondary), #7B18BF); color: #fff; }
[dir="rtl"] #sendIcon { transform: scaleX(-1); }

/* ===== Foot row (disclaimer + social) ===== */
.foot-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    max-width: 820px;
    margin: 8px auto 0;
}
.disclaimer { color: #6B7787; font-size: 0.72rem; line-height: 1.4; flex: 1; }
.social-mini { display: flex; gap: 6px; flex-shrink: 0; }
.social-mini a {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-gray);
    transition: 0.25s;
}
.social-mini a:hover { color: var(--primary); border-color: var(--primary); }
.social-mini svg { width: 14px; height: 14px; }

/* ===== Scrollbar ===== */
.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Larger screens ===== */
@media (min-width: 720px) {
    .topbar { padding: 12px 24px; }
    .messages { padding: 26px 20px 12px; gap: 16px; }
    .msg { max-width: 76%; font-size: 1rem; }
    .chips { padding: 8px 20px 22px; }
    .composer-wrap { padding: 12px 20px calc(10px + env(safe-area-inset-bottom)); }
    .icon-btn { min-width: 44px; height: 42px; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    .status-dot, .typing span, .msg.bot.streaming::after { animation: none; }
    .chat-scroll { scroll-behavior: auto; }
    .chip, .icon-btn, #sendBtn { transition: none; }
    .sidebar { transition: none; }
}

/* ===== History sidebar (drawer) =====
   Slides from the inline-start edge (left in EN, right in AR) over a
   dimmed backdrop. visibility:hidden when closed -> out of tab order. */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: min(320px, 86vw);
    z-index: 60;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-inline-end: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform 0.28s ease, visibility 0s linear 0.28s;
}
[dir="rtl"] .sidebar {
    transform: translateX(104%);
}
.sidebar.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.28s ease;
}

.backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(2, 6, 12, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.sb-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
[dir="rtl"] .sb-head { padding: calc(10px + env(safe-area-inset-top)) 14px 10px 12px; }
.sb-head h2 { font-size: 0.95rem; font-weight: 600; }
.sb-close { min-width: 34px; height: 34px; padding: 0; }
.sb-close svg { width: 16px; height: 16px; }

.sb-new {
    margin: 12px 12px 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: linear-gradient(135deg, rgba(0, 210, 255, 0.14), rgba(176, 38, 255, 0.12));
    border: 1px solid rgba(0, 210, 255, 0.4);
    border-radius: 10px;
    color: #9FE9F7;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.25s;
    flex-shrink: 0;
}
.sb-new:hover { box-shadow: 0 0 14px rgba(0, 210, 255, 0.25); }
.sb-plus { font-size: 1.1rem; line-height: 1; }

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.session-list::-webkit-scrollbar { width: 6px; }
.session-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sb-empty { color: #6B7787; font-size: 0.85rem; text-align: center; padding: 26px 10px; }

.sess {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 6px 9px 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.2s;
}
[dir="rtl"] .sess { padding: 9px 10px 9px 6px; }
.sess:hover { background: rgba(0, 210, 255, 0.05); border-color: var(--border); }
.sess.active { background: rgba(0, 210, 255, 0.08); border-color: rgba(0, 210, 255, 0.35); }
.sess-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sess-title {
    font-size: 0.86rem;
    color: var(--text-body);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sess.active .sess-title { color: var(--text-light); font-weight: 600; }
.sess-date { font-size: 0.7rem; color: #6B7787; }

.sess-del {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #5A6675;
    cursor: pointer;
    transition: 0.2s;
    opacity: 0;
}
.sess:hover .sess-del, .sess-del:focus-visible { opacity: 1; }
@media (hover: none) { .sess-del { opacity: 0.75; } }
.sess-del:hover { color: var(--danger); background: rgba(255, 82, 82, 0.1); }
.sess-del svg { width: 14px; height: 14px; }

.sb-foot {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.sb-clear {
    width: 100%;
    padding: 9px;
    background: transparent;
    border: 1px solid rgba(255, 82, 82, 0.35);
    border-radius: 10px;
    color: #FF8A80;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.25s;
}
.sb-clear:hover { background: rgba(255, 82, 82, 0.1); }

/* Slightly tighter header now that it carries one more button */
@media (max-width: 380px) {
    .logo { font-size: 1.1rem; }
    .icon-btn { min-width: 36px; padding: 0 8px; }
}
