/**
 * Chat Widget Styles
 * Floating chat bubble and panel for LLM-powered database Q&A
 */

/* ========================================= */
/* FLOATING BUBBLE                           */
/* ========================================= */

.chat-widget-bubble {
    position: fixed;
    bottom: 100px;
    right: 30px;
    height: 56px;
    width: auto;
    padding: 0 20px 0 16px;
    background: #2c3e50;
    color: white;
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(44, 62, 80, 0.35);
    transition: padding 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.3s ease,
                background 0.3s ease,
                box-shadow 0.3s ease,
                transform 0.2s ease;
    z-index: 1100;
    border: 2px solid rgba(255, 255, 255, 0.3);
    animation: chat-bubble-enter 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Glow layer: GPU-composited via opacity instead of animating box-shadow */
.chat-widget-bubble::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 20px 6px rgba(44, 62, 80, 0.3);
    opacity: 0;
    animation: chat-bubble-glow 2.5s ease-in-out 1.5s infinite;
    pointer-events: none;
}

.chat-widget-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 35px rgba(44, 62, 80, 0.5);
}

.chat-widget-bubble-icon {
    font-size: 1.3rem;
    line-height: 1;
    flex-shrink: 0;
}

.chat-widget-bubble.open .chat-widget-bubble-icon::before {
    content: '\f659'; /* bi-x-lg */
}

/* Text label inside the pill */
.chat-widget-bubble-label {
    display: inline-block;
    white-space: nowrap;
    font-size: 0.85rem;
    font-weight: 600;
    max-width: 200px;
    opacity: 1;
    margin-left: 8px;
    transition: opacity 0.3s ease, max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1), margin 0.4s ease;
    overflow: hidden;
}

/* Collapsed state: pill → circle */
.chat-widget-bubble--collapsed {
    width: 56px;
    padding: 0;
    border-radius: 50%;
}

.chat-widget-bubble--collapsed .chat-widget-bubble-label {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
}

/* Stop glow when collapsed or open */
.chat-widget-bubble--collapsed::before,
.chat-widget-bubble.open::before {
    animation: none;
    opacity: 0;
}

/* Open state: revert to dark circle with X */
.chat-widget-bubble.open {
    background: #2c3e50;
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    animation: none;
    box-shadow: 0 6px 25px rgba(44, 62, 80, 0.4);
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-widget-bubble.open:hover {
    transform: none;
    box-shadow: 0 8px 35px rgba(44, 62, 80, 0.5);
}

/* Hide label in open state too — user may click before auto-collapse fires */
.chat-widget-bubble.open .chat-widget-bubble-label {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
}

/* Entry animation: slide in from right */
@keyframes chat-bubble-enter {
    0%   { transform: translateX(120px) scale(0.8); opacity: 0; }
    60%  { transform: translateX(-8px) scale(1.02); opacity: 1; }
    80%  { transform: translateX(3px) scale(1); }
    100% { transform: translateX(0) scale(1); }
}

/* Pulsing glow on ::before pseudo — only opacity animates (GPU-composited) */
@keyframes chat-bubble-glow {
    0%, 100% { opacity: 0; }
    50%      { opacity: 1; }
}


/* ========================================= */
/* CHAT PANEL                                */
/* ========================================= */

.chat-widget-panel {
    position: fixed;
    bottom: 170px;
    right: 30px;
    width: 380px;
    height: 500px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1099;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.chat-widget-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========================================= */
/* PANEL HEADER                              */
/* ========================================= */

.chat-widget-header {
    background: #2c3e50;
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-widget-header-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.chat-widget-header-info {
    flex: 1;
    min-width: 0;
}

.chat-widget-header-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0;
}

.chat-widget-header-subtitle {
    font-size: 0.75rem;
    opacity: 0.7;
    margin: 0;
}

.chat-widget-header-newchat {
    color: #7ec8e3;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.2s ease;
}

.chat-widget-header-newchat:hover {
    color: #ffffff;
}

.chat-widget-header-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    font-size: 1.2rem;
    line-height: 1;
}

.chat-widget-header-close:hover {
    opacity: 1;
}

/* ========================================= */
/* MESSAGES AREA                             */
/* ========================================= */

.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-widget-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 2px;
}

/* Message bubble base */
.chat-widget-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: chat-message-in 0.3s ease;
}

@keyframes chat-message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User messages (right-aligned) */
.chat-widget-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-widget-message.user .chat-widget-message-bubble {
    background: #2c3e50;
    color: white;
    border-radius: 16px 16px 4px 16px;
}

/* Assistant messages (left-aligned) */
.chat-widget-message.assistant {
    align-self: flex-start;
}

