/* Mai An Đức AI Chatbot - Frontend Styles */

#madc-chatbot-container {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Chat CTA */
.madc-chat-cta {
    position: absolute;
    right: 96px;
    top: 50%;
    transform: translateY(-50%);
    min-width: 245px;
    padding: 11px 20px;
    border-radius: 999px;
    background: linear-gradient(135deg, #ffffff 0%, #fff8d6 100%);
    color: #003F7D;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(0, 63, 125, 0.2), 0 0 0 2px rgba(255, 194, 14, 0.45);
    animation: madcCtaSlideIn 0.7s ease-out both, madcCtaPulse 2.8s ease-in-out 0.8s infinite;
}

.madc-chat-cta::after {
    content: "";
    position: absolute;
    right: -7px;
    top: 50%;
    width: 14px;
    height: 14px;
    background: #fff8d6;
    border-top: 2px solid rgba(255, 194, 14, 0.45);
    border-right: 2px solid rgba(255, 194, 14, 0.45);
    transform: translateY(-50%) rotate(45deg);
}

#madc-chatbot-container.position-bottom-left .madc-chat-cta,
#madc-chatbot-container.position-top-left .madc-chat-cta {
    right: auto;
    left: 96px;
}

#madc-chatbot-container.position-bottom-left .madc-chat-cta::after,
#madc-chatbot-container.position-top-left .madc-chat-cta::after {
    right: auto;
    left: -7px;
    border-top: 0;
    border-right: 0;
    border-bottom: 2px solid rgba(255, 194, 14, 0.45);
    border-left: 2px solid rgba(255, 194, 14, 0.45);
}

.madc-chat-cta:hover {
    color: #005BAA;
    box-shadow: 0 12px 32px rgba(0, 91, 170, 0.26), 0 0 0 3px rgba(255, 194, 14, 0.55);
}

@keyframes madcCtaSlideIn {
    from {
        opacity: 0;
        transform: translate(18px, -50%) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(0, -50%) scale(1);
    }
}

@keyframes madcCtaPulse {
    0%, 100% {
        transform: translateY(-50%) scale(1);
    }
    50% {
        transform: translateY(-50%) scale(1.04);
    }
}

/* Chat Button */
.madc-chat-button {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 30px rgba(0, 91, 170, 0.32), 0 0 0 6px rgba(255, 194, 14, 0.18);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #003F7D;
    font-size: 32px;
    overflow: hidden;
}

/* Chat Button Icon - SVG */
.madc-chat-icon-svg {
    width: 32px;
    height: 32px;
    stroke: currentColor;
    flex-shrink: 0;
}

/* Chat Button Icon - Custom Image */
.madc-chat-icon-img {
    width: 70%;
    height: 70%;
    object-fit: contain;
    flex-shrink: 0;
}

/* Button Size Variants */
.madc-button-size-small .madc-chat-button {
    width: 48px;
    height: 48px;
}

.madc-button-size-small .madc-chat-icon-svg {
    width: 24px;
    height: 24px;
}

.madc-button-size-small .madc-chat-icon-img {
    width: 60%;
    height: 60%;
}

.madc-button-size-medium .madc-chat-button {
    width: 64px;
    height: 64px;
}

.madc-button-size-medium .madc-chat-icon-svg {
    width: 32px;
    height: 32px;
}

.madc-button-size-medium .madc-chat-icon-img {
    width: 70%;
    height: 70%;
}

.madc-button-size-large .madc-chat-button {
    width: 80px;
    height: 80px;
}

.madc-button-size-large .madc-chat-icon-svg {
    width: 40px;
    height: 40px;
}

.madc-button-size-large .madc-chat-icon-img {
    width: 75%;
    height: 75%;
}

.madc-chat-button:hover {
    transform: translateY(-2px) scale(1.08);
    box-shadow: 0 16px 38px rgba(0, 91, 170, 0.38), 0 0 0 8px rgba(255, 194, 14, 0.2);
}

.madc-chat-button:active {
    transform: scale(0.95);
}

