/* ── Shared chat styles (used by widget + full page) ───── */

:root {
    --cgsp-bg:          #FFFFFF;
    --cgsp-surface:     #F5F0E8;
    --cgsp-surface-alt: #EDE7DB;
    --cgsp-text:        #3B2F24;
    --cgsp-text-light:  #8B7355;
    --cgsp-accent:      #9B3B2B;
    --cgsp-accent-light:#C85A48;
    --cgsp-border:      #D6CCBC;
    --cgsp-user-bubble: #5C4033;
    --cgsp-taupe:       #947D74;
    --cgsp-brown:       #6C594F;
    --cgsp-cream:       #F6F1EC;
    --cgsp-radius:      12px;
    --cgsp-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Messages area ─────────────────────────────────────── */

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

.cgsp-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

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

.cgsp-msg-ai {
    align-self: flex-start;
}

.cgsp-msg-bubble {
    padding: 12px 16px;
    border-radius: var(--cgsp-radius);
    line-height: 1.55;
    font-size: 15px;
    word-wrap: break-word;
    font-family: var(--cgsp-font);
}

.cgsp-msg-user .cgsp-msg-bubble {
    background: var(--cgsp-user-bubble);
    color: #FFF;
    border-bottom-right-radius: 4px;
}

.cgsp-msg-ai .cgsp-msg-bubble {
    background: var(--cgsp-surface);
    color: var(--cgsp-text);
    border-bottom-left-radius: 4px;
}

.cgsp-msg-ai .cgsp-msg-bubble a {
    color: var(--cgsp-accent);
    text-decoration: underline;
}

/* ── Markdown blocks rendered from API answers ─────────── */

.cgsp-msg-ai .cgsp-msg-bubble p {
    margin: 0 0 8px;
}

.cgsp-msg-ai .cgsp-msg-bubble p:last-child {
    margin-bottom: 0;
}

.cgsp-msg-ai .cgsp-msg-bubble h3,
.cgsp-msg-ai .cgsp-msg-bubble h4 {
    margin: 12px 0 4px;
    font-family: var(--cgsp-font);
    font-weight: 700;
    line-height: 1.3;
    color: var(--cgsp-text);
}

.cgsp-msg-ai .cgsp-msg-bubble h3 {
    font-size: 16px;
}

.cgsp-msg-ai .cgsp-msg-bubble h4 {
    font-size: 15px;
}

.cgsp-msg-ai .cgsp-msg-bubble h3:first-child,
.cgsp-msg-ai .cgsp-msg-bubble h4:first-child {
    margin-top: 0;
}

.cgsp-msg-ai .cgsp-msg-bubble ul,
.cgsp-msg-ai .cgsp-msg-bubble ol {
    margin: 4px 0 8px 20px;
    padding: 0;
}

.cgsp-msg-ai .cgsp-msg-bubble ul {
    list-style: disc;
}

.cgsp-msg-ai .cgsp-msg-bubble ol {
    list-style: decimal;
}

.cgsp-msg-ai .cgsp-msg-bubble li {
    margin: 0 0 4px;
}

.cgsp-msg-ai .cgsp-msg-bubble code {
    font-family: SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--cgsp-surface-alt);
}

/* ── Refusal ───────────────────────────────────────────── */

.cgsp-refusal {
    padding: 4px 0;
}

.cgsp-refusal strong {
    color: var(--cgsp-accent);
}

/* ── Typing indicator ──────────────────────────────────── */

.cgsp-typing .cgsp-msg-bubble {
    display: flex;
    gap: 5px;
    padding: 14px 20px;
}

.cgsp-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cgsp-text-light);
    animation: cgsp-bounce 1.4s infinite ease-in-out both;
}

.cgsp-dot:nth-child(1) { animation-delay: -0.32s; }
.cgsp-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes cgsp-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* ── Sources ───────────────────────────────────────────── */

.cgsp-sources {
    margin-top: 8px;
    padding-left: 4px;
    max-height: 40vh;
    overflow-y: auto;
}

.cgsp-sources-heading {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--cgsp-text-light);
    margin-bottom: 6px;
    font-family: var(--cgsp-font);
}

