/* ============================================================
   Chat Widget — Enterprise AI Assistant
   ============================================================ */

#chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1055;
    display: flex;
    flex-direction: column;
    align-items: flex-end;

    /* Theme tokens scoped to the widget */
    --cw-bg:        #0d1117;
    --cw-surface:   #161b22;
    --cw-surface-2: #1c2128;
    --cw-surface-3: #21262d;
    --cw-border:    #30363d;
    --cw-accent:    #2f81f7;
    --cw-accent-dk: #1c6fd6;
    --cw-text:      #e6edf3;
    --cw-muted:     #8b949e;
    --cw-subtle:    #6e7681;
    --cw-success:   #3fb950;
}

/* ── Toggle Button ─────────────────────────────────────────── */

.chat-toggle-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cw-accent) 0%, var(--cw-accent-dk) 100%);
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(47, 129, 247, 0.45), 0 2px 6px rgba(0, 0, 0, 0.45);
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(47, 129, 247, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
}

.chat-toggle-btn:active {
    transform: scale(0.94);
}

/* ── Chat Panel ────────────────────────────────────────────── */

.chat-panel {
    width: 360px;
    height: 500px;
    min-width: 300px;
    min-height: 380px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 100px);
    background-color: var(--cw-surface);
    border-radius: 14px;
    border: 1px solid var(--cw-border);
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.65),
        0 0 0 1px rgba(47, 129, 247, 0.06);
    overflow: hidden;
    transform-origin: bottom right;
    animation: chat-open 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition:
        width  0.25s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    resize: both;
}

.chat-panel--expanded {
    width: min(640px, calc(100vw - 48px));
    height: min(680px, calc(100vh - 100px));
}

@media (max-width: 680px) {
    .chat-panel--expanded {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
    }
}

@keyframes chat-open {
    from { opacity: 0; transform: scale(0.88) translateY(14px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

.chat-panel--hidden {
    display: none !important;
}

/* ── Header ────────────────────────────────────────────────── */

.chat-header {
    background-color: var(--cw-surface-2);
    border-bottom: 1px solid var(--cw-border);
    padding: 11px 10px 11px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(145deg, var(--cw-accent) 0%, var(--cw-accent-dk) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.9rem;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 2px 8px rgba(47, 129, 247, 0.35);
}

/* Online status dot */
.chat-header-avatar::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background-color: var(--cw-success);
    border-radius: 50%;
    border: 2px solid var(--cw-surface-2);
    animation: status-pulse 2.8s infinite;
}

@keyframes status-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(63, 185, 80, 0.5); }
    70%  { box-shadow: 0 0 0 5px rgba(63, 185, 80, 0);   }
    100% { box-shadow: 0 0 0 0   rgba(63, 185, 80, 0);   }
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.chat-header-title {
    color: var(--cw-text);
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
}

.chat-header-subtitle {
    color: var(--cw-muted);
    font-size: 0.71rem;
    line-height: 1.2;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 1px;
}

.chat-header-btn {
    background: none;
    border: none;
    color: var(--cw-muted);
    cursor: pointer;
    font-size: 0.8rem;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background-color 0.15s;
}

.chat-header-btn:hover {
    color: var(--cw-text);
    background-color: rgba(255, 255, 255, 0.07);
}

/* ── Messages ──────────────────────────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: var(--cw-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--cw-border) transparent;
}

.chat-messages::-webkit-scrollbar       { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background-color: var(--cw-border); border-radius: 2px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background-color: #484f58; }

/* Message row */
.chat-message {
    display: flex;
    flex-direction: column;
    gap: 3px;
    animation: msg-in 0.16s ease-out;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(7px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.chat-message--user { align-items: flex-end; }
.chat-message--ai   { align-items: flex-start; }

/* Bubbles */
.chat-bubble {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-message--user .chat-bubble {
    background: linear-gradient(145deg, var(--cw-accent) 0%, var(--cw-accent-dk) 100%);
    color: #fff;
    border-bottom-right-radius: 3px;
    box-shadow: 0 2px 10px rgba(47, 129, 247, 0.25);
}

.chat-message--ai .chat-bubble {
    background-color: var(--cw-surface-2);
    color: var(--cw-text);
    border: 1px solid var(--cw-border);
    border-bottom-left-radius: 3px;
}

/* Timestamp */
.chat-timestamp {
    font-size: 0.68rem;
    color: var(--cw-subtle);
    padding: 0 2px;
}

/* Navigate CTA button */
.chat-navigate-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 10px;
    padding: 7px 14px;
    background: linear-gradient(145deg, var(--cw-accent) 0%, var(--cw-accent-dk) 100%);
    color: #fff !important;
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s, transform 0.12s;
    box-shadow: 0 2px 10px rgba(47, 129, 247, 0.35);
}

.chat-navigate-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    color: #fff;
}

.chat-navigate-btn:active {
    transform: translateY(0);
}

/* ── Export Download Button ────────────────────────────────── */

.chat-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    background: linear-gradient(145deg, #1a7a4a 0%, #145c38 100%);
    color: #fff !important;
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s, transform 0.12s;
    box-shadow: 0 2px 10px rgba(26, 122, 74, 0.40);
    width: fit-content;
}

.chat-export-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    color: #fff;
}

.chat-export-btn:active {
    transform: translateY(0);
}

/* ── Typing Indicator ──────────────────────────────────────── */

.chat-typing {
    padding: 2px 14px 10px;
    background-color: var(--cw-bg);
    flex-shrink: 0;
}

.typing-dots {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    background-color: var(--cw-surface-2);
    border: 1px solid var(--cw-border);
    border-radius: 12px;
    border-bottom-left-radius: 3px;
    padding: 8px 13px;
}

.typing-dots span {
    width: 5px;
    height: 5px;
    background-color: var(--cw-muted);
    border-radius: 50%;
    animation: typing-bounce 1.3s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.3; }
    30%           { transform: translateY(-4px); opacity: 1;   }
}

/* ── Input Area ────────────────────────────────────────────── */

.chat-input-area {
    padding: 10px 12px 8px;
    background-color: var(--cw-surface);
    border-top: 1px solid var(--cw-border);
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background-color: var(--cw-surface-2);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
    padding: 7px 7px 7px 13px;
    transition: border-color 0.18s, box-shadow 0.18s;
}

.chat-input-row:focus-within {
    border-color: var(--cw-accent);
    box-shadow: 0 0 0 3px rgba(47, 129, 247, 0.12);
}

.chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--cw-text);
    font-size: 0.875rem;
    outline: none;
    resize: none;
    min-height: 22px;
    max-height: 110px;
    line-height: 1.55;
    padding: 2px 0;
    font-family: inherit;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cw-border) transparent;
}

