/* =========================
   General Page & Setup
   ========================= */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #f4f7fb;
    color: #222;
}

/* =========================
   Homepage Elements
   ========================= */
.homepage {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
}

.homepage h1 {
    font-size: 42px;
    margin-bottom: 10px;
}

.homepage p {
    color: #666;
    margin-bottom: 25px;
}

.start-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #169ec5;
    /* Updated to custom teal */
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(22, 158, 197, 0.3);
    /* Themed shadow */
    transition: transform 0.2s, background-color 0.2s;
    cursor: move;
    touch-action: none;
}

.start-button:hover {
    transform: scale(1.1);
    background-color: #117b99;
    /* Darker teal variant */
}

/* =========================
   Chatbot Panel Window
   ========================= */
.chatbot {
    position: fixed;
    right: 25px;
    bottom: 25px;
    width: 360px;
    height: 520px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    display: none;
    flex-direction: column;
    z-index: 1000;
}

/* =========================
   Chat Window Header
   ========================= */
.chat-header {
    background: #169ec5;
    /* Updated to custom teal */
    color: white;

    /* ӨӨРЧЛӨЛТ: Padding-ийг 14px 20px болгож ихэсгэв (Илүү уужим, цэлгэр зайтай болно) */
    padding: 14px 20px;

    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.chat-header h2 {
    color: white;
    max-width: fit-content;
    margin: 0;
    padding: 0;

    /* ӨӨРЧЛӨЛТ: Үсгийн хэмжээг 18px-ээс 15px болгож жижигсгэв (Нарийхан харагдуулна) */
    font-size: 15px;

    /* НЭМЭЛТ: Үсэг хоорондын зайг 0.5px холдуулав (Цэвэрхэн харагдуулах эффект) */
    letter-spacing: 0.5px;

    /* НЭМЭЛТ: Үсгийг хэт бүдүүн харагдуулахгүйн тулд дундаж болгов */
    font-weight: 600;
}

.chat-header span {
    font-size: 12px;
    color: #e2f5fa;
    /* Softened light teal contrast text */
}

.close-button {
    background: transparent;
    border: none;
    color: white;

    /* ӨӨРЧЛӨЛТ: Гарчиг жижигссэн тул Х товчийг пропорцын дагуу 22px болгож багасгав */
    font-size: 22px;

    cursor: pointer;
    line-height: 1.3;

    /* НЭМЭЛТ: Товчлуур дарах зайг илүү эвтэйхэн болгох padding */
    padding: 0 4px;
}

/* =========================
   Conversation Messages Stream
   ========================= */
.messages {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    gap: 14px;
    background: #f8fafc;
}

.message {
    max-width: 80%;
    padding: 8px 11px;
    margin-bottom: 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.3;
    word-wrap: break-word;
}

.bot-message {
    background: #e5e7eb;
    color: #222;
    border-bottom-left-radius: 4px;
}

.user-message {
    background: #169ec5;
    /* Updated to custom teal */
    color: white;
    margin-left: 9px;
    border-bottom-right-radius: 4px;
}

/* Босоо бүтэцтэй болгож шинэчлэв (Цэс нь input-ийнхээ дээр байрлах зориулалттай) */
#chatbot .chat-input-area {
    display: flex;
    flex-direction: column;
    /* Зүйлсийг дээр дээрээс нь цувуулж байрлуулна */
    padding: 4px;
    border-top: 1px solid #e5e7eb;
    background: white;
}

/* Container to relative-position the absolute arrows */
.chat-submenu-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

/* Base style for both transparent scroll arrows */
.scroll-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    background: rgba(255, 255, 255, 0.6);
    /* Semi-transparent background */
    backdrop-filter: blur(4px);
    /* Elegant frosted glass look */
    border: none;
    color: #4b5563;
    /* Charcoal gray color for arrow */
    font-size: 14px;
    width: 24px;
    height: 38px;
    /* Tall enough to cover the 2 rows slightly */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

/* Hover effect */
.scroll-arrow:hover {
    background: rgba(22, 158, 197, 0.15);
    /* Tinted with your custom teal color */
    color: #169ec5;
}

/* Position the buttons on extreme ends */
.prev-arrow {
    left: 0;
    border-radius: 0 4px 4px 0;
}

.next-arrow {
    right: 0;
    border-radius: 4px 0 0 4px;
}

/* --- ШИНЭ ДЭД ЦЭСНИЙ ХЭСЭГ --- */
#chatbot .chat-submenu {
    display: grid;
    grid-template-rows: repeat(2, auto); 
    grid-auto-flow: column; 
    grid-auto-columns: max-content; 
    gap: 6px 8px;
    justify-content: flex-start;
    margin-bottom: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    
    /* ADD PADDING padding on left and right so text isn't permanently hidden behind arrows */
    padding: 4px 26px; 
    box-sizing: border-box;
    
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
/* Hide scrollbar fully if using layout arrows for a cleaner aesthetic */
#chatbot .chat-submenu::-webkit-scrollbar {
    display: none;
}

/* Make individual button boxes slim and lightweight */
#chatbot .submenu-opt {
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb;

    /* SLIM EFFECT: Reduced vertical padding to 5px, horizontal padding to 10px */
    padding: 5px 10px;

    border-radius: 14px;
    /* Made smaller to match the slim profile */
    font-size: 12px;
    /* Dropped to 12px for compact text styling */
    color: #4b5563;
    cursor: pointer;
    white-space: nowrap;
    /* Ensures button text stays on a single line */
    transition: all 0.2s ease;
}