.cgsp-source-card {
    display: block;
    padding: 6px 10px;
    margin-bottom: 3px;
    background: var(--cgsp-surface-alt);
    border-radius: 8px;
    text-decoration: none;
    color: var(--cgsp-text);
    transition: background 0.15s;
    font-family: var(--cgsp-font);
}

.cgsp-source-card:hover {
    background: var(--cgsp-border);
}

.cgsp-source-main {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    min-width: 0;
}

.cgsp-source-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    word-break: break-word;
    color: var(--cgsp-text);
}

.cgsp-source-url-full {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.45;
    color: var(--cgsp-accent);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.cgsp-source-card:hover .cgsp-source-url-full {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cgsp-source-date {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--cgsp-text-light);
    line-height: 1.3;
    margin-top: 1px;
}

.cgsp-source-chunk {
    font-size: 12px;
    line-height: 1.45;
    color: var(--cgsp-text-light);
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--cgsp-border);
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* ── Input bar ─────────────────────────────────────────── */

.cgsp-chat-input-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid var(--cgsp-border);
    flex-shrink: 0;
}

.cgsp-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--cgsp-border);
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    background: var(--cgsp-bg);
    color: var(--cgsp-text);
    font-family: var(--cgsp-font);
    transition: border-color 0.15s;
}

.cgsp-chat-input:focus {
    border-color: var(--cgsp-accent);
}

.cgsp-chat-input::placeholder {
    color: var(--cgsp-text-light);
}

.cgsp-chat-send-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--cgsp-user-bubble);
    color: #FFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.cgsp-chat-send-btn:hover:not(:disabled) {
    background: var(--cgsp-accent);
}

.cgsp-chat-send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.cgsp-chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ── Welcome / Full-page ───────────────────────────────── */

.cgsp-chat-welcome {
    text-align: center;
    padding: 40px 20px 20px;
    font-family: var(--cgsp-font);
}

.cgsp-chat-welcome h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--cgsp-text);
    margin: 0 0 8px;
    line-height: 1.2;
}

.cgsp-chat-welcome h1 .cgsp-ai-label {
    color: var(--cgsp-accent);
}

.cgsp-chat-welcome .cgsp-sparkle {
    color: var(--cgsp-accent);
    font-size: 0.7em;
    vertical-align: super;
}

.cgsp-chat-subtitle {
    font-size: 1.05rem;
    color: var(--cgsp-text-light);
    margin: 0 0 24px;
}

/* ── Quick action chips ────────────────────────────────── */

.cgsp-quick-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 32px;
}

.cgsp-quick-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 1px solid var(--cgsp-border);
    border-radius: 24px;
    background: var(--cgsp-bg);
    color: var(--cgsp-accent);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--cgsp-font);
    text-decoration: none;
}

.cgsp-quick-action:hover {
    background: var(--cgsp-surface);
    border-color: var(--cgsp-accent);
}

.cgsp-quick-action-custom {
    cursor: pointer;
}

/* ── Prompt cards ──────────────────────────────────────── */

.cgsp-prompt-cards {
    max-width: 620px;
    margin: 0 auto 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cgsp-prompt-heading {
    font-size: 13px;
    color: var(--cgsp-text-light);
    text-align: center;
    margin-bottom: 4px;
    font-family: var(--cgsp-font);
}

.cgsp-prompt-card {
    padding: 16px 20px;
    border: 1px solid var(--cgsp-border);
    border-radius: var(--cgsp-radius);
    background: var(--cgsp-bg);
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    text-align: left;
    font-family: var(--cgsp-font);
}

.cgsp-prompt-card:hover {
    background: var(--cgsp-surface);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.cgsp-prompt-card-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--cgsp-text);
    margin-bottom: 4px;
}

.cgsp-prompt-card-desc {
    font-size: 13px;
    color: var(--cgsp-text-light);
    line-height: 1.4;
}

/* ── Full-page layout ──────────────────────────────────── */

.cgsp-chat-fullpage {
    /*max-width: 800px;*/
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    min-height: 70vh;
}

.cgsp-chat-fullpage .cgsp-chat-messages {
    min-height: 200px;
}

