/* ============================================
   e-Kiblat AI Chatbot (Soalan Lazim)
   Uses landing.css tokens (--landing-*)
   ============================================ */
.ekb-chat {
    --chat-primary: var(--landing-primary, #1B5E3B);
    --chat-primary-light: var(--landing-primary-light, #2D7D46);
    --chat-accent: var(--landing-accent, #C9A84C);
    --chat-dark: var(--landing-dark, #0D2818);
    --chat-text: var(--landing-text, #1a2e22);
    --chat-muted: var(--landing-text-muted, #526b5c);
    --chat-surface-alt: var(--landing-surface-alt, #F4F9F5);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---------- Floating launcher ---------- */
.ekb-chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1100;
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-primary-light), var(--chat-primary));
    box-shadow: 0 10px 30px rgba(13, 40, 24, 0.35), 0 0 0 3px rgba(201, 168, 76, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.ekb-chat-launcher:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 14px 36px rgba(13, 40, 24, 0.45), 0 0 0 4px rgba(201, 168, 76, 0.75);
}

.ekb-chat-launcher i {
    font-size: 1.9rem;
    color: #fff;
    transition: transform 0.3s ease, opacity 0.2s ease;
}

.ekb-chat-launcher .ekb-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.ekb-chat.open .ekb-chat-launcher .ekb-icon-open {
    opacity: 0;
    transform: rotate(90deg);
}

.ekb-chat.open .ekb-chat-launcher .ekb-icon-close {
    opacity: 1;
    transform: rotate(0);
}

/* Pulse ring to draw attention (stops once opened) */
.ekb-chat-launcher::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--chat-accent);
    animation: ekbPulse 2.4s ease-out infinite;
    pointer-events: none;
}

.ekb-chat.opened-once .ekb-chat-launcher::after {
    display: none;
}

@keyframes ekbPulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.55); opacity: 0; }
}

/* Teaser bubble */
.ekb-chat-teaser {
    position: fixed;
    right: 98px;
    bottom: 36px;
    z-index: 1100;
    max-width: 230px;
    padding: 10px 14px;
    border-radius: 14px 14px 4px 14px;
    background: #fff;
    color: var(--chat-text);
    font-size: 0.85rem;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(13, 40, 24, 0.2);
    animation: ekbFadeUp 0.4s ease both;
    animation-delay: 1.2s;
    cursor: pointer;
}

.ekb-chat.opened-once .ekb-chat-teaser {
    display: none;
}

/* ---------- Panel ---------- */
.ekb-chat-panel {
    position: fixed;
    right: 24px;
    bottom: 100px;
    z-index: 1100;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 130px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    border: 1px solid rgba(27, 94, 59, 0.12);
    box-shadow: 0 24px 60px rgba(13, 40, 24, 0.35);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.ekb-chat.open .ekb-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ekb-chat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-dark) 0%, var(--chat-primary) 100%);
}

.ekb-chat-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--chat-accent), transparent);
}

.ekb-chat-avatar {
    position: relative;
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ekb-chat-avatar img {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.ekb-chat-header-text {
    flex: 1;
    min-width: 0;
}

.ekb-chat-title {
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.2;
}

.ekb-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.75);
}

.ekb-chat-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

.ekb-chat-icon-btn {
    border: none;
    background: rgba(255, 255, 255, 0.1);
    width: 34px;
    height: 34px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.ekb-chat-icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ekb-chat-icon-btn i {
    color: #fff;
    font-size: 1.15rem;
}

/* Messages */
.ekb-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 8px;
    background:
        radial-gradient(circle at 100% 0%, rgba(201, 168, 76, 0.08), transparent 40%),
        var(--chat-surface-alt);
    scroll-behavior: smooth;
}

.ekb-chat-body::-webkit-scrollbar {
    width: 6px;
}

.ekb-chat-body::-webkit-scrollbar-thumb {
    background: rgba(27, 94, 59, 0.2);
    border-radius: 3px;
}