/* Mobile: Smaller button like call button */
@media (max-width: 768px) {
    .madc-chat-cta {
        right: 58px;
        min-width: 165px;
        max-width: calc(100vw - 95px);
        padding: 8px 12px;
        font-size: 12px;
        white-space: normal;
    }

    #madc-chatbot-container.position-bottom-left .madc-chat-cta,
    #madc-chatbot-container.position-top-left .madc-chat-cta {
        right: auto;
        left: 58px;
    }

    .madc-chat-button {
        width: 38px;
        height: 38px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25) !important;
    }

    .madc-chat-icon-svg {
        width: 24px !important;
        height: 24px !important;
    }

    .madc-chat-icon-img {
        width: 55% !important;
        height: 55% !important;
    }
}

/* Chat Window */
.madc-chat-window {
    position: absolute;
    right: 0;
    bottom: 86px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 400px;
    height: 600px;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#madc-chatbot-container.position-bottom-left .madc-chat-window,
#madc-chatbot-container.position-top-left .madc-chat-window {
    right: auto;
    left: 0;
}

#madc-chatbot-container.position-top-right .madc-chat-window,
#madc-chatbot-container.position-top-left .madc-chat-window {
    top: 86px;
    bottom: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile: Full screen chat with safe area */
@media (max-width: 768px) {
    .madc-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height for mobile browsers */
        max-height: -webkit-fill-available !important;
        border-radius: 0;
        animation: slideUpMobile 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
}

/* Chat Header */
.madc-chat-header {
    padding: 20px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: inset 0 -4px 0 #FFC20E, 0 2px 12px rgba(0, 63, 125, 0.24);
    flex-shrink: 0;
}

/* Mobile: Add safe area for header */
@media (max-width: 768px) {
    .madc-chat-header {
        padding: max(env(safe-area-inset-top), 15px) 20px 15px 20px;
        min-height: 60px;
    }

    .madc-chat-header-info h3 {
        font-size: 16px;
    }

    .madc-chat-header-info p {
        font-size: 12px;
    }
}

.madc-chat-header-info h3 {
    margin: 0;
    color: #ffffff !important;
    font-size: 18px;
    font-weight: 700;
}

.madc-chat-header-info p {
    margin: 5px 0 0 0;
    color: #ffffff !important;
    font-size: 13px;
    opacity: 0.92;
}

.madc-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    transition: background 0.2s;
}

.madc-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Chat Messages */
.madc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f9fafb;
    scroll-behavior: smooth;
}

.madc-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.madc-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.madc-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.madc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Message */
.madc-message {
    display: flex;
    margin-bottom: 16px;
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.madc-message.user {
    justify-content: flex-end;
}

.madc-message.bot {
    justify-content: flex-start;
}

.madc-message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.madc-message.user .madc-message-content {
    background: linear-gradient(135deg, #005BAA 0%, #003F7D 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 6px 16px rgba(0, 91, 170, 0.22);
}

.madc-message.bot .madc-message-content {
    background: white;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Typing Indicator */
.madc-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.madc-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typing 1.4s infinite;
}

.madc-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.madc-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Chat Input */
.madc-chat-input {
    padding: 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
}

.madc-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.madc-chat-input input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.madc-chat-input input:focus {
    border-color: #005BAA;
    box-shadow: 0 0 0 3px rgba(0, 91, 170, 0.12);
}

.madc-chat-input input:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
}

.madc-send-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #FFC20E;
    color: #003F7D;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(255, 194, 14, 0.32);
}

.madc-send-button:hover:not(:disabled) {
    background: #E0A800;
    transform: scale(1.05);
}

.madc-send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.madc-send-button:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.madc-send-icon {
    width: 20px;
    height: 20px;
}

/* Hotline Footer */
.madc-hotline-footer {
    padding: 12px 20px;
    text-align: center;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: #6b7280;
}

.madc-hotline-footer a {
    color: #005BAA;
    font-weight: 600;
    text-decoration: none;
}

.madc-hotline-footer a:hover {
    text-decoration: underline;
}

/* Loading spinner */
.madc-spinner {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility classes */
.madc-hidden {
    display: none !important;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    .madc-chat-window {
        background: #1f2937;
    }
    
    .madc-chat-messages {
        background: #111827;
    }
    
    .madc-message.bot .madc-message-content {
        background: #374151;
        color: #f3f4f6;
    }
    
    .madc-chat-input {
        background: #1f2937;
        border-top-color: #374151;
    }
    
    .madc-chat-input input {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }
}
