/* =========================
   FAB (Floating Action Button)
   ========================= */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-ubam-dark-gray);
    color: var(--color-ubam-white);
    border: none;
    box-shadow: 0 4px 12px rgba(33, 33, 33, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    z-index: 1000;
    transition:
            background-color var(--ubam-transition),
            box-shadow var(--ubam-transition),
            transform var(--ubam-transition);
}
.chat-fab:hover {
    background: var(--color-ubam-dark-blue);
    box-shadow: 0 6px 16px rgba(33, 33, 33, 0.4);
    transform: scale(1.05);
}
.chat-fab:active { transform: scale(0.95); }
.chat-fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* =========================
   Notification Badge
   ========================= */
.chat-fab .notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--color-ubam-pink);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    animation: bounce 1s ease-in-out infinite;
}

/* =========================
   Bounce Animation
   ========================= */
@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* =========================
   Icons (Close & Support)
   ========================= */
.close-icon,
.support-icon img { filter: brightness(0) invert(1); margin-bottom: 0.4rem; }
.welcome-icon img { height: 5.4rem; width: 5.4rem; }

/* =========================
   Overlays (Chat + Modals)
   ========================= */
.chat-overlay,
.clear-chat-modal,
.rate-limit-modal {
    position: fixed;
    inset: 0;
    background: rgba(33, 33, 33, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-overlay {
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: var(--ubam-transition);
}
.chat-overlay.visible { opacity: 1; pointer-events: all; }

/* Distinct stacking + entry anim for modals */
.clear-chat-modal { z-index: 10000; animation: fadeIn 0.2s ease; }
.rate-limit-modal { z-index: 10001; animation: fadeIn 0.2s ease; }

/* =========================
   Chat Container
   ========================= */
.chatbot-container {
    position: fixed;
    bottom: 90px;
    right: 16px;
    width: 380px;
    height: 550px;
    background: var(--color-ubam-white);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(33, 33, 33, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transform: scale(0) translateY(50px);
    opacity: 0;
    transform-origin: bottom right;
    transition: var(--ubam-transition);
}
.chatbot-container.visible { transform: scale(1) translateY(0); opacity: 1; }

/* Desactivar al inicio (conservar comportamiento original) */
.chatbot-container,
.chat-overlay { transition: none !important; }

/* =========================
   Header
   ========================= */
.chat-header {
    background: var(--color-ubam-dark);
    color: var(--color-ubam-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    min-height: 72px;
}
.chat-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    animation: shimmer 3s ease-in-out infinite;
}
@keyframes shimmer {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
}

/* Header elements */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--color-ubam-white);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}
.avatar img { width: 32px; height: 32px; }

.chat-info { flex: 1; position: relative; z-index: 1; min-width: 0; }
.chat-title {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-status { font-size: 12px; opacity: 0.9; display: flex; align-items: center; gap: 6px; }

/* Status Indicator */
.status-indicator {
    width: 6px;
    height: 6px;
    background: var(--color-ubam-green);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

/* Close Button */
.close-button {
    background: none;
    border: none;
    color: var(--color-ubam-white);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: var(--fast-transition);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}
.close-button:hover { background: rgba(255, 255, 255, 0.1); }

/* =========================
   Messages Container
   ========================= */
.messages-container {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.messages-container::-webkit-scrollbar { width: 3px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb {
    background: var(--color-ubam-gray);
    border-radius: 2px;
}

/* =========================
   Message Bubbles
   ========================= */
.message {
    display: flex;
    gap: 6px;
    animation: messageSlideIn 0.3s ease-out;
}
@keyframes messageSlideIn {
    from { opacity: 0; transform: translateY(15px); }
    to   { opacity: 1; transform: translateY(0); }
}
.message.user { flex-direction: row-reverse; }

.message-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 500;
    flex-shrink: 0;
}
.message.bot .message-avatar { background: var(--color-ubam-light-gray); color: var(--color-ubam-dark-gray); }
.message.user .message-avatar { background: var(--color-ubam-pink); color: var(--color-ubam-white); }

.message-content {
    max-width: 220px;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.3;
    position: relative;
    word-wrap: break-word;
}
.message.bot .message-content {
    background: var(--color-ubam-light-gray);
    color: var(--color-ubam-dark);
    border-bottom-left-radius: 4px;
}
.message.user .message-content {
    background: var(--color-ubam-dark-blue);
    color: var(--color-ubam-white);
    border-bottom-right-radius: 4px;
}
.message-time { font-size: 10px; opacity: 0.7; margin-top: 3px; }

/* =========================
   WhatsApp Phone Link
   ========================= */
.whatsapp-phone-link {
    color: #25D366;
    text-decoration: none;
    font-weight: 500;
    position: relative;
    padding: 2px 6px;
    margin: 0 2px;
    border-radius: 6px;
    background: rgba(37, 211, 102, 0.1);
    border: 1px solid rgba(37, 211, 102, 0.2);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.whatsapp-phone-link:hover {
    background: rgba(37, 211, 102, 0.15);
    border-color: rgba(37, 211, 102, 0.4);
    color: #1ea952;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.2);
}
.whatsapp-phone-link:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(37, 211, 102, 0.2);
}
/* Icon (pseudo-element) */
.whatsapp-phone-link::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background-image: url("/images/icons/chat.svg");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    filter: brightness(0) saturate(100%) invert(46%) sepia(87%) saturate(747%) hue-rotate(75deg) brightness(90%) contrast(90%);
}
.whatsapp-phone-link:hover::after { opacity: 1; }

/* =========================
   Typing Indicator
   ========================= */
.typing-indicator {
    margin-left: 1.2rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
}
.typing-indicator.active { animation: fadeInOut 2s ease-in-out infinite; }
@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}
.typing-dots {
    display: flex;
    gap: 3px;
    padding: 10px 14px;
    background: var(--color-ubam-light-gray);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.typing-dot {
    width: 5px;
    height: 5px;
    background: var(--color-ubam-gray);
    border-radius: 50%;
}
.typing-indicator.active .typing-dot { animation: typingAnimation 1.4s ease-in-out infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingAnimation {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* =========================
   Input Area
   ========================= */
.input-area {
    padding: 10px 12px 12px;
    background: var(--color-ubam-white);
    border-top: 1px solid var(--color-ubam-light-gray);
}
.input-container {
    display: flex;
    align-items: end;
    gap: 6px;
    background: var(--color-ubam-light-gray);
    border-radius: 20px;
    padding: 4px 4px 4px 12px;
    border: 2px solid transparent;
    transition: var(--fast-transition);
}
.input-container:focus-within {
    border-color: var(--color-ubam-dark-blue);
    box-shadow: 0 0 0 2px rgba(18, 124, 166, 0.1);
}
.message-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13px;
    line-height: 1.3;
    padding: 8px 0;
    color: var(--color-ubam-dark);
    resize: none;
    max-height: 80px;
    min-height: 18px;
}
.message-input::placeholder { color: var(--color-ubam-gray); }
.message-input::-webkit-scrollbar { width: 4px; }
.message-input::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 2px;
}
.message-input::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}
.message-input::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.4); }