.chat-widget-message-avatar {
    width: 28px;
    height: 28px;
    background: #2c3e50;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.7rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-widget-message-bubble {
    padding: 10px 14px;
    border-radius: 16px 16px 16px 4px;
    background: #f1f3f5;
    color: #212529;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

/* ========================================= */
/* MARKDOWN ELEMENTS IN CHAT BUBBLES         */
/* ========================================= */

/* -- Paragraphs: compact margins for chat feel -- */
.chat-widget-message-bubble p {
    margin: 0.3em 0;
}

/* -- Bold/italic: inherit font, change weight/style only -- */
.chat-widget-message-bubble strong {
    font-weight: 700;
}

.chat-widget-message-bubble em {
    font-style: italic;
}

/* -- Blockquotes: compact styling for chat feel -- */
.chat-widget-message-bubble blockquote {
    margin: 0.3em 0;
    padding-left: 0.8em;
    border-left: 3px solid #dee2e6;
    color: #495057;
}

/* -- Headings (h3/h4): modest size, bold, tight margins -- */
.chat-widget-message-bubble h3 {
    font-size: 1em;
    font-weight: 700;
    margin: 0.4em 0 0.2em;
    line-height: 1.3;
}

.chat-widget-message-bubble h4 {
    font-size: 0.95em;
    font-weight: 700;
    margin: 0.4em 0 0.2em;
    line-height: 1.3;
}

/* -- Lists (ul/ol): compact padding and tight spacing -- */
.chat-widget-message-bubble ul,
.chat-widget-message-bubble ol {
    margin: 0.3em 0;
    padding-left: 1.2em;
    line-height: 1.4;
}

.chat-widget-message-bubble li {
    margin: 0.1em 0;
}

.chat-widget-message-bubble li::marker {
    font-size: 0.85em;
}

/* -- Tables: full-width, thin borders, alternating rows -- */
.chat-widget-message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.4em 0;
    font-size: 0.85em;
    display: block;
    overflow-x: auto;
}

.chat-widget-message-bubble thead {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.chat-widget-message-bubble tbody {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.chat-widget-message-bubble th,
.chat-widget-message-bubble td {
    border: 1px solid #dee2e6;
    padding: 4px 8px;
    text-align: left;
}

.chat-widget-message-bubble th {
    font-weight: 600;
    background: #e9ecef;
}

.chat-widget-message-bubble tr:nth-child(even) {
    background: #f8f9fa;
}

/* -- Inline code: subtle background, small radius -- */
.chat-widget-message-bubble code {
    background: #e9ecef;
    border-radius: 3px;
    padding: 0.1em 0.3em;
    font-size: 0.85em;
}

/* -- Fenced code blocks (pre > code): background, scroll -- */
.chat-widget-message-bubble pre {
    margin: 0.4em 0;
    padding: 8px 10px;
    background: #e9ecef;
    border-radius: 6px;
    overflow-x: auto;
}

.chat-widget-message-bubble pre > code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 0.85em;
}

/* -- First/last child margin stripping -- */
.chat-widget-message-bubble > :first-child {
    margin-top: 0;
}

.chat-widget-message-bubble > :last-child {
    margin-bottom: 0;
}

/* Also strip margins inside the streaming wrapper div */
.chat-widget-stream-text > :first-child {
    margin-top: 0;
}

.chat-widget-stream-text > :last-child {
    margin-bottom: 0;
}

/* Welcome message */
.chat-widget-welcome {
    text-align: center;
    padding: 20px 16px;
    color: #6c757d;
    font-size: 0.85rem;
    line-height: 1.5;
}

.chat-widget-welcome-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    display: block;
}

.chat-widget-docs-link {
    display: block;
    margin-top: 10px;
    font-size: 0.78rem;
    color: #2c3e50;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.chat-widget-docs-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.chat-widget-docs-link i {
    font-size: 0.65rem;
    margin-left: 2px;
}

/* ========================================= */
/* SUGGESTION CHIPS                          */
/* ========================================= */

.chat-widget-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 16px 16px;
    justify-content: center;
}

.chat-widget-suggestion-chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border-radius: 18px;
    border: 1px solid #dee2e6;
    background: #fff;
    color: #2c3e50;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chat-widget-suggestion-chip:hover {
    background: #2c3e50;
    color: #fff;
    border-color: #2c3e50;
}

/* ========================================= */
/* CTA BUTTONS IN MESSAGES                   */
/* ========================================= */

