/* Rubidyum AI Assistant Styles */
:root {
    --ai-primary: #B8001F;
    --ai-primary-hover: #D60024;
    --ai-bg: rgba(18, 22, 36, 0.97);
    --ai-text: #dfe3f0;
    --ai-glass: rgba(28, 34, 54, 0.95);
    --ai-blur: 15px;
    --ai-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.dark-mode {
    --ai-bg: rgba(12, 14, 24, 0.98);
    --ai-text: #f0f2ff;
    --ai-glass: rgba(20, 24, 42, 0.98);
}

/* ---- Trigger Button ---- */
#ai-chat-trigger {
    background: radial-gradient(circle at 38% 35%, #e8001f, #a0001a 55%, #6e000f);
    box-shadow: 0 8px 28px rgba(184, 0, 31, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.18);
    outline: none;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

#ai-chat-trigger::before {
    content: '';
    position: absolute;
    inset: -7px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(220, 0, 30, 0.6) 0%, transparent 70%);
    animation: ai-glow-pulse 2.8s ease-in-out infinite;
    z-index: -1;
    pointer-events: none;
}

@keyframes ai-glow-pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50%       { opacity: 0.9; transform: scale(1.3); }
}

#ai-chat-trigger:hover {
    transform: scale(1.1);
    background: radial-gradient(circle at 38% 35%, #ff1a2e, #c0001e 55%, #880013);
    box-shadow: 0 10px 35px rgba(184, 0, 31, 0.65);
}

/* ---- Atom Icon ---- */
.ai-atom {
    position: relative;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-atom-nucleus {
    position: relative;
    z-index: 3;
    width: 26px;
    height: 26px;
    background: linear-gradient(145deg, #232855, #0d1028);
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 900;
    color: #fff;
    letter-spacing: 0.5px;
    box-shadow:
        0 0 10px rgba(255, 255, 255, 0.45),
        0 0 22px rgba(255, 255, 255, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    font-family: 'Inter', 'Arial', sans-serif;
}

.ai-atom-orbit {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 42px;
    height: 14px;
    border: 1.5px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    margin: -7px 0 0 -21px;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.1);
}

.ai-atom-orbit-1 { animation: ai-orbit-1 3.2s linear infinite; }
.ai-atom-orbit-2 { animation: ai-orbit-2 2.6s linear infinite; }

@keyframes ai-orbit-1 {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
@keyframes ai-orbit-2 {
    0%   { transform: rotate(60deg); }
    100% { transform: rotate(420deg); }
}

.ai-atom-electron {
    position: absolute;
    top: -3.5px;
    left: calc(50% - 3px);
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 5px 2px rgba(255, 255, 255, 0.75);
}

#ai-chat-trigger:hover .ai-atom-orbit-1 { animation-duration: 1.8s; }
#ai-chat-trigger:hover .ai-atom-orbit-2 { animation-duration: 1.4s; }

/* ---- Chat Window (Desktop Base) ---- */
#ai-chat-window {
    position: fixed;
    bottom: 20px;
    right: 85px;
    width: 380px;
    height: 560px;
    max-height: 82vh;
    max-width: calc(100vw - 3rem);
    background: var(--ai-bg);
    backdrop-filter: blur(var(--ai-blur));
    -webkit-backdrop-filter: blur(var(--ai-blur));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--ai-shadow);
    z-index: 9998;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    /* Specific properties only — avoids animating layout/color which 'all' would trigger */
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1),
                opacity 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    will-change: transform, opacity;
}

#ai-chat-window.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* ---- Chat Header ---- */
.ai-chat-header {
    background: var(--ai-primary);
    padding: 20px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.ai-chat-header-info img {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 10px;
    padding: 5px;
    flex-shrink: 0;
}

.ai-chat-header-title {
    min-width: 0;
}

.ai-chat-header-title h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-header-title span {
    font-size: 12px;
    opacity: 0.8;
}

.ai-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
    /* Larger tap target on touch devices */
    padding: 8px;
    margin: -8px -8px -8px 8px;
    border-radius: 50%;
    flex-shrink: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-close:hover {
    opacity: 1;
    transform: rotate(90deg);
}

/* ---- Chat Messages ---- */
#ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--ai-primary) transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    animation: message-in 0.3s ease-out;
    word-break: break-word;
    overflow-wrap: break-word;
}

.ai-message strong {
    font-weight: 700;
    color: inherit;
}

.ai-message em {
    font-style: italic;
    opacity: 0.9;
}

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

.ai-message.bot {
    background: var(--ai-glass);
    color: var(--ai-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255,255,255,0.08);
}

.ai-message.user {
    background: var(--ai-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* ---- Typing Indicator ---- */
.ai-typing {
    display: none;
    align-self: flex-start;
    background: var(--ai-glass);
    padding: 10px 15px;
    border-radius: 18px;
    gap: 5px;
    flex-shrink: 0;
    margin: 0 20px 0 20px;
}

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

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

@keyframes typing-dots {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* ---- Chat Input ---- */
.ai-chat-input-area {
    padding: 20px;
    background: var(--ai-glass);
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

#ai-chat-input {
    flex: 1;
    background: rgba(40, 48, 72, 0.85);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 12px 15px;
    font-size: 14px;
    outline: none;
    color: var(--ai-text);
    transition: border-color 0.3s;
    min-width: 0;
}

#ai-chat-input::placeholder {
    color: rgba(200, 208, 230, 0.5);
}

.dark-mode #ai-chat-input {
    background: rgba(24, 28, 48, 0.9);
    color: var(--ai-text);
    border-color: rgba(255,255,255,0.08);
}

#ai-chat-input:focus {
    border-color: var(--ai-primary);
}