.send-button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--color-ubam-dark-blue);
    color: var(--color-ubam-white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--fast-transition);
    flex-shrink: 0;
}
.send-button:hover { background: var(--color-ubam-blue); transform: scale(1.05); }
.send-button:active { transform: scale(0.95); }
.send-button:disabled { background: var(--color-ubam-gray); cursor: not-allowed; transform: none; }

/* =========================
   Welcome Message
   ========================= */
.welcome-message { text-align: center; padding: 20px 12px; color: var(--color-ubam-gray); }
.welcome-icon { font-size: 36px; margin-bottom: 10px; color: var(--color-ubam-dark-blue); }
.welcome-title { font-size: 16px; font-weight: 500; margin-bottom: 6px; color: var(--color-ubam-dark); }
.welcome-subtitle { font-size: 12px; line-height: 1.3; margin-bottom: 12px; }
#warning-message { text-align: center; color: var(--color-ubam-gray); font-size: 0.8rem; margin-top: 0.6rem; }

/* =========================
   Suggestions
   ========================= */
.suggestions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.suggestion-chip {
    background: var(--color-ubam-white);
    color: var(--color-ubam-dark);
    border: 1px solid var(--color-ubam-light-gray);
    border-radius: 10px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    transition: var(--fast-transition);
}
.suggestion-chip:hover { background: var(--color-ubam-light-blue); border-color: var(--color-ubam-blue); }

/* =========================
   Conversation Controls (Header)
   ========================= */
.conversation-controls { display: flex; align-items: center; margin-right: 8px; }
.control-btn {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.control-btn:hover { background-color: rgba(255, 255, 255, 0.1); }
.control-btn img { opacity: 0.8; filter: brightness(0) invert(1); }

/* Integration with existing chat styles */
.chatbot-container .chat-header { position: relative; }

/* Header content ordering */
.chat-header .conversation-controls { order: 2; }
.chat-header .close-button { order: 3; }

/* =========================
   Modal Content (Shared)
   ========================= */
.clear-chat-content,
.rate-limit-content {
    background: var(--color-ubam-white);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(33, 33, 33, 0.3);
    width: 90%;
    animation: slideIn 0.3s ease;
    text-align: center;
}
.clear-chat-content { max-width: 320px; }
.rate-limit-content { max-width: 380px; }

/* Modal text */
.clear-chat-content h6,
.rate-limit-content h6 {
    margin: 0 0 12px;
    font-weight: 600;
    color: var(--color-ubam-dark);
}
.clear-chat-content h6 { font-size: 18px; }
.rate-limit-content h6 { font-size: 20px; }

.clear-chat-content p,
.rate-limit-content p {
    margin: 0 0 16px;
    color: var(--color-ubam-dark-gray);
    font-size: 14px;
    line-height: 1.45;
}
.clear-chat-content p { margin-bottom: 20px; } /* preserve exact spacing difference */

/* Modal actions */
.clear-chat-actions,
.rate-limit-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}
.clear-chat-btn,
.rate-limit-btn {
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 80px;
    padding: 10px 20px;
}

