/* ─────────────────────────────────────────────────────────────────────────
   SparkBI Chatbot Widget
   ───────────────────────────────────────────────────────────────────────── */

/* ─── Container ─────────────────────────────────────────────────────────── */
#sparkbi-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9990;
    font-family: var(--font-family, 'Montserrat', sans-serif);
}

/* ─── Toggle Button ─────────────────────────────────────────────────────── */
#sparkbi-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-orange, #f17a1f);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(241, 122, 31, 0.45);
    transition: background 250ms ease, transform 250ms ease, box-shadow 250ms ease;
    position: relative;
    z-index: 1;
}

#sparkbi-chat-toggle:hover {
    background: var(--color-orange-hover, #e06810);
    transform: scale(1.07);
    box-shadow: 0 6px 28px rgba(241, 122, 31, 0.55);
}

#sparkbi-chat-toggle:focus-visible {
    outline: 3px solid var(--color-orange, #f17a1f);
    outline-offset: 3px;
}

.chat-toggle-icon {
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 200ms ease, transform 200ms ease;
}

.chat-toggle-icon--open  { position: absolute; }
.chat-toggle-icon--close { position: absolute; opacity: 0; transform: rotate(-90deg); }

#sparkbi-chat-toggle[aria-expanded="true"] .chat-toggle-icon--open  { opacity: 0; transform: rotate(90deg); }
#sparkbi-chat-toggle[aria-expanded="true"] .chat-toggle-icon--close { opacity: 1; transform: rotate(0deg); }

/* ─── Unread Badge ──────────────────────────────────────────────────────── */
#sparkbi-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--color-navy, #06193e);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0);
    transition: opacity 200ms ease, transform 200ms ease;
    pointer-events: none;
}

#sparkbi-chat-badge.visible {
    opacity: 1;
    transform: scale(1);
}

/* ─── Panel ─────────────────────────────────────────────────────────────── */
#sparkbi-chat-panel {
    position: absolute;
    bottom: 68px;
    right: 0;
    width: 360px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(6, 25, 62, 0.18), 0 4px 16px rgba(6, 25, 62, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 280ms cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1),
                visibility 280ms,
                width 220ms ease,
                height 220ms ease;
    visibility: hidden;
    pointer-events: none;
}

#sparkbi-chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    pointer-events: all;
}

/* ─── Resize Handle ─────────────────────────────────────────────────────── */
#sparkbi-chat-resize {
    position: absolute;
    top: 0;
    left: 0;
    width: 22px;
    height: 22px;
    cursor: nwse-resize;
    z-index: 10;
    border-radius: 16px 0 0 0;
}

#sparkbi-chat-resize::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    width: 9px;
    height: 9px;
    border-top: 2px solid rgba(255, 255, 255, 0.35);
    border-left: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 2px 0 0 0;
}

@media (max-width: 480px) {
    #sparkbi-chat-resize { display: none; }
}

/* ─── Reset Size Button ──────────────────────────────────────────────────── */
#sparkbi-chat-reset-size {
    display: none;
}

#sparkbi-chat-reset-size.visible {
    display: flex;
}

/* ─── Panel Header ──────────────────────────────────────────────────────── */
.chat-header {
    background: var(--color-navy, #06193e);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-orange, #f17a1f);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.chat-header-name {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.2;
}

.chat-header-status {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.65);
    margin-top: 2px;
}

.chat-header-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 200ms ease, background 200ms ease;
    flex-shrink: 0;
}

.chat-header-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* ─── Messages Area ─────────────────────────────────────────────────────── */
#sparkbi-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#sparkbi-chat-messages::-webkit-scrollbar {
    width: 4px;
}
#sparkbi-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#sparkbi-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(6, 25, 62, 0.15);
    border-radius: 2px;
}

/* ─── Message Bubbles ───────────────────────────────────────────────────── */
.chat-message {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    animation: chatMsgIn 200ms ease forwards;
    word-break: break-word;
}

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-message--assistant {
    align-self: flex-start;
    background: #f0f2f5;
    color: #1a2035;
    border-bottom-left-radius: 4px;
}

.chat-message--user {
    align-self: flex-end;
    background: var(--color-navy, #06193e);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* ─── Markdown in assistant bubbles ────────────────────────────────────── */
.chat-message--assistant strong {
    font-weight: 700;
}

.chat-message--assistant code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    background: rgba(6, 25, 62, 0.07);
    padding: 1px 5px;
    border-radius: 4px;
}

.chat-message--assistant ul {
    margin: 6px 0 4px;
    padding-left: 18px;
    list-style: disc;
}

.chat-message--assistant li {
    margin-bottom: 3px;
}

.chat-message--assistant pre {
    margin: 6px 0 2px;
    background: #1a2035;
    border-radius: 8px;
    overflow-x: auto;
    padding: 12px 14px;
}

.chat-message--assistant pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    color: #e8ecf4;
    line-height: 1.6;
    white-space: pre;
}

