/* SafeZone AI — Public chatbot widget
 * Premium dark, mobile-responsive, RTL-aware.
 * Scoped under .szai-* so it never collides with theme styles.
 * ---------------------------------------------------------------- */

#szai-root,
#szai-root * {
    box-sizing: border-box;
}

#szai-root {
    --szai-bg:        #0b1220;
    --szai-bg-2:      #111a2c;
    --szai-bg-3:      #1a2540;
    --szai-border:    #243352;
    --szai-text:      #e6edf7;
    --szai-text-2:    #98a6c2;
    --szai-muted:     #6a7898;
    --szai-primary:   #22d3ee;
    --szai-primary-2: #38bdf8;
    --szai-accent:    #c084fc;
    --szai-success:   #4ade80;
    --szai-warn:      #fbbf24;
    --szai-danger:    #ef4444;
    --szai-radius:    14px;
    --szai-shadow:    0 18px 48px rgba(2,8,23,0.55);
    --szai-font:      -apple-system, BlinkMacSystemFont, "Segoe UI", "Tajawal", system-ui, sans-serif;
    --szai-mono:      "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ============================ Launcher ============================ */
.szai-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99998;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border: 0;
    cursor: pointer;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--szai-primary), var(--szai-primary-2));
    color: #062a35;
    font-family: var(--szai-font);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.2px;
    box-shadow: 0 14px 36px rgba(34,211,238,0.35), 0 0 0 1px rgba(34,211,238,0.4);
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}
.szai-launcher.szai-pos-left { right: auto; left: 24px; }
.szai-launcher:hover { transform: translateY(-2px); box-shadow: 0 18px 44px rgba(34,211,238,0.45); }
.szai-launcher .szai-launcher-icon { font-size: 18px; }
.szai-launcher.szai-hidden { opacity: 0; pointer-events: none; transform: scale(0.8); }
.szai-launcher .szai-pulse {
    position: absolute;
    top: -4px; right: -4px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--szai-success);
    box-shadow: 0 0 0 0 rgba(74,222,128,0.75);
    animation: szai-pulse 2s infinite;
}
.szai-launcher.szai-pos-left .szai-pulse { right: auto; left: -4px; }
@keyframes szai-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(74,222,128,0.7); }
    70%  { box-shadow: 0 0 0 10px rgba(74,222,128,0); }
    100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

/* ============================ Panel ============================ */
.szai-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 48px);
    background: var(--szai-bg);
    color: var(--szai-text);
    border: 1px solid var(--szai-border);
    border-radius: var(--szai-radius);
    box-shadow: var(--szai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--szai-font);
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s cubic-bezier(.2,.8,.2,1), opacity 0.18s ease;
}
.szai-panel.szai-pos-left { right: auto; left: 24px; }
.szai-panel.szai-open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }
.szai-panel.szai-rtl { direction: rtl; }

/* ============================ Header ============================ */
.szai-header {
    flex: 0 0 auto;
    padding: 14px 16px;
    background: linear-gradient(135deg, #0d1626 0%, #122140 100%);
    border-bottom: 1px solid var(--szai-border);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}
.szai-header::after {
    content: '';
    position: absolute;
    inset: auto 0 -1px 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--szai-primary), var(--szai-accent), transparent);
    opacity: 0.7;
}
.szai-avatar {
    flex: 0 0 auto;
    width: 38px; height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--szai-primary), var(--szai-accent));
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #042027;
    box-shadow: 0 6px 16px rgba(34,211,238,0.35);
    position: relative;
}
.szai-avatar::after {
    content: '';
    position: absolute;
    bottom: -2px; right: -2px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--szai-success);
    box-shadow: 0 0 0 2px var(--szai-bg);
}
.szai-header-text { flex: 1; min-width: 0; }
.szai-header-title { font-size: 14px; font-weight: 700; line-height: 1.2; }
.szai-header-sub   { font-size: 11.5px; color: var(--szai-text-2); margin-top: 2px; line-height: 1.3; }
.szai-header-actions { display: flex; gap: 6px; }
.szai-icon-btn {
    width: 30px; height: 30px;
    border: 0;
    background: rgba(255,255,255,0.04);
    border-radius: 8px;
    color: var(--szai-text-2);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px;
}
.szai-icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--szai-text); }

