/* ========================================
   CONSULT CHAT
   Fixed right-side panel + floating button
   ======================================== */

/* Floating action button — appears after results load */
.chat-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
    color: var(--on-brand-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg), 0 0 0 0 rgba(var(--brand-primary-rgb), 0.4);
    cursor: pointer;
    z-index: 200;
    transition: all var(--transition-base);
    animation: fab-pulse 3s ease-in-out infinite;
}

.chat-fab:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-xl), 0 0 0 0 rgba(var(--brand-primary-rgb), 0);
    animation: none;
}

.chat-fab [data-lucide] {
    width: 18px;
    height: 18px;
}

@keyframes fab-pulse {
    0%, 100% { box-shadow: var(--shadow-lg), 0 0 0 0 rgba(var(--brand-primary-rgb), 0.4); }
    50%       { box-shadow: var(--shadow-lg), 0 0 0 8px rgba(var(--brand-primary-rgb), 0); }
}

/* Main content shifts left when chat panel is open */
body.chat-open .recording-container {
    margin-right: 44vw;
    transition: margin-right var(--transition-slow);
}

body:not(.chat-open) .recording-container {
    margin-right: 0;
    transition: margin-right var(--transition-slow);
}

/* Chat panel — slides in from the right */
.chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 44vw;
    height: 100vh;
    background: var(--background-primary);
    border-left: 1px solid var(--border-light);
    box-shadow: -4px 0 32px rgba(var(--brand-dark-rgb), 0.1);
    display: flex;
    flex-direction: column;
    z-index: 150;
    transform: translateX(100%);
    transition: transform var(--transition-slow);
}

.chat-panel.chat-panel--open {
    transform: translateX(0);
}

/* Panel header */
.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
    background: var(--background-primary);
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.chat-header-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(var(--brand-primary-rgb), 0.15) 0%, rgba(var(--brand-primary-rgb), 0.08) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-primary-dark);
    flex-shrink: 0;
}

.chat-header-icon [data-lucide] {
    width: 18px;
    height: 18px;
}

.chat-panel-header h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.chat-header-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
}

.chat-close-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-close-btn:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.chat-close-btn [data-lucide] {
    width: 16px;
    height: 16px;
}

/* Non-intrusive disclaimer banner */
.chat-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    background: rgba(var(--info-500-rgb), 0.05);
    border-bottom: 1px solid rgba(var(--info-500-rgb), 0.1);
    font-size: 0.6875rem;
    color: var(--text-muted);
    line-height: 1.4;
    flex-shrink: 0;
}

/* Message list */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    scroll-behavior: smooth;
}

/* Individual messages */
.chat-message {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: 92%;
}

.chat-message--user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-message--assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    line-height: 1.65;
    white-space: normal;
    word-break: break-word;
}

.chat-message--user .message-content {
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
    color: var(--on-brand-primary);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap; /* preserve line breaks in user-typed text */
}

.chat-message--assistant .message-content {
    background: var(--background-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
}

/* Markdown-ish formatting inside assistant messages */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    font-size: 0.875rem;
    font-weight: 700;
    margin-top: var(--space-3);
    margin-bottom: 0;
    color: var(--text-primary);
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child,
.message-content h4:first-child {
    margin-top: 0;
}

.message-content ul,
.message-content ol {
    padding-left: 1.25rem;
    margin: var(--space-1) 0;
}

.message-content li {
    margin-bottom: 0;
}

.message-content li + li {
    margin-top: 0.2em;
}

.message-content strong {
    font-weight: 700;
}

.message-content em {
    font-style: italic;
    color: var(--text-secondary);
}

.message-content p {
    margin-bottom: var(--space-1);
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Streaming cursor */
.message-content.streaming::after {
    content: '▋';
    display: inline-block;
    color: var(--brand-primary-dark);
    animation: blink 0.8s step-end infinite;
    margin-left: 1px;
}

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

/* "Analyseert..." animated loading indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: rgba(var(--brand-primary-rgb), 0.08);
    border: 1px solid rgba(var(--brand-primary-rgb), 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--brand-primary-dark);
    font-weight: 500;
    width: fit-content;
}

.thinking-dots {
    display: flex;
    gap: 3px;
    align-items: center;
}

.thinking-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--brand-primary-dark);
    animation: thinking-bounce 1.2s ease-in-out infinite;
}

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

@keyframes thinking-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40%            { transform: scale(1);   opacity: 1;   }
}

/* Chat input area */
.chat-input-area {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-light);
    background: var(--background-primary);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    background: var(--background-secondary);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
    transition: border-color var(--transition-fast);
}

.chat-input-wrapper:focus-within {
    border-color: var(--brand-primary);
    background: var(--background-primary);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
}

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

.chat-send-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
    color: var(--on-brand-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

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

.chat-send-btn [data-lucide] {
    width: 15px;
    height: 15px;
}

.chat-input-hint {
    margin-top: var(--space-2);
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-align: right;
}

/* Welcome / empty state */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-8) var(--space-6);
    color: var(--text-muted);
    gap: var(--space-3);
}

.chat-welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(var(--brand-primary-rgb), 0.12) 0%, rgba(var(--brand-primary-rgb), 0.06) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-primary-dark);
}

.chat-welcome-icon [data-lucide] {
    width: 24px;
    height: 24px;
}

.chat-welcome h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}

.chat-welcome p {
    font-size: 0.8125rem;
    line-height: 1.6;
    max-width: 280px;
}

.chat-suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    margin-top: var(--space-2);
}

.chat-chip {
    padding: var(--space-2) var(--space-3);
    background: var(--background-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-family: inherit;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-chip:hover {
    background: rgba(var(--brand-primary-rgb), 0.1);
    border-color: var(--brand-primary);
    color: var(--brand-primary-dark);
}

/* Guideline reference pills — rendered inline in assistant messages */
.guideline-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 100px;
    background: var(--info-50);
    border: 1px solid var(--info-200);
    color: var(--info-800);
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    vertical-align: middle;
    text-decoration: none;
    cursor: default;
    transition: background 0.15s ease, border-color 0.15s ease;
}

a.guideline-pill {
    cursor: pointer;
}

a.guideline-pill:hover {
    background: var(--info-100);
    border-color: var(--info-300);
    text-decoration: none;
}

.chat-data-wiped {
    color: var(--text-muted);
    font-style: normal;
    font-size: 0.875rem;
}

/* Responsive — on narrow screens use a bottom sheet style */
@media (max-width: 900px) {
    body.chat-open .recording-container {
        margin-right: 0;
    }

    .chat-panel {
        width: 100%;
        height: 65vh;
        top: auto;
        bottom: 0;
        border-left: none;
        border-top: 1px solid var(--border-light);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        transform: translateY(100%);
    }

    .chat-panel.chat-panel--open {
        transform: translateY(0);
    }

    .chat-fab {
        bottom: 1.25rem;
        right: 1.25rem;
    }
}