.cgsp-chat-fullpage .cgsp-chat-input-bar {
    position: sticky;
    bottom: 0;
    background: var(--cgsp-bg);
    padding: 12px 0 20px;
}

/* ── Disclaimer ────────────────────────────────────────── */

.cgsp-chat-disclaimer {
    text-align: center;
    font-size: 12px;
    color: var(--cgsp-text-light);
    padding: 8px 0 16px;
    font-family: var(--cgsp-font);
}

/* ── Response cards ────────────────────────────────────── */

.cgsp-response-card {
    padding: 14px 16px;
    border-radius: var(--cgsp-radius);
    background: var(--cgsp-surface);
    line-height: 1.55;
    font-size: 15px;
    font-family: var(--cgsp-font);
}

.cgsp-response-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.cgsp-response-summarize .cgsp-response-badge {
    background: #E8D8C4;
    color: var(--cgsp-accent);
}

.cgsp-response-translate .cgsp-response-badge {
    background: #D4E4D4;
    color: #2D5F2D;
}

.cgsp-response-audio .cgsp-response-badge {
    background: #D8DCE8;
    color: #3B3F6B;
}

.cgsp-response-body {
    word-wrap: break-word;
    white-space: normal;
}

.cgsp-response-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--cgsp-text);
    margin-bottom: 8px;
    line-height: 1.3;
}

.cgsp-response-article-ref {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--cgsp-border);
    font-size: 12px;
    color: var(--cgsp-text-light);
    font-style: italic;
}

.cgsp-response-article-link {
    display: inline-block;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--cgsp-border);
    font-size: 13px;
    color: var(--cgsp-accent);
    text-decoration: none;
    font-weight: 600;
}

.cgsp-response-article-link:hover {
    text-decoration: underline;
}

.cgsp-response-date {
    font-size: 12px;
    color: var(--cgsp-text-light);
    margin-top: 4px;
}

/* ── Intent badge (shown before response arrives) ─────── */

.cgsp-intent-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    background: var(--cgsp-surface-alt);
    color: var(--cgsp-text-light);
    font-size: 12px;
    font-family: var(--cgsp-font);
    margin-bottom: 4px;
    align-self: flex-start;
}

/* ── Audio spinner ────────────────────────────────────── */

.cgsp-audio-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--cgsp-border);
    border-top-color: var(--cgsp-accent);
    border-radius: 50%;
    animation: cgsp-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

.cgsp-audio-status audio {
    width: 100%;
    margin-top: 8px;
}

.cgsp-audio-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
}

.cgsp-audio-download {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--cgsp-border);
    background: var(--cgsp-bg);
    font-size: 13px;
    font-weight: 600;
    color: var(--cgsp-accent);
    text-decoration: none;
    font-family: var(--cgsp-font);
}

.cgsp-audio-download:hover {
    text-decoration: none;
    border-color: var(--cgsp-accent);
    background: var(--cgsp-surface-alt);
}

.cgsp-audio-script {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--cgsp-border);
}

.cgsp-audio-script-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    color: var(--cgsp-text-light);
    margin-bottom: 8px;
}

.cgsp-audio-script-body {
    font-size: 14px;
    color: var(--cgsp-text);
}

/* ── Command autocomplete dropdown ────────────────────── */

.cgsp-cmd-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--cgsp-bg);
    border: 1px solid var(--cgsp-border);
    border-radius: var(--cgsp-radius);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
    margin-bottom: 6px;
    overflow: hidden;
    z-index: 100;
    font-family: var(--cgsp-font);
}

.cgsp-cmd-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.1s;
}

.cgsp-cmd-item:hover {
    background: var(--cgsp-surface);
}

.cgsp-cmd-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--cgsp-accent);
}

.cgsp-cmd-hint {
    font-size: 13px;
    color: var(--cgsp-text-light);
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 600px) {
    .cgsp-chat-welcome h1 {
        font-size: 1.75rem;
    }

    .cgsp-msg {
        max-width: 92%;
    }

    .cgsp-chat-fullpage {
        padding: 0 12px;
    }

    .cgsp-prompt-cards {
        margin-left: 0;
        margin-right: 0;
    }
}
