/* MiPA Chatbot - Premium UI */
.mipa-chatbot-root {
    position: relative;
    z-index: 999999 !important;
}

.mipa-chatbot-launcher {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 999999 !important;
    width: 70px;
    height: 70px;
    border: none;
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    background: linear-gradient(145deg, #192d66 0%, #164976 50%, #0f7f8f 100%);
    box-shadow: 0 10px 30px rgba(25, 45, 102, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    overflow: visible;
}

.mipa-chatbot-launcher::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(22, 73, 118, 0.35);
    animation: mipa-chatbot-pulse 2.2s ease-out infinite;
    pointer-events: none;
}

.mipa-chatbot-launcher::after {
    content: 'Ask MiPA';
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) translateX(8px);
    white-space: nowrap;
    background: #192d66;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 4px 14px rgba(25, 45, 102, 0.25);
}

.mipa-chatbot-launcher:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.mipa-chatbot-launcher:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 14px 36px rgba(25, 45, 102, 0.5);
}

.mipa-chatbot-launcher.is-active {
    transform: scale(0.92);
    opacity: 0.85;
}

.mipa-chatbot-launcher img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    position: relative;
    z-index: 1;
}

@keyframes mipa-chatbot-pulse {
    0% { transform: scale(1); opacity: 0.85; }
    70% { transform: scale(1.18); opacity: 0; }
    100% { transform: scale(1.18); opacity: 0; }
}

/* Backdrop – click outside to close */
.mipa-chatbot-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(12, 22, 48, 0.42);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999998 !important;
    animation: mipa-chatbot-fade-in 0.25s ease;
}

.mipa-chatbot-overlay.is-open {
    display: block;
}

@keyframes mipa-chatbot-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

#chatWindow {
    display: none;
    flex-direction: column;
    position: fixed;
    top: auto;
    bottom: 100px;
    right: 28px;
    width: 460px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 160px);
    background: #f8fafc;
    border-radius: 20px;
    border: 1px solid rgba(25, 45, 102, 0.1);
    box-shadow:
        0 24px 64px rgba(15, 35, 80, 0.28),
        0 0 0 1px rgba(255, 255, 255, 0.6) inset;
    z-index: 999999 !important;
    overflow: hidden;
    font-family: 'Ubuntu', 'Segoe UI', sans-serif;
}

#chatWindow.is-open {
    display: flex;
    animation: mipa-chatbot-slide-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes mipa-chatbot-slide-in {
    from { opacity: 0; transform: translateY(24px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

#chatHeader {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 54px 20px 20px;
    background: linear-gradient(135deg, #192d66 0%, #1a4a7a 45%, #0f7f8f 100%);
    color: #fff;
    margin: 0;
    flex-shrink: 0;
}

#chatHeader::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
}

#chatHeader .chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#chatHeader .chat-avatar img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

#chatHeader .chat-title-wrap p {
    margin: 0;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    line-height: 1.25;
    letter-spacing: 0.01em;
}

#chatHeader .chat-title-wrap span {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.88);
}

#chatHeader .chat-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #b8f0c8;
    background: rgba(255, 255, 255, 0.12);
    padding: 3px 10px;
    border-radius: 20px;
}

#chatHeader .chat-status-badge::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
    animation: mipa-status-blink 2s ease infinite;
}

@keyframes mipa-status-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#chatHeader button.chat-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    padding: 0;
}

#chatHeader button.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.05);
}

#chatContent {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background:
        linear-gradient(180deg, #f0f4f9 0%, #f8fafc 40%, #f8fafc 100%);
}

#chatContent::-webkit-scrollbar {
    width: 7px;
}

#chatContent::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #b8c9de, #94a8c4);
    border-radius: 7px;
}

.chat-footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #e8eef5;
    font-size: 11px;
    color: #6e88ae;
    font-weight: 500;
}

