﻿/* Header buttons container */
.header-buttons {
    display: flex;
    gap: 8px;
}

/* Reset button */
.reset-btn {
    background: rgba(255, 255, 255, 0.25);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 20px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

    .reset-btn:hover {
        background: rgba(255, 255, 255, 0.4);
        transform: rotate(180deg);
    }

/* Input wrapper to position dots inside the input */
.input-wrapper {
    position: relative;
    flex: 1;
}

    .input-wrapper input {
        width: 100%;
        padding-left: 16px;
        padding-right: 16px;
    }

        /* Hide placeholder when typing indicator is active */
        .input-wrapper input.typing::placeholder {
            color: transparent;
        }

/* Typing indicator (three bouncing dots) */
.typing-indicator {
    position: absolute;
    left: 26px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 4px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

    .typing-indicator.active {
        opacity: 1;
    }

    .typing-indicator span {
        width: 7px;
        height: 7px;
        background-color: #999;
        border-radius: 50%;
        display: inline-block;
        animation: typingBounce 1.4s infinite ease-in-out;
    }

        .typing-indicator span:nth-child(1) {
            animation-delay: 0s;
        }

        .typing-indicator span:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-indicator span:nth-child(3) {
            animation-delay: 0.4s;
        }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* TOGGLE BUTTON */
.chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, orange, orangered);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(255, 69, 0, 0.4);
    z-index: 1001;
    transition: all 0.3s ease;
    border: none;
    user-select: none;
}

    .chat-toggle:hover {
        transform: scale(1.1) rotate(10deg);
        box-shadow: 0 12px 35px rgba(255, 69, 0, 0.6);
    }

/* CHAT CONTAINER */
.chat-container {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 800px;
    max-width: 90vw;
    height: 1000px;
    max-height: 90vh;
    border: 1px solid #ccc;
    border-radius: 10px;
    background: white;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    font-family: 'Segoe UI', Arial, sans-serif;
    z-index: 9999999;
    overflow: hidden;
    animation: slideUp 0.35s ease-out forwards;
    transform-origin: bottom right;
    display: none;
    margin-bottom: 20px;
    font-weight: 500;
}

    .chat-container p {
        margin-top: 5px;
        margin-bottom: 5px;
    }

    .chat-container img {
        width: 100%;
        height: auto;
        display: block;
    }

    .chat-container table {
        margin-bottom: 10px;
    }

    .chat-container th {
        border: solid 1px silver;
        padding: 3px 5px 2px 5px;
        background-color: #f0f0f0;
        font-weight: 700;
        vertical-align: top;
    }

    .chat-container td {
        border: solid 1px silver;
        padding: 3px 5px 2px 5px;
        vertical-align: top;
    }