.chat-code-lang {
    display: block;
    font-family: 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.4);
    background: #1a2035;
    padding: 6px 14px 0;
    border-radius: 8px 8px 0 0;
    margin-bottom: -6px;
}

.chat-code-lang + pre {
    border-radius: 0 0 8px 8px;
    margin-top: 0;
}

.chat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    margin: 6px 0 2px;
}

.chat-table th,
.chat-table td {
    padding: 6px 10px;
    text-align: left;
    border: 1px solid rgba(6, 25, 62, 0.12);
}

.chat-table th {
    background: rgba(6, 25, 62, 0.06);
    font-weight: 700;
    font-size: 12px;
}

.chat-table tr:nth-child(even) td {
    background: rgba(6, 25, 62, 0.03);
}

/* Wider bubble for code blocks and tables */
.chat-message--assistant:has(pre),
.chat-message--assistant:has(.chat-table) {
    max-width: 96%;
}

/* ─── Typing Indicator ──────────────────────────────────────────────────── */
.chat-message--typing {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-message--typing span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-navy, #06193e);
    opacity: 0.35;
    animation: chatDot 1.2s ease-in-out infinite;
}

.chat-message--typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-message--typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatDot {
    0%, 80%, 100% { opacity: 0.35; transform: scale(1); }
    40%            { opacity: 1;    transform: scale(1.3); }
}

/* ─── Suggestion Chips ──────────────────────────────────────────────────── */
#sparkbi-chat-suggestions {
    display: none;
    padding: 4px 16px 10px;
    flex-wrap: wrap;
    gap: 7px;
    flex-shrink: 0;
}

#sparkbi-chat-suggestions.visible {
    display: flex;
}

.chat-chip {
    background: #fff;
    color: var(--color-navy, #06193e);
    border: 1.5px solid rgba(6, 25, 62, 0.2);
    border-radius: 20px;
    padding: 6px 13px;
    font-family: var(--font-family, 'Montserrat', sans-serif);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
    line-height: 1.3;
    text-align: left;
}

.chat-chip:hover {
    background: var(--color-navy, #06193e);
    border-color: var(--color-navy, #06193e);
    color: #fff;
}

/* ─── Input Area ────────────────────────────────────────────────────────── */
.chat-input-area {
    padding: 12px 14px;
    border-top: 1px solid rgba(6, 25, 62, 0.08);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #fff;
    flex-shrink: 0;
}

#sparkbi-chat-input {
    flex: 1;
    border: 1.5px solid rgba(6, 25, 62, 0.15);
    border-radius: 10px;
    padding: 9px 12px;
    font-family: var(--font-family, 'Montserrat', sans-serif);
    font-size: 13px;
    line-height: 1.45;
    color: #1a2035;
    resize: none;
    min-height: 38px;
    max-height: 100px;
    outline: none;
    transition: border-color 200ms ease;
    background: #fafbfc;
}

#sparkbi-chat-input:focus {
    border-color: var(--color-orange, #f17a1f);
    background: #fff;
}

#sparkbi-chat-input::placeholder {
    color: rgba(6, 25, 62, 0.35);
}

#sparkbi-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--color-orange, #f17a1f);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 200ms ease, transform 150ms ease;
    color: #fff;
}

#sparkbi-chat-send:hover:not(:disabled) {
    background: var(--color-orange-hover, #e06810);
    transform: scale(1.05);
}

#sparkbi-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── Form-fill Action Button ───────────────────────────────────────────── */
.chat-form-action {
    align-self: flex-start;
    width: 100%;
    padding: 4px 0 2px;
}

.chat-form-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--color-navy, #06193e);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-family: var(--font-family, 'Montserrat', sans-serif);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 200ms ease, transform 150ms ease;
    max-width: 100%;
}

.chat-form-btn::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    flex-shrink: 0;
}

.chat-form-btn:hover {
    background: #0d2a6b;
    transform: translateY(-1px);
}

.chat-form-done {
    display: block;
    font-size: 12.5px;
    color: #2a7a4b;
    font-weight: 600;
    padding: 8px 0 4px;
}

/* ─── Disclaimer ────────────────────────────────────────────────────────── */
.chat-disclaimer {
    text-align: center;
    font-size: 10.5px;
    color: rgba(6, 25, 62, 0.38);
    padding: 4px 14px 10px;
    line-height: 1.4;
    flex-shrink: 0;
    margin: 0;
}

.chat-disclaimer a {
    color: rgba(6, 25, 62, 0.5);
    text-decoration: underline;
    transition: color 150ms ease;
}

.chat-disclaimer a:hover {
    color: var(--color-navy, #06193e);
}

/* ─── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #sparkbi-chat {
        bottom: 16px;
        right: 16px;
    }

    #sparkbi-chat-panel {
        width: calc(100vw - 32px);
        max-height: 70vh;
        right: 0;
    }
}