#chatbot .submenu-opt:hover {
    background-color: #e5e7eb;
    color: #1f2937;
}

/* Elegant scrollbar aesthetics */
#chatbot .chat-submenu::-webkit-scrollbar {
    height: 3px;
    /* Ultra thin subtle track line */
}

#chatbot .chat-submenu::-webkit-scrollbar-thumb {
    background: #169ec5;
    border-radius: 4px;
}

/* --- ОРОЛТЫН ТАЛБАР БОЛОН ТОВЧЛУУРЫН МӨР --- */
/* Таны хуучин .chat-input-area-д байсан flex болон gap загварыг энд шилжүүлэв */
#chatbot .input-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

/* Таны хуучин input загварууд (хэвээрээ үлдсэн) */
.input-row input {
    flex: 1;
    min-width: 0;
    border: 1px solid #d1d5db;
    border-radius: 9px;
    padding: 11px 12px;
    outline: none;
    font-size: 14px;
}

.input-row input:focus {
    border-color: #169ec5;
}

/* Таны хуучин Илгээх товчны загварууд (хэвээрээ үлдсэн) */
.input-row button {
    border: none;
    background: #169ec5;
    color: white;
    padding: 0 16px;
    border-radius: 9px;
    cursor: pointer;
}

.input-row button:hover {
    background: #117b99;
}

/* Алдаа заах үеийн эффект (хэвээрээ үлдсэн) */
.input-row input.input-error {
    border-color: #dc3545 !important;
    background-color: #fff5f5;
    box-shadow: 0 0 5px rgba(220, 53, 69, 0.3);
    transition: all 0.15s ease-in-out;
}

/* =========================
   Floating Icon & Launcher
   ========================= */
.chat-icon {
    position: fixed;
    right: 25px;
    bottom: 25px;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: #169ec5;
    /* Updated to custom teal */
    color: white;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(22, 158, 197, 0.4);
    /* Themed shadow */
    transition: transform 0.2s, background 0.2s;
    z-index: 999;
}

.chat-icon:hover {
    background: #117b99;
    /* Darker teal variant */
    transform: scale(1.08);
}

.chatbot.open~.chat-icon {
    display: none;
}

/* =========================
   Attention Bubble Badge
   ========================= */
#chatAttentionBadge {
    position: fixed;
    right: 25px;
    bottom: 95px;
    background-color: #169ec5;
    /* Updated to custom teal */
    color: white;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 4px 15px rgba(22, 158, 197, 0.3);
    /* Themed shadow */
    z-index: 1001;
    pointer-events: none;
    animation: popBounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popBounceIn {
    0% {
        transform: scale(0.6) translateY(15px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* ==================================================
   Chat Quick Menu Options & Internal Document Links
   ================================================== */
.chat-menu-container {
    display: flex;
    flex-direction: column;

    margin-bottom: 12px;
    max-width: 85%;
    animation: popBounceIn 0.3s ease-out forwards;
}

.chat-menu-btn {
    background-color: white;
    color: #169ec5;
    /* Updated to custom teal */
    border: 1px solid #169ec5;
    /* Updated border */
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    margin-top: 6px;
}

.chat-menu-btn:hover {
    background-color: #169ec5;
    /* Updated to custom teal */
    color: white;
}

/* Hyperlinks injected inside the responses */
.chat-link {
    color: #169ec5;
    /* Updated to custom teal */
    text-decoration: underline;
    font-weight: 500;
}

.chat-link:hover {
    color: #117b99;
    /* Darker teal variant */
}

/* =========================
   Responsive Media Queries
   ========================= */
@media (max-width: 500px) {
    .chatbot {
        right: 10px;
        bottom: 10px;
        width: calc(100% - 20px);
        height: 80vh;
    }

    .homepage h1 {
        font-size: 32px;
    }
}

/* ==================================================
   UPDATED MESSAGE ALIGNMENT RULES
   ================================================== */

/* Parent layout wrapper holding text + avatar side-by-side */
.message-wrapper {
    display: flex;
    align-items: flex-end;
    /* Keeps the avatar at the bottom edge of long text blocks */
    margin-bottom: 9px;
    width: 100%;
    /* Spans the full chat area width */
}

/* User alignment pushes right, Bot alignment stays left */
.user-wrapper {
    justify-content: flex-end;
}

/* Base message structural layout block modification */
.message {
    max-width: 70%;
    /* Soft decrease to make reliable space for the avatar image */
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.2;
    word-wrap: break-word;
    margin-bottom: 9px;
    /* Let message-wrapper handle spacing */
}

.user-message {
    background: #169ec5;
    color: white;
    border-bottom-right-radius: 4px;
}

/* Profile Picture Layout Properties */
.chat-profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    /* CRITICAL: Stops the image from getting squished by long text strings */
    border: 1px solid #d1d5db;
}

/* Username Label element details */
.chat-profile-name {
    display: block;
    font-size: 10px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 2px;
}

.chat-text-content {
    margin: 0;
    padding: auto;
}

/* Bot-specific wrapper alignment to ensure it sits left */
.bot-wrapper {
    justify-content: flex-start;
}

/* Specific styling for the bot name tag inside the gray bubble */
.chat-profile-name.bot-name {
    color: #666666;
    /* Muted gray text color to look professional on the light gray background */
}

/* Gives the bot icon badge a unique accent border line if wanted */
.chat-profile-avatar.bot-avatar {
    border: 1px solid #169ec5;
    /* Accent teal border ring matching your theme */
}