.chat-widget-cta {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    margin-top: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-widget-cta-calculator {
    background: #0066cc;
    color: white;
}

.chat-widget-cta-calculator:hover {
    background: #0055aa;
    color: white;
    transform: translateY(-1px);
}

/* ========================================= */
/* TYPING INDICATOR                          */
/* ========================================= */

.chat-widget-typing {
    display: flex;
    gap: 8px;
    align-self: flex-start;
    max-width: 85%;
}

.chat-widget-typing .chat-widget-message-avatar {
    width: 28px;
    height: 28px;
}

.chat-widget-typing-dots {
    padding: 12px 18px;
    background: #f1f3f5;
    border-radius: 16px 16px 16px 4px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.chat-widget-typing-dot {
    width: 7px;
    height: 7px;
    background: #adb5bd;
    border-radius: 50%;
    animation: chat-typing 1.4s infinite;
}

.chat-widget-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-widget-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chat-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ========================================= */
/* INPUT AREA                                */
/* ========================================= */

.chat-widget-input-area {
    padding: 12px;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: #ffffff;
}

.chat-widget-pd-disclosure {
    padding: 0 14px 10px;
    font-size: 0.7rem;
    color: #6c757d;
    background: #ffffff;
    flex-shrink: 0;
    line-height: 1.3;
}

.chat-widget-pd-disclosure a {
    color: #6c757d;
    text-decoration: underline;
}

.chat-widget-pd-disclosure a:hover {
    color: var(--primary-color, #1976d2);
}

.chat-widget-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #dee2e6;
    border-radius: 20px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    font-family: inherit;
}

.chat-widget-input:focus {
    border-color: #2c3e50;
}

.chat-widget-input::placeholder {
    color: #adb5bd;
}

.chat-widget-send {
    width: 40px;
    height: 40px;
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    align-self: flex-end;
}

.chat-widget-send:hover {
    background: #1a252f;
    transform: scale(1.05);
}

.chat-widget-send:disabled {
    background: #adb5bd;
    cursor: not-allowed;
    transform: none;
}

.chat-widget-send i {
    font-size: 1rem;
}

/* ========================================= */
/* STREAMING CURSOR & TOOL PILLS             */
/* ========================================= */

.chat-widget-stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: currentColor;
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: chat-cursor-blink 0.7s infinite;
}

@keyframes chat-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.chat-widget-tool-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 4px 0;
    padding: 3px 8px;
    background: rgba(45, 90, 62, 0.2);
    border: 1px solid rgba(45, 90, 62, 0.4);
    border-radius: 4px;
    font-size: 0.75em;
    color: #6dba6d;
}

.chat-widget-tool-pill.complete {
    background: rgba(45, 90, 62, 0.1);
    color: #4a9a4a;
}

.chat-widget-tool-spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 1.5px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: chat-tool-spin 0.8s linear infinite;
}

.chat-widget-tool-pill.complete .chat-widget-tool-spinner {
    border: none;
    animation: none;
    width: auto;
    height: auto;
}

@keyframes chat-tool-spin {
    to { transform: rotate(360deg); }
}

/* ========================================= */
/* PEEK CARD (Proactive CTA)                */
/* ========================================= */

.chat-widget-peek-card {
    position: fixed;
    bottom: 170px;
    right: 30px;
    max-width: 280px;
    padding: 14px 32px 14px 14px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1098;
    cursor: pointer;
    animation: chat-peek-in 250ms ease-out both;
    transition: opacity 150ms ease-out;
}

/* Dismissal state — animation:none removes fill-mode lock so transition works */
.chat-widget-peek-card--leaving {
    animation: none;
    opacity: 0;
}

/* Arrow/tail pointing down toward the bubble */
.chat-widget-peek-card::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 16px;
    height: 16px;
    background: #ffffff;
    transform: rotate(45deg);
    box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
}

.chat-widget-peek-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #212529;
    word-wrap: break-word;
}

.chat-widget-peek-card .chat-widget-cta {
    display: block;
    text-align: center;
    margin-top: 10px;
}

/* Close (X) button */
.chat-widget-peek-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    color: #adb5bd;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    transition: color 0.15s ease, background 0.15s ease;
}

.chat-widget-peek-close:hover {
    color: #495057;
    background: #f1f3f5;
}

/* Notification dot on bubble */
.chat-widget-bubble--has-notification::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #e74c3c;
    border-radius: 50%;
    border: 2px solid #2c3e50;
    animation: chat-notification-pulse 2s infinite;
}

/* Peek card animations */
@keyframes chat-peek-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chat-notification-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* ========================================= */
/* RESPONSIVE                                */
/* ========================================= */

@media (max-width: 768px) {
    .chat-widget-bubble,
    .chat-widget-panel,
    .chat-widget-peek-card {
        display: none !important;
    }
}



/* ========================================= */
/* ACCESSIBILITY                             */
/* ========================================= */

@media (prefers-reduced-motion: reduce) {
    .chat-widget-bubble,
    .chat-widget-panel,
    .chat-widget-message,
    .chat-widget-cta,
    .chat-widget-peek-card {
        animation: none;
        transition: opacity 0.2s ease;
    }

    .chat-widget-bubble-label {
        transition: none;
    }

    .chat-widget-bubble-icon {
        animation: none;
    }

    .chat-widget-typing-dot {
        animation: none;
        opacity: 0.6;
    }

    .chat-widget-stream-cursor {
        animation: none;
        opacity: 1;
    }

    .chat-widget-tool-spinner {
        animation: none;
    }

    .chat-widget-bubble--has-notification::after {
        animation: none;
    }
}

.chat-widget-bubble:focus,
.chat-widget-send:focus,
.chat-widget-header-close:focus,
.chat-widget-input:focus,
.chat-widget-peek-close:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* Hide widget when other modals are active */
.chat-widget-bubble.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
