/* ===================================
   iBUL Chatbot Widget
   =================================== */

:root {
    --ibul-primary: #6366f1;
    --ibul-radius: 16px;
    --ibul-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    --ibul-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Reset */
#ibul-chatbot,
#ibul-chatbot * {
    box-sizing: border-box;
    margin: 0;
    font-family: var(--ibul-font);
    -webkit-font-smoothing: antialiased;
}

/* Container */
.ibul-chatbot {
    position: fixed;
    z-index: 999999;
    bottom: 24px;
}

.ibul-chatbot--bottom-right {
    right: 24px;
}

.ibul-chatbot--bottom-left {
    left: 24px;
}

/* Hide on mobile */
.ibul-chatbot[data-hide-mobile="true"] {
    display: none !important;
}

@media (min-width: 768px) {
    .ibul-chatbot[data-hide-mobile="true"] {
        display: block !important;
    }
}

/* ===================================
   Bubble
   =================================== */
.ibul-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ibul-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
    position: relative;
}

.ibul-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.25);
}

.ibul-bubble:active {
    transform: scale(0.95);
}

.ibul-bubble__icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ibul-bubble__icon svg {
    stroke: #fff;
}

/* Notification dot */
.ibul-bubble--has-notification::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: ibul-pulse 2s infinite;
}

@keyframes ibul-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===================================
   Chat Window
   =================================== */
.ibul-chat-window {
    position: absolute;
    bottom: 76px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: var(--ibul-radius);
    box-shadow: var(--ibul-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: ibul-slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.ibul-chatbot--bottom-right .ibul-chat-window {
    right: 0;
}

.ibul-chatbot--bottom-left .ibul-chat-window {
    left: 0;
}

.ibul-chat-window.ibul-chat-window--open {
    display: flex;
}

@keyframes ibul-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile full-screen */
@media (max-width: 480px) {
    .ibul-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        /* Use dvh (dynamic viewport height) so keyboard doesn't overlap */
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        z-index: 1000000;
        /* Account for iOS safe areas (notch, home bar) */
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .ibul-chat-window--open ~ .ibul-bubble {
        display: none;
    }

    /* Ensure input area stays above keyboard */
    .ibul-chat-input {
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }
}

/* ===================================
   Header
   =================================== */
.ibul-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--ibul-primary);
    color: #fff;
    flex-shrink: 0;
}

.ibul-chat-header__info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ibul-chat-header__avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ibul-chat-header__avatar svg {
    stroke: #fff;
}

.ibul-chat-header__name {
    display: block;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}

.ibul-chat-header__status {
    display: block;
    font-size: 11px;
    opacity: 0.8;
    line-height: 1.2;
    margin-top: 2px;
}

.ibul-chat-header__status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 4px;
    vertical-align: middle;
}

.ibul-chat-header__actions {
    display: flex;
    gap: 4px;
}

.ibul-chat-header__btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: background 0.2s;
}

.ibul-chat-header__btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ibul-chat-header__btn svg {
    stroke: #fff;
}

/* ===================================
   Messages
   =================================== */
.ibul-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f9fafb;
}

.ibul-chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.ibul-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.ibul-msg {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.6;
    word-break: break-word;
    animation: ibul-msg-in 0.25s ease-out;
    letter-spacing: 0.01em;
}

@keyframes ibul-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ibul-msg--bot {
    background: #fff;
    color: #374151;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #e5e7eb;
}

.ibul-msg a {
    color: var(--ibul-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    transition: opacity 0.15s;
}

.ibul-msg a:hover {
    opacity: 0.75;
}

.ibul-msg--user a {
    color: #fff;
}

.ibul-msg--user {
    background: var(--ibul-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ibul-msg--typing {
    background: #fff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #e5e7eb;
    padding: 14px 20px;
}

.ibul-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ibul-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: ibul-typing 1.4s infinite;
}

.ibul-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ibul-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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


/* Error message */
.ibul-msg--error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    align-self: center;
    font-size: 12px;
    text-align: center;
    max-width: 90%;
}

/* ===================================
   Input
   =================================== */
.ibul-chat-input {
    padding: 14px 18px 10px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}

#ibul-chat-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

#ibul-chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 11px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f9fafb;
    color: #111827;
}

#ibul-chat-input:focus {
    border-color: var(--ibul-primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12);
    background: #fff;
}

#ibul-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--ibul-primary);
    color: #fff;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, opacity 0.2s, transform 0.15s;
}

#ibul-send-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.05);
}

#ibul-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#ibul-send-btn svg {
    stroke: #fff;
}

/* Powered by */
.ibul-chat-powered {
    text-align: center;
    font-size: 10px;
    color: #c0c0c0;
    padding: 6px 0 2px;
}

.ibul-chat-powered a {
    color: #9ca3af;
    text-decoration: none;
    font-weight: 600;
}

.ibul-chat-powered a:hover {
    color: var(--ibul-primary);
}