#ai-chat-send {
    background: var(--ai-primary);
    color: white;
    border: none;
    border-radius: 12px;
    width: 45px;
    height: 45px;
    min-width: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s, transform 0.3s;
    flex-shrink: 0;
}

#ai-chat-send:hover {
    background: var(--ai-primary-hover);
    transform: scale(1.05);
}

/* ---- Links & Buttons in Messages ---- */
.ai-link {
    color: var(--ai-primary);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1.5px solid rgba(184, 0, 31, 0.3);
    padding-bottom: 1px;
    transition: all 0.2s ease;
    word-break: break-all;
}

.ai-link:hover {
    color: var(--ai-primary-hover);
    border-bottom-color: var(--ai-primary-hover);
    background: rgba(184, 0, 31, 0.06);
    border-radius: 3px;
    padding: 1px 3px;
    margin: 0 -3px;
}

.ai-auto-link {
    display: inline;
    font-size: 0.9em;
}

.ai-auto-link::before {
    content: "🔗 ";
    font-size: 0.85em;
}

.ai-phone-link {
    color: #16a34a;
    border-bottom-color: rgba(22, 163, 74, 0.3);
}

.ai-phone-link::before {
    content: "📞 ";
    font-size: 0.85em;
}

.ai-phone-link:hover {
    color: #15803d;
    border-bottom-color: #15803d;
    background: rgba(22, 163, 74, 0.06);
}

.ai-email-link {
    color: #2563eb;
    border-bottom-color: rgba(37, 99, 235, 0.3);
}

.ai-email-link::before {
    content: "✉️ ";
    font-size: 0.85em;
}

.ai-email-link:hover {
    color: #1d4ed8;
    border-bottom-color: #1d4ed8;
    background: rgba(37, 99, 235, 0.06);
}

.ai-cta-container {
    display: block;
    margin: 15px 0;
    width: 100%;
}

.ai-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 22px;
    background: var(--ai-primary);
    color: white !important;
    text-decoration: none !important;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(184, 0, 31, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-cta-btn i {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.ai-cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(184, 0, 31, 0.4);
}

.ai-cta-btn:hover i {
    transform: translateX(4px);
}

.ai-message.bot .ai-cta-btn {
    margin-left: 0;
}

/* ---- Mobile Backdrop Overlay ---- */
#ai-chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10004;
    opacity: 0;
    pointer-events: none;
    /* opacity-only transition: works on both open AND close */
    transition: opacity 0.3s ease;
}

#ai-chat-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* ================================================================
   RESPONSIVE BREAKPOINTS
   ================================================================ */

/* ---- Tablet: 481px – 768px ---- */
@media (min-width: 481px) and (max-width: 768px) {
    #ai-chat-window {
        width: 340px;
        height: 520px;
        max-height: 78vh;
        bottom: 20px;
        right: 80px;
        /* z-index stays 9998; navbar (10000) is at top, chat is at bottom-right — no visual overlap */
    }
}

/* ---- Mobile: ≤ 480px — Bottom Sheet ---- */
@media (max-width: 480px) {
    #ai-chat-window {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        /* dvh = dynamic viewport height: shrinks when keyboard appears on iOS/Android */
        height: 88vh;
        max-height: 88vh;
        border-radius: 20px 20px 0 0;
        /* Above navbar (10000), dropdown menu (1000), menu-toggle (10003) */
        z-index: 10005;
        /* Bottom sheet slide animation instead of scale */
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }

    /* dvh supported: more accurate on iOS when keyboard shows */
    @supports (height: 1dvh) {
        #ai-chat-window {
            height: 88dvh;
            max-height: 88dvh;
        }
    }

    #ai-chat-window.active {
        transform: translateY(0);
        opacity: 1;
        pointer-events: all;
    }

    .ai-chat-header {
        padding: 16px 15px;
        border-radius: 20px 20px 0 0;
    }

    .ai-chat-header-title h4 {
        font-size: 15px;
    }

    .ai-chat-input-area {
        padding: 12px;
    }

    #ai-chat-input {
        padding: 10px 12px;
        font-size: 16px; /* Prevents iOS auto-zoom on input focus */
    }

    .ai-message {
        max-width: 90%;
        font-size: 13px;
    }

    .ai-cta-btn {
        padding: 8px 16px;
        font-size: 12px;
    }

    /* Larger tap target for close button on mobile */
    .ai-chat-close {
        font-size: 22px;
        padding: 10px;
        margin: -10px -10px -10px 8px;
    }
}

/* ---- Large Desktop: ≥ 1440px ---- */
@media (min-width: 1440px) {
    #ai-chat-window {
        width: 420px;
        height: 640px;
    }
}

/* ================================================================
   iOS / ANDROID SAFE AREA SUPPORT
   Applies only to mobile bottom sheet (≤ 480px)
   ================================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 480px) {
        #ai-chat-window {
            /* Padding pushes input area above home indicator */
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}