.chat-footer-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-footer-stats {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: linear-gradient(135deg, #eef3f9 0%, #f4f8fc 100%);
    border: 1px solid #dce5f0;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #164976;
}

.chat-footer-stats::before {
    content: '👥';
    font-size: 13px;
    line-height: 1;
}

.chat-footer .chat-footer-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
}

.chat-welcome {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: flex-start;
}

.chat-welcome .chat-bot-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #192d66, #0f7f8f);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(25, 45, 102, 0.2);
}

.chat-welcome .chat-bot-icon img {
    width: 22px;
    height: 22px;
}

.chat-welcome .bubble {
    background: #fff;
    border: 1px solid #e2eaf4;
    border-radius: 4px 16px 16px 16px;
    padding: 14px 16px;
    font-size: 15px;
    line-height: 1.55;
    color: #2c3e5a;
    box-shadow: 0 4px 16px rgba(25, 45, 102, 0.07);
    flex: 1;
}

.chat-welcome .bubble strong {
    color: #192d66;
}

.chat-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #164976;
    margin: 0 0 12px;
    padding-left: 2px;
}

.module-btn,
.question-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    text-align: left;
    margin: 0 0 10px;
    padding: 15px 16px;
    border: 1px solid #dce5f0;
    border-left: 4px solid transparent;
    border-radius: 12px;
    background: #fff;
    color: #192d66;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.45;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease, border-left-color 0.2s ease;
    box-shadow: 0 2px 8px rgba(25, 45, 102, 0.05);
}

.module-btn:hover,
.question-btn:hover {
    border-left-color: #164976;
    border-color: #b8cce0;
    box-shadow: 0 6px 18px rgba(25, 45, 102, 0.12);
    transform: translateX(3px);
}

.module-btn::after,
.question-btn::after {
    content: '›';
    font-size: 22px;
    font-weight: 300;
    color: #164976;
    margin-left: 12px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.module-btn:hover::after,
.question-btn:hover::after {
    transform: translateX(3px);
}

.chat-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    margin: 0 0 14px;
    padding: 9px 14px;
    border: 1px solid #dce5f0;
    border-radius: 10px;
    background: #fff;
    color: #164976;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 6px rgba(25, 45, 102, 0.05);
}

.chat-back-btn:hover {
    background: #eef3f9;
    box-shadow: 0 4px 10px rgba(25, 45, 102, 0.08);
}

.chat-answer-wrap {
    background: #fff;
    border: 1px solid #e2eaf4;
    border-radius: 14px;
    padding: 18px 20px;
    font-size: 15px;
    line-height: 1.65;
    color: #2c3e5a;
    box-shadow: 0 4px 16px rgba(25, 45, 102, 0.07);
    margin-bottom: 14px;
}

.chat-answer-wrap p {
    margin: 0 0 10px;
}

.spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 48px 20px;
    font-size: 14px;
    color: #6e88ae;
    font-weight: 500;
}

.spinner::before {
    content: '';
    width: 38px;
    height: 38px;
    border: 3px solid #dce5f0;
    border-top-color: #164976;
    border-radius: 50%;
    animation: mipa-chatbot-spin 0.75s linear infinite;
}

@keyframes mipa-chatbot-spin {
    to { transform: rotate(360deg); }
}

.chat-error {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    padding: 14px;
    font-size: 14px;
}

.chat-empty {
    color: #6e88ae;
    font-size: 14px;
    padding: 10px 0;
}

@media (max-width: 520px) {
    #chatWindow {
        top: auto;
        right: 10px;
        bottom: 88px;
        width: calc(100vw - 20px);
        height: 460px;
        max-height: calc(100vh - 140px);
        border-radius: 16px;
    }

    .mipa-chatbot-launcher {
        right: 16px;
        bottom: 16px;
        width: 60px;
        height: 60px;
    }

    .mipa-chatbot-launcher::after {
        display: none;
    }

    .mipa-chatbot-launcher img {
        width: 38px;
        height: 38px;
    }
}