.chat-input::placeholder { color: var(--cw-subtle); }
.chat-input:disabled      { opacity: 0.5; }

.chat-send-btn {
    width: 32px;
    height: 32px;
    background: linear-gradient(145deg, var(--cw-accent) 0%, var(--cw-accent-dk) 100%);
    border: none;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.12s;
    box-shadow: 0 2px 6px rgba(47, 129, 247, 0.3);
}

.chat-send-btn:hover:not(:disabled) { opacity: 0.85; transform: scale(1.06); }
.chat-send-btn:active:not(:disabled) { transform: scale(0.94); }
.chat-send-btn:disabled {
    background: var(--cw-surface-3);
    box-shadow: none;
    cursor: not-allowed;
}

.chat-input-hint {
    font-size: 0.68rem;
    color: var(--cw-subtle);
    margin-top: 5px;
    text-align: right;
}

/* ── Suggestions toggle button ────────────────────────────── */

.chat-suggestions-btn {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--cw-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1px;
    transition: color 0.15s, background-color 0.15s;
}

.chat-suggestions-btn:hover,
.chat-suggestions-btn.active {
    color: var(--cw-accent);
    background-color: rgba(47, 129, 247, 0.1);
}

/* ── Suggestions panel (floats above input, below messages) ── */

.chat-suggestions-panel {
    border-top: 1px solid var(--cw-border);
    background: var(--cw-surface-2);
    padding: 10px 14px 10px;
    flex-shrink: 0;
}

.chat-suggestions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.chat-suggestions-title {
    font-size: 0.68rem;
    color: var(--cw-subtle);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chat-suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 130px;
    overflow-y: auto;
}

.chat-suggestions-loading {
    font-size: 0.78rem;
    color: var(--cw-subtle);
    padding: 2px 0;
}

/* ── Preset Quick-Question Chips ──────────────────────────── */

.chat-presets {
    padding: 4px 0 2px;
}

.chat-presets-label {
    font-size: 0.68rem;
    color: var(--cw-subtle);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 7px;
}

.chat-presets-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chat-preset-chip,
.chat-suggestion-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    background: var(--cw-surface-2);
    border: 1px solid var(--cw-border);
    border-radius: 20px;
    color: var(--cw-muted);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background-color 0.15s;
    white-space: nowrap;
    user-select: none;
    line-height: 1.3;
}

.chat-preset-chip:hover,
.chat-suggestion-chip:hover {
    border-color: var(--cw-accent);
    color: var(--cw-text);
    background-color: rgba(47, 129, 247, 0.08);
}

.chat-preset-chip:active,
.chat-suggestion-chip:active {
    background-color: rgba(47, 129, 247, 0.15);
}