.ekb-msg {
    display: flex;
    margin-bottom: 12px;
    animation: ekbFadeUp 0.25s ease both;
}

.ekb-msg.user {
    justify-content: flex-end;
}

.ekb-msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 0.88rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.ekb-msg.bot .ekb-msg-bubble {
    color: var(--chat-text);
    background: #fff;
    border: 1px solid rgba(27, 94, 59, 0.08);
    border-radius: 4px 16px 16px 16px;
    box-shadow: 0 2px 8px rgba(13, 40, 24, 0.05);
}

.ekb-msg.user .ekb-msg-bubble {
    color: #fff;
    background: linear-gradient(135deg, var(--chat-primary-light), var(--chat-primary));
    border-radius: 16px 4px 16px 16px;
}

.ekb-msg.error .ekb-msg-bubble {
    color: #8a2a1f;
    background: #fdf0ee;
    border-color: rgba(176, 52, 38, 0.18);
}

.ekb-msg-bubble p { margin: 0 0 6px; }
.ekb-msg-bubble p:last-child { margin-bottom: 0; }
.ekb-msg-bubble ul,
.ekb-msg-bubble ol { margin: 4px 0 6px; padding-left: 18px; }
.ekb-msg-bubble li { margin-bottom: 3px; }
.ekb-msg-bubble strong { font-weight: 700; }
.ekb-msg-bubble a { color: var(--chat-primary); font-weight: 600; text-decoration: underline; }
.ekb-msg.user .ekb-msg-bubble a { color: #fff; }

/* Typing indicator */
.ekb-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 2px;
}

.ekb-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-primary-light);
    opacity: 0.4;
    animation: ekbBounce 1.2s infinite ease-in-out;
}

.ekb-typing span:nth-child(2) { animation-delay: 0.15s; }
.ekb-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ekbBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Suggestion chips */
.ekb-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 2px 0 12px;
}

.ekb-suggestions-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--chat-muted);
    margin-bottom: 2px;
}

.ekb-chip {
    align-self: flex-start;
    max-width: 100%;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid rgba(27, 94, 59, 0.25);
    background: #fff;
    color: var(--chat-primary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.ekb-chip:hover {
    background: rgba(27, 94, 59, 0.06);
    border-color: var(--chat-accent);
    transform: translateX(3px);
}

/* Input */
.ekb-chat-footer {
    padding: 12px 14px 10px;
    background: #fff;
    border-top: 1px solid rgba(27, 94, 59, 0.08);
}

.ekb-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 14px;
    border-radius: 14px;
    border: 1.5px solid rgba(27, 94, 59, 0.15);
    background: var(--chat-surface-alt);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ekb-chat-form:focus-within {
    border-color: var(--chat-primary-light);
    box-shadow: 0 0 0 3px rgba(45, 125, 70, 0.12);
}

.ekb-chat-input {
    flex: 1;
    min-height: 24px;
    max-height: 110px;
    padding: 6px 0;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--chat-text);
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
}

.ekb-chat-input::placeholder {
    color: #8aa093;
}

.ekb-chat-send {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--chat-primary-light), var(--chat-primary));
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ekb-chat-send:hover:not(:disabled) {
    transform: scale(1.06);
}

.ekb-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ekb-chat-send i {
    color: #fff;
    font-size: 1.15rem;
}

.ekb-chat-disclaimer {
    margin-top: 7px;
    text-align: center;
    font-size: 0.68rem;
    color: #8aa093;
}

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

/* ---------- Mobile ---------- */
@media (max-width: 575px) {
    .ekb-chat-launcher {
        right: 16px;
        bottom: 16px;
        width: 56px;
        height: 56px;
    }

    .ekb-chat-teaser {
        right: 82px;
        bottom: 24px;
    }

    .ekb-chat-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .ekb-chat.open .ekb-chat-launcher {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ekb-chat *,
    .ekb-chat *::before,
    .ekb-chat *::after {
        animation: none !important;
        transition: none !important;
    }
}
