/* =========================================================
   Perga Copilot — Floating Chatbot Widget
   Styles for FAB button + slide-up panel + message bubbles
   ========================================================= */

/* ── Floating Action Button ───────────────────────────── */

.chatbot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--pg-color-primary, #0070f2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    color: #fff;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}

.chatbot-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.chatbot-fab:focus-visible {
    outline: 2px solid var(--pg-color-primary, #0070f2);
    outline-offset: 3px;
}

.chatbot-fab svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Panel ────────────────────────────────────────────── */

.chatbot-panel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--pg-color-surface, #ffffff);
    border: 1px solid var(--pg-color-border, #e0e0e0);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 8999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatbot-panel--closed {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

/* ── Header ───────────────────────────────────────────── */

.chatbot-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--pg-color-border, #e0e0e0);
    background: var(--pg-color-surface-raised, #f7f7f7);
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
}

.chatbot-panel__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--pg-color-text-primary, #1a1a1a);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-panel__title-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
}

.chatbot-panel__close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--pg-color-text-secondary, #666);
    font-size: 16px;
    line-height: 1;
    border-radius: 4px;
    transition: color 0.1s;
}

.chatbot-panel__close:hover {
    color: var(--pg-color-text-primary, #1a1a1a);
    background: var(--pg-color-border, #e0e0e0);
}

/* ── Message thread ───────────────────────────────────── */

.chatbot-panel__thread {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.chatbot-panel__thread:empty::before {
    content: "Ask anything about your SAP project…";
    color: var(--pg-color-text-secondary, #999);
    font-size: 13px;
    text-align: center;
    margin: auto;
    padding: 24px;
}

/* ── Message bubbles ──────────────────────────────────── */

.chatbot-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
}

.chatbot-msg--user {
    align-self: flex-end;
}

.chatbot-msg--assistant {
    align-self: flex-start;
}

.chatbot-msg__meta {
    font-size: 10px;
    color: var(--pg-color-text-secondary, #999);
    margin-bottom: 3px;
    padding: 0 4px;
}

.chatbot-msg--user .chatbot-msg__meta {
    text-align: right;
}

.chatbot-msg__bubble {
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}

.chatbot-msg--user .chatbot-msg__bubble {
    background: var(--pg-color-primary, #0070f2);
    color: #ffffff;
    border-radius: 12px 12px 2px 12px;
}

.chatbot-msg--assistant .chatbot-msg__bubble {
    background: var(--pg-color-surface-raised, #f5f5f5);
    color: var(--pg-color-text-primary, #1a1a1a);
    border-radius: 12px 12px 12px 2px;
    border: 1px solid var(--pg-color-border, #e8e8e8);
}

/* Error state */
.chatbot-msg__bubble--error {
    background: #fff1f0;
    border-color: #ffa39e;
    color: #cf1322;
}

/* Loading skeleton bubble */
.chatbot-msg__bubble--loading {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--pg-color-text-secondary, #999);
    font-style: italic;
}

.chatbot-loading-dots {
    display: flex;
    gap: 3px;
}

.chatbot-loading-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--pg-color-text-secondary, #bbb);
    animation: chatbot-bounce 1.2s ease-in-out infinite;
}

.chatbot-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-4px); }
}

/* Streaming cursor blink */
.chatbot-streaming-cursor::after {
    content: "▌";
    animation: chatbot-blink 0.8s step-end infinite;
    color: var(--pg-color-primary, #0070f2);
    font-size: 12px;
}

@keyframes chatbot-blink {
    50% { opacity: 0; }
}

/* ── NL query result table ────────────────────────────── */

.chatbot-nl-result {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chatbot-nl-answer {
    font-size: 13px;
    line-height: 1.5;
}

.chatbot-nl-table-wrap {
    max-height: 200px;
    overflow: auto;
    border-radius: 6px;
    border: 1px solid var(--pg-color-border, #e0e0e0);
}

.chatbot-nl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
}

.chatbot-nl-table th,
.chatbot-nl-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--pg-color-border, #e8e8e8);
    text-align: left;
    white-space: nowrap;
}

.chatbot-nl-table th {
    background: var(--pg-color-surface-raised, #f5f5f5);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.chatbot-nl-table tr:last-child td {
    border-bottom: none;
}

.chatbot-nl-rowcount {
    font-size: 11px;
    color: var(--pg-color-text-secondary, #999);
}

/* ── Composer ─────────────────────────────────────────── */

.chatbot-panel__composer {
    padding: 8px 12px;
    border-top: 1px solid var(--pg-color-border, #e0e0e0);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--pg-color-surface, #ffffff);
}

.chatbot-panel__input {
    flex: 1;
    resize: none;
    border: 1px solid var(--pg-color-border, #d0d0d0);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.45;
    color: var(--pg-color-text-primary, #1a1a1a);
    background: var(--pg-color-surface, #ffffff);
    transition: border-color 0.15s;
    outline: none;
}

.chatbot-panel__input:focus {
    border-color: var(--pg-color-primary, #0070f2);
}

.chatbot-panel__input::placeholder {
    color: var(--pg-color-text-secondary, #bbb);
}

.chatbot-panel__send {
    padding: 8px 14px;
    border-radius: 8px;
    background: var(--pg-color-primary, #0070f2);
    color: #ffffff;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    flex-shrink: 0;
    transition: opacity 0.15s;
    outline: none;
    line-height: 1;
}

.chatbot-panel__send:disabled {
    opacity: 0.45;
    cursor: default;
}

.chatbot-panel__send:not(:disabled):hover {
    opacity: 0.88;
}

.chatbot-panel__send:focus-visible {
    outline: 2px solid var(--pg-color-primary, #0070f2);
    outline-offset: 2px;
}

/* ── Mobile: full-width sheet ─────────────────────────── */

@media (max-width: 480px) {
    .chatbot-panel {
        width: 100vw;
        height: 70vh;
        bottom: 0;
        right: 0;
        border-radius: 12px 12px 0 0;
    }

    .chatbot-fab {
        bottom: 16px;
        right: 16px;
    }
}