/* Rate-limit specifics */
.rate-limit-btn {
    background: var(--color-ubam-dark-blue);
    color: var(--color-ubam-white);
    padding: 12px 24px;
    transition: background-color 0.2s ease;
}
.rate-limit-btn:hover { background: var(--color-ubam-blue); }
.rate-limit-icon {
    width: 48px; height: 48px; background: var(--color-ubam-pink);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px; font-size: 24px; color: var(--color-ubam-white);
}

/* Rate Limit stats & progress */
.rate-limit-stats {
    background: var(--color-ubam-light-gray);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}
.rate-limit-stat { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.rate-limit-stat:last-child { margin-bottom: 0; }
.rate-limit-stat-label { color: var(--color-ubam-dark-gray); }
.rate-limit-stat-value { color: var(--color-ubam-dark); font-weight: 600; }

.rate-limit-progress { margin: 16px 0; }
.rate-limit-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--color-ubam-light-gray);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}
.rate-limit-progress-fill {
    height: 100%;
    background: var(--color-ubam-pink);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.rate-limit-progress-text { font-size: 12px; color: var(--color-ubam-dark-gray); margin-bottom: 4px; }

/* =========================
   Animations (Modal/Overlay)
   ========================= */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* =========================
   Responsive — Tablets
   ========================= */
@media (max-width: 768px) {
    .chat-fab { bottom: 20px; right: 20px; width: 52px; height: 52px; font-size: 22px; }
    .chatbot-container { bottom: 80px; right: 12px; width: 340px; height: 500px; }
    .message-content { max-width: 200px; }
    .whatsapp-phone-link { font-size: 12px; padding: 1px 4px; }
    .whatsapp-phone-link::after { width: 10px; height: 10px; }
}

/* =========================
   Responsive — Small Screens
   ========================= */
@media (max-width: 480px) {
    .chat-fab { bottom: 16px; right: 16px; width: 48px; height: 48px; font-size: 20px; }
    .chat-fab .notification-badge { width: 16px; height: 16px; font-size: 10px; }

    .chatbot-container {
        bottom: 0; right: 0; left: 0; top: 0;
        width: 100%; height: 100%; border-radius: 0; transform-origin: center;
    }
    .chatbot-container.visible { transform: scale(1) translateY(0); }

    .chat-header { padding: 12px 16px; min-height: 60px; }
    .avatar { width: 32px; height: 32px; font-size: 14px; }
    .chat-title { font-size: 15px; }
    .chat-status { font-size: 11px; }

    .messages-container { padding: 8px 12px; gap: 8px; }
    .message-content { max-width: calc(100vw - 80px); font-size: 14px; padding: 12px 16px; }

    .input-area { padding: 8px 12px 20px; }
    .input-container { padding: 6px 6px 6px 16px; }
    .message-input { font-size: 16px; padding: 10px 0; }
    .send-button { width: 40px; height: 40px; }

    .welcome-message { padding: 16px; }
    .suggestions { gap: 6px; }
    .suggestion-chip { padding: 6px 12px; font-size: 12px; }

    .whatsapp-phone-link { font-size: 13px; padding: 2px 4px; margin: 0 1px; }
    .whatsapp-phone-link::after { width: 11px; height: 11px; }
}

/* =========================
   Very Small Screens
   ========================= */
@media (max-width: 320px) {
    .message-content { max-width: calc(100vw - 60px); font-size: 13px; }
    .input-container { padding: 4px 4px 4px 12px; }
    .send-button { width: 36px; height: 36px; }
    .whatsapp-phone-link { font-size: 12px; padding: 1px 3px; }
    .whatsapp-phone-link::after { width: 10px; height: 10px; }
}

/* =========================
   Reduced Motion
   ========================= */
@media (prefers-reduced-motion: reduce) {
    .chat-fab,
    .chatbot-container,
    .message,
    .typing-indicator,
    .chat-overlay,
    .input-container,
    .send-button,
    .suggestion-chip,
    .whatsapp-phone-link {
        transition: none !important;
        animation: none !important;
    }
    .chat-header::before { animation: none !important; }
    .status-indicator,
    .notification-badge { animation: none !important; }
}
