/* ═══════════════════════════════════════════════════════════
   AAMAQ AI CHATBOT — Brutalist Design System
   ═══════════════════════════════════════════════════════════ */

/* ── Floating Button ── */
#aamaq-chat-toggle {
    position: fixed;
    bottom: 28px;
    left: 28px;
    z-index: 9999;
    width: 64px;
    height: 64px;
    background: var(--accent-cyan, #00D2FF);
    border: 3px solid var(--border-color, #0A0E27);
    box-shadow: 5px 5px 0px var(--border-color, #0A0E27);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    padding: 0;
}

#aamaq-chat-toggle:hover {
    transform: translate(-3px, -3px);
    box-shadow: 8px 8px 0px var(--border-color, #0A0E27);
}

#aamaq-chat-toggle:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px var(--border-color, #0A0E27);
}

#aamaq-chat-toggle svg {
    width: 30px;
    height: 30px;
    fill: var(--border-color, #0A0E27);
    transition: transform 0.3s ease;
}

#aamaq-chat-toggle.active svg {
    transform: rotate(90deg);
}

/* Pulse ring animation */
#aamaq-chat-toggle::before {
    content: '';
    position: absolute;
    inset: -6px;
    border: 2px solid var(--accent-cyan, #00D2FF);
    opacity: 0;
    animation: chatPulse 2.5s ease-in-out infinite;
}

#aamaq-chat-toggle.active::before {
    animation: none;
    opacity: 0;
}

@keyframes chatPulse {
    0% { opacity: 0; transform: scale(0.95); }
    50% { opacity: 0.6; transform: scale(1.05); }
    100% { opacity: 0; transform: scale(1.15); }
}

/* Tooltip next to toggle */
#aamaq-chat-toggle .chat-tooltip {
    position: absolute;
    left: calc(100% + 15px);
    background: var(--bg-dark, #0A0E27);
    color: white;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 800;
    white-space: nowrap;
    border: 2px solid var(--border-color, #0A0E27);
    box-shadow: 4px 4px 0px var(--accent-cyan, #00D2FF);
    pointer-events: none;
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    animation: tooltip-slide-in 0.5s ease 1s forwards;
    display: flex;
    align-items: center;
    font-family: var(--font-arabic, 'Tajawal', sans-serif);
}

/* Tooltip Pointer */
#aamaq-chat-toggle .chat-tooltip::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-right: 7px solid var(--border-color, #0A0E27);
}

#aamaq-chat-toggle .chat-tooltip::after {
    content: '';
    position: absolute;
    left: -5px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 5px solid var(--bg-dark, #0A0E27);
}

@keyframes tooltip-slide-in {
    0% { opacity: 0; transform: translateX(-10px); }
    100% { opacity: 1; transform: translateX(0); }
}

#aamaq-chat-toggle:hover .chat-tooltip {
    opacity: 1;
    transform: translateX(0);
    animation: none;
}

/* Notification dot */
#aamaq-chat-toggle .chat-notif {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background: #FF3333;
    border: 2px solid var(--border-color, #0A0E27);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 900;
    color: white;
    animation: brutal-bounce 1s ease infinite;
}