/* ============================ Body ============================ */
.szai-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 14px 6px;
    background: radial-gradient(ellipse at top, rgba(34,211,238,0.04), transparent 60%), var(--szai-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--szai-border) transparent;
}
.szai-body::-webkit-scrollbar { width: 6px; }
.szai-body::-webkit-scrollbar-thumb { background: var(--szai-border); border-radius: 3px; }

.szai-msg {
    max-width: 84%;
    margin-bottom: 8px;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: szai-msg-in 0.22s ease;
}
@keyframes szai-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.szai-msg.szai-bot,
.szai-msg.szai-admin {
    background: var(--szai-bg-2);
    border: 1px solid var(--szai-border);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    margin-right: auto;
}
.szai-panel.szai-rtl .szai-msg.szai-bot,
.szai-panel.szai-rtl .szai-msg.szai-admin {
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
    margin-right: 0; margin-left: auto;
}
.szai-msg.szai-admin {
    border-color: rgba(192,132,252,0.4);
    box-shadow: 0 0 0 1px rgba(192,132,252,0.15);
}
.szai-msg.szai-admin::before {
    content: '👤 SafeZone Team';
    display: block;
    font-size: 10.5px;
    color: var(--szai-accent);
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.szai-msg.szai-visitor {
    background: linear-gradient(135deg, var(--szai-primary), var(--szai-primary-2));
    color: #062a35;
    border-bottom-right-radius: 4px;
    margin-left: auto;
    font-weight: 500;
}
.szai-panel.szai-rtl .szai-msg.szai-visitor {
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
    margin-left: 0; margin-right: auto;
}
.szai-msg.szai-system {
    background: transparent;
    border: 1px dashed var(--szai-border);
    color: var(--szai-muted);
    font-size: 11.5px;
    text-align: center;
    margin: 6px auto;
    padding: 6px 10px;
    border-radius: 999px;
    max-width: 70%;
}
.szai-msg a { color: var(--szai-primary); text-decoration: underline; }
.szai-msg.szai-visitor a { color: #042027; }
.szai-msg b, .szai-msg strong { color: var(--szai-primary); }
.szai-msg.szai-visitor b, .szai-msg.szai-visitor strong { color: #042027; }

.szai-msg-time {
    font-size: 10px;
    opacity: 0.55;
    margin-top: 4px;
}
.szai-msg-upload {
    display: flex; gap: 8px; align-items: center;
    background: rgba(34,211,238,0.08);
    border: 1px solid rgba(34,211,238,0.25);
    border-radius: 10px;
    padding: 8px 10px;
}
.szai-msg-upload-thumb {
    width: 42px; height: 42px;
    border-radius: 8px;
    background: var(--szai-bg-3);
    background-size: cover;
    background-position: center;
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.szai-msg-upload-meta { flex: 1; min-width: 0; }
.szai-msg-upload-name { font-size: 12px; font-weight: 600; color: var(--szai-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.szai-msg-upload-size { font-size: 11px; color: var(--szai-muted); }

/* ============================ Typing ============================ */
.szai-typing {
    display: inline-flex; gap: 4px; padding: 8px 12px;
    background: var(--szai-bg-2); border: 1px solid var(--szai-border);
    border-radius: 14px; border-bottom-left-radius: 4px;
    margin-bottom: 8px;
}
.szai-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--szai-text-2);
    animation: szai-bounce 1s infinite;
}
.szai-typing span:nth-child(2) { animation-delay: 0.15s; }
.szai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes szai-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ============================ Quick replies ============================ */
.szai-quick {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 6px 12px 0;
}
.szai-quick-btn {
    background: rgba(34,211,238,0.08);
    border: 1px solid rgba(34,211,238,0.3);
    color: var(--szai-primary);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-family: var(--szai-font);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.szai-quick-btn:hover { background: var(--szai-primary); color: #062a35; }

/* ============================ Choice cards (click flow) ============================ */
.szai-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 6px 12px 4px;
}
.szai-choice {
    background: var(--szai-bg-2);
    border: 1px solid var(--szai-border);
    color: var(--szai-text);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-family: var(--szai-font);
    font-weight: 600;
    text-align: start;
    cursor: pointer;
    transition: all 0.15s;
}
.szai-choice:hover { background: var(--szai-bg-3); border-color: var(--szai-primary); transform: translateY(-1px); }

/* ============================ Form (lead capture) ============================ */
.szai-form {
    padding: 12px;
    background: var(--szai-bg-2);
    border: 1px solid var(--szai-border);
    border-radius: 12px;
    margin: 8px 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.szai-form input,
.szai-form textarea {
    width: 100%;
    background: var(--szai-bg);
    border: 1px solid var(--szai-border);
    color: var(--szai-text);
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
}
.szai-form input:focus,
.szai-form textarea:focus { outline: none; border-color: var(--szai-primary); }
.szai-form textarea { min-height: 60px; resize: vertical; }
.szai-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.szai-form-upload {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    background: rgba(34,211,238,0.05);
    border: 1px dashed rgba(34,211,238,0.4);
    border-radius: 8px;
    color: var(--szai-text-2);
    font-size: 12px;
    cursor: pointer;
}
.szai-form-upload:hover { background: rgba(34,211,238,0.1); color: var(--szai-text); }
.szai-form-upload input[type=file] { display: none; }
.szai-form-submit {
    background: linear-gradient(135deg, var(--szai-primary), var(--szai-primary-2));
    color: #062a35;
    border: 0;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 13.5px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.szai-form-submit:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(34,211,238,0.35); }
.szai-form-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================ Composer ============================ */
.szai-composer {
    flex: 0 0 auto;
    padding: 10px 12px;
    background: var(--szai-bg-2);
    border-top: 1px solid var(--szai-border);
    display: flex; align-items: center; gap: 8px;
}
.szai-composer input {
    flex: 1;
    background: var(--szai-bg);
    border: 1px solid var(--szai-border);
    color: var(--szai-text);
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 13.5px;
    font-family: inherit;
}
.szai-composer input:focus { outline: none; border-color: var(--szai-primary); }
.szai-composer-btn {
    width: 38px; height: 38px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--szai-primary), var(--szai-primary-2));
    color: #062a35;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: transform 0.15s;
}
.szai-composer-btn:hover { transform: scale(1.05); }
.szai-composer-attach {
    background: rgba(255,255,255,0.04);
    color: var(--szai-text-2);
}
.szai-composer-attach:hover { color: var(--szai-text); background: rgba(255,255,255,0.08); }
.szai-composer-attach input[type=file] { display: none; }

/* ============================ Footer ============================ */
.szai-footer {
    flex: 0 0 auto;
    padding: 6px 12px;
    border-top: 1px solid var(--szai-border);
    background: var(--szai-bg);
    text-align: center;
    font-size: 10.5px;
    color: var(--szai-muted);
    font-family: var(--szai-mono);
}
.szai-footer .szai-brand { color: var(--szai-primary); font-weight: 700; }

/* ============================ Mobile ============================ */
@media (max-width: 480px) {
    .szai-panel {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        bottom: 0; right: 0;
        border-radius: 0;
        border: 0;
    }
    .szai-launcher {
        bottom: 16px; right: 16px;
        padding: 11px 16px;
    }
    .szai-launcher .szai-launcher-text { display: none; }
    .szai-choices { grid-template-columns: 1fr; }
}