/* Slide-up animation */
@keyframes slideUp {
    from {
        transform: translateY(100%) scale(0.8);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.chat-container.closing {
    animation: fadeOut 0.25s ease-in forwards;
}

@keyframes fadeOut {
    to {
        transform: translateY(50px) scale(0.9);
        opacity: 0;
    }
}

/* HEADER */
.chat-header {
    position: relative;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 15px 18px;
    font-weight: 600;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 10;
}

.close-btn {
    background: rgba(255, 255, 255, 0.25);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 22px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

    .close-btn:hover {
        background: rgba(255, 255, 255, 0.4);
        transform: rotate(90deg);
    }

/* MESSAGES AREA – ABSOLUTE POSITIONING (SCROLL GUARANTEED) */
.chat-messages {
    position: absolute;
    top: 63px; /* Below header */
    left: 0;
    right: 0;
    bottom: 75px; /* Increased from 70px to 75px to give more room for scrollbar arrows */
    padding: 15px;
    overflow-y: scroll; /* Force scrollbar to always show */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    background: #f8f9fa;
    /* FORCE VISIBLE & CLICKABLE SCROLLBAR */
    scrollbar-width: auto;
    scrollbar-color: #007bff #f1f1f1; /* thumb color, track color (Firefox) */
    -ms-overflow-style: auto;
}


    /* WebKit scrollbar for vertical scrolling (Chrome/Safari) */
    .chat-messages::-webkit-scrollbar {
        width: 16px; /* Increased from 14px to 16px */
    }

    .chat-messages::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 10px;
        border: 1px solid #ddd;
    }

    .chat-messages::-webkit-scrollbar-thumb {
        background: #007bff;
        border-radius: 10px;
        border: 3px solid #f1f1f1;
        min-height: 40px;
    }

        .chat-messages::-webkit-scrollbar-thumb:hover {
            background: #0056b3;
        }

    /* TABLES */
    /* 1. Make tables auto-size columns but never explode */
    .chat-messages table {
        width: 100% !important;
        table-layout: fixed; /* THIS IS THE KEY: forces column widths */
        border-collapse: collapse;
        margin: 15px 0;
        border: 1px solid #ddd;
        overflow: hidden;
        background: white;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }

    /* 2. Give each column exactly the width it deserves */
    .chat-messages th,
    .chat-messages td {
        width: 100px;
    }

        /* 3. Force long URLs to wrap/fold instead of staying on one line */
        .chat-messages td a {
            display: inline-block;
            word-break: break-all; /* break at any character */
            hyphens: auto; /* add hyphens where possible */
        }

    /* 4. Wrap the table in its own scroll container using display: block trick */
    .chat-messages table {
        display: block;
        overflow-x: auto; /* ← horizontal scrollbar ONLY when needed */
        overflow-y: hidden;
        white-space: nowrap;
    }

    /* 5. Restore normal row behavior */
    .chat-messages thead,
    .chat-messages tbody,
    .chat-messages tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    .chat-messages th,
    .chat-messages td {
        display: table-cell;
        white-space: normal; /* allow wrapping inside cells */
        padding: 8px 10px !important;
        word-wrap: break-word;
    }

    /* 6. Beautiful fat scrollbar under the table only */
    .chat-messages table::-webkit-scrollbar {
        height: 14px;
    }

    .chat-messages table::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 10px;
    }

    .chat-messages table::-webkit-scrollbar-thumb {
        background: #007bff;
        border-radius: 10px;
        border: 2.5px solid #f1f1f1;
    }

        .chat-messages table::-webkit-scrollbar-thumb:hover {
            background: #0056b3;
        }

/* MESSAGE BUBBLES */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.45;
    font-size: 14.5px;
    margin-bottom: 10px;
    animation: messagePop 0.3s ease-out;
}

@keyframes messagePop {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    background: linear-gradient(135deg, #dcf8c6, #a8e6cf);
    margin-left: auto;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.ai-message {
    background: white;
    margin-right: auto;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
    color: #2c3e50;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    max-width: 100%;
    padding-right: 10px;
    margin-right: 0;
}

.message a {
    color: #007bff;
    text-decoration: underline;
    font-weight: 500;
}

    .message a:hover {
        color: #0056b3;
        text-decoration: none;
    }

/* INPUT AREA */
.chat-input {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    border-top: 1px solid #dee2e6;
    padding: 15px;
    padding-right: 31px; /* 15px base + 16px scrollbar = 31px total */
    background: #f8f9fa;
    gap: 10px;
    z-index: 20;
}

    .chat-input input {
        flex: 1;
        padding: 12px 16px;
        border: 1px solid #ced4da;
        border-radius: 25px;
        font-size: 14px;
        outline: none;
    }

        .chat-input input:focus {
            border-color: #007bff;
            box-shadow: 0 0 0 3px rgba(0,123,255,0.15);
        }

    .chat-input button {
        padding: 12px 24px;
        background: #007bff;
        color: white;
        border: none;
        border-radius: 25px;
        cursor: pointer;
        font-weight: 500;
        font-size: 14px;
        min-width: 70px;
    }

        .chat-input button:hover:not(:disabled) {
            background: #0056b3;
        }

/* MOBILE */
@media (max-width: 767px) {
    .chat-container {
        display: none;
    }

    .chat-toggle {
        display: none;
    }
}

/* CONVERSATION STARTERS */
.starter-buttons-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
    margin-bottom: 10px;
}

.starter-btn {
    display: inline-block;
    padding: 8px 14px;
    background: #e8f0ff;
    border: 1.5px solid #007bff;
    border-radius: 20px;
    color: #007bff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    user-select: none;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .starter-btn:hover {
        background: #007bff;
        color: white;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    }

    .starter-btn:active {
        transform: translateY(0);
    }