@keyframes brutal-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* ── Chat Window ── */
#aamaq-chat-window {
    position: fixed;
    bottom: 104px;
    left: 28px;
    z-index: 9998;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--bg-secondary, #FFFFFF);
    border: 3px solid var(--border-color, #0A0E27);
    box-shadow: 8px 8px 0px var(--border-color, #0A0E27);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

#aamaq-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ── Chat Header ── */
.aamaq-chat-header {
    background: var(--bg-dark, #0A0E27);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 3px solid var(--border-color, #0A0E27);
    flex-shrink: 0;
}

.aamaq-chat-header .chat-avatar {
    width: 40px;
    height: 40px;
    background: var(--accent-cyan, #00D2FF);
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.aamaq-chat-header .chat-avatar svg {
    width: 22px;
    height: 22px;
    fill: var(--border-color, #0A0E27);
}

.aamaq-chat-header .chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.aamaq-chat-header .agent-name {
    margin: 0;
    font-size: 16px;
    font-weight: 900;
    color: white;
    margin-bottom: 2px;
}

/* ── Agent Tabs ── */
.aamaq-agent-tabs {
    display: flex;
    border-bottom: 3px solid var(--border-color, #0A0E27);
    background: var(--bg-secondary, #FFFFFF);
    flex-shrink: 0;
}

.aamaq-agent-tabs .agent-tab {
    flex: 1;
    padding: 10px;
    background: var(--bg-primary, #F4F7FB);
    border: none;
    border-left: 3px solid var(--border-color, #0A0E27);
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    color: var(--text-primary, #0A0E27);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    outline: none;
}

.aamaq-agent-tabs .agent-tab:last-child {
    border-left: none;
}

.aamaq-agent-tabs .agent-tab:hover {
    background: rgba(0, 210, 255, 0.2);
}

.aamaq-agent-tabs .agent-tab.active {
    background: var(--accent-cyan, #00D2FF);
    color: var(--border-color, #0A0E27);
}

.aamaq-agent-tabs .agent-tab[data-agent="support"].active {
    background: #FF3366;
    color: white;
}

.aamaq-agent-tabs .agent-tab[data-agent="support"]:hover:not(.active) {
    background: rgba(255, 51, 102, 0.2);
}

.aamaq-chat-header .chat-info span {
    font-size: 11px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 5px;
}

.aamaq-chat-header .chat-info span::before {
    content: '';
    width: 7px;
    height: 7px;
    background: #00CC66;
    display: inline-block;
    border: 1px solid rgba(255,255,255,0.3);
}

.aamaq-chat-header .chat-close,
.aamaq-chat-header .chat-clear {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

.aamaq-chat-header .chat-clear svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.aamaq-chat-header .chat-close:hover,
.aamaq-chat-header .chat-clear:hover {
    background: rgba(255,255,255,0.15);
    border-color: white;
}

/* ── Messages Area ── */
.aamaq-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--bg-primary, #F4F7FB);
    scroll-behavior: smooth;
}

/* Custom scrollbar for messages */
.aamaq-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.aamaq-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.aamaq-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color, #0A0E27);
    border: 0;
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.7;
    position: relative;
    word-wrap: break-word;
    animation: msgSlideIn 0.3s ease;
}

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

.chat-msg.bot {
    align-self: flex-start;
    background: var(--bg-secondary, #FFFFFF);
    color: var(--text-primary, #0A0E27);
    border: 2px solid var(--border-color, #0A0E27);
    box-shadow: 3px 3px 0px var(--accent-cyan, #00D2FF);
    margin-left: 0;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--bg-dark, #0A0E27);
    color: white;
    border: 2px solid var(--border-color, #0A0E27);
    box-shadow: 3px 3px 0px var(--accent-cyan, #00D2FF);
    margin-right: 0;
}

.chat-msg .msg-time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 6px;
    display: block;
    font-weight: 600;
}

/* ── Typing Indicator ── */
.chat-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 20px;
    background: var(--bg-secondary, #FFFFFF);
    border: 2px solid var(--border-color, #0A0E27);
    box-shadow: 3px 3px 0px var(--accent-cyan, #00D2FF);
}

.chat-typing div span {
    width: 6px;
    height: 6px;
    background: var(--border-color, #0A0E27);
    display: inline-block;
    animation: typingDot 1.4s ease-in-out infinite;
    border-radius: 50%;
}

.chat-typing div span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing div span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Quick Actions ── */
.aamaq-chat-quick {
    padding: 10px 16px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    border-top: 2px solid rgba(10,14,39,0.1);
    background: var(--bg-secondary, #FFFFFF);
    flex-shrink: 0;
}

.aamaq-chat-quick button {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 700;
    background: var(--bg-primary, #F4F7FB);
    border: 2px solid var(--border-color, #0A0E27);
    color: var(--text-primary, #0A0E27);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
    box-shadow: 2px 2px 0px var(--border-color, #0A0E27);
    white-space: nowrap;
}

.aamaq-chat-quick button:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0px var(--border-color, #0A0E27);
    background: var(--accent-cyan, #00D2FF);
    color: var(--border-color, #0A0E27);
}

.aamaq-chat-quick button:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px var(--border-color, #0A0E27);
}

/* ── Input Area ── */
.aamaq-chat-input {
    padding: 14px 16px;
    display: flex;
    gap: 10px;
    border-top: 3px solid var(--border-color, #0A0E27);
    background: var(--bg-secondary, #FFFFFF);
    flex-shrink: 0;
    align-items: flex-end;
}

.aamaq-chat-input textarea {
    flex: 1;
    border: 2px solid var(--border-color, #0A0E27) !important;
    padding: 10px 14px !important;
    font-size: 14px;
    font-family: var(--font-arabic, 'Tajawal', sans-serif);
    resize: none;
    min-height: 42px;
    max-height: 100px;
    line-height: 1.5;
    background: var(--bg-primary, #F4F7FB) !important;
    color: var(--text-primary, #0A0E27);
    outline: none;
    transition: box-shadow 0.15s ease !important;
    transform: none !important;
    box-shadow: none !important;
}

.aamaq-chat-input textarea:focus {
    box-shadow: 3px 3px 0px var(--accent-cyan, #00D2FF) !important;
    border-color: var(--accent-cyan, #00D2FF) !important;
}

.aamaq-chat-input textarea::placeholder {
    color: var(--text-muted, #64748B);
    font-weight: 500;
}

.aamaq-chat-input button {
    width: 44px;
    height: 42px;
    background: var(--accent-cyan, #00D2FF);
    border: 2px solid var(--border-color, #0A0E27);
    box-shadow: 3px 3px 0px var(--border-color, #0A0E27);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, box-shadow 0.1s;
    flex-shrink: 0;
    padding: 0;
}

.aamaq-chat-input button:hover {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0px var(--border-color, #0A0E27);
}

.aamaq-chat-input button:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px var(--border-color, #0A0E27);
}

.aamaq-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.aamaq-chat-input button svg {
    width: 20px;
    height: 20px;
    fill: var(--border-color, #0A0E27);
    transform: scaleX(-1); /* Flip for RTL send arrow */
}

/* ── Powered By Footer ── */
.aamaq-chat-powered {
    padding: 6px 16px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted, #64748B);
    background: var(--bg-secondary, #FFFFFF);
    border-top: 1px solid rgba(10,14,39,0.08);
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.aamaq-chat-powered a {
    color: var(--accent-cyan, #00D2FF);
    text-decoration: none;
    font-weight: 800;
}

/* ═══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    #aamaq-chat-toggle {
        bottom: 20px;
        left: 20px;
        width: 56px;
        height: 56px;
    }

    #aamaq-chat-toggle svg {
        width: 26px;
        height: 26px;
    }

    #aamaq-chat-window {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border: none;
        box-shadow: none;
    }

    #aamaq-chat-window.open {
        border-top: 3px solid var(--border-color, #0A0E27);
    }

    .aamaq-chat-header {
        padding: 14px 16px;
    }

    /* Hide the floating toggle on mobile when chat is open — header X is enough */
    #aamaq-chat-toggle.active {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   DARK MODE SUPPORT (if ever needed)
   ═══════════════════════════════════════════════════════════ */

@media (prefers-color-scheme: dark) {
    /* Keep brutalist dark theme consistent */
}
