/* ============================================================================
   Cetan embedded chat (Components/Shared/CetanEmbeddedChat.razor) — theme-agnostic
   base for confirmation-panel chat panels: StudyEnrollmentForm's post-submit welcome
   thread and the Contact form Cetan-armed threads. This is an INLINE panel embedded
   directly in page content — distinct from the FAB drawer widget (comm-chat.base.css /
   --tcc-* / .tc-chat-*). All colours come from --tccc-* vars fed by brand role vars;
   no hex is hardcoded per theme — only safe fallbacks.
   ============================================================================ */
.tc-cetan-chat {
    --tccc-accent:      var(--brand-button, #ff4d24);
    --tccc-accent-text: #ffffff;
    --tccc-font:        inherit;
    --tccc-radius:      14px;
    --tccc-max-h:       420px;
}

/* Dark modifier — default; matches both themes' dark confirmation-card faces
   (Blackhawk #1a1e2e-context cards, Zonar's #353535 content-back). */
.tc-cetan-chat--dark {
    --tccc-bg:             rgba(255, 255, 255, .05);
    --tccc-surface:        rgba(255, 255, 255, .03);
    --tccc-text:           rgba(255, 255, 255, .92);
    --tccc-muted:          rgba(255, 255, 255, .6);
    --tccc-border:         rgba(255, 255, 255, .18);
    --tccc-bubble-in:      rgba(255, 255, 255, .08);
    --tccc-bubble-in-text: rgba(255, 255, 255, .92);
    /* Anchor the panel as ONE card on dark faces (it sits over dark maps/cards). */
    box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
}

/* Light modifier — reserved for any future light-surface embedding. */
.tc-cetan-chat--light {
    --tccc-bg:             #ffffff;
    --tccc-surface:        #f6f7f9;
    --tccc-text:           #1b1f24;
    --tccc-muted:          #6b7280;
    --tccc-border:         #e5e7eb;
    --tccc-bubble-in:      #f1f3f5;
    --tccc-bubble-in-text: #1b1f24;
}

.tc-cetan-chat {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    margin-top: 18px;
    border: 1px solid var(--tccc-border);
    border-radius: var(--tccc-radius);
    background: var(--tccc-bg);
    font-family: var(--tccc-font);
    overflow: hidden;
    text-align: left;
}

.tc-cetan-chat-head {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .3px;
    color: var(--tccc-text);
    border-bottom: 1px solid var(--tccc-border);
    background: var(--tccc-surface);
}

.tc-cetan-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    max-height: var(--tccc-max-h);
    overflow-y: auto;
    background: var(--tccc-surface);
    /* Thin, theme-tinted scrollbar — the raw native bar reads as a broken fragment. */
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--tccc-text) 25%, transparent) transparent;
}
.tc-cetan-chat-messages::-webkit-scrollbar { width: 6px; }
.tc-cetan-chat-messages::-webkit-scrollbar-track { background: transparent; }
.tc-cetan-chat-messages::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--tccc-text) 25%, transparent);
    border-radius: 3px;
}

.tc-cetan-msg {
    max-width: 75%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    /* white-space: pre-wrap must live on the TEXT span only — on the bubble it turns
       Razor's inter-span markup newlines into huge blank gaps inside every bubble. */
    white-space: normal;
}
.tc-cetan-msg--in  { align-self: flex-start; background: var(--tccc-bubble-in); color: var(--tccc-bubble-in-text); border-bottom-left-radius: 4px; }
.tc-cetan-msg--out { align-self: flex-end;   background: var(--tccc-accent);    color: var(--tccc-accent-text);    border-bottom-right-radius: 4px; }
.tc-cetan-msg-sender { display: block; font-size: 11px; font-weight: 700; opacity: .75; margin-bottom: 2px; }
.tc-cetan-msg-sender:empty { display: none; }
.tc-cetan-msg-text   { display: block; white-space: pre-wrap; }
.tc-cetan-msg-time   { display: block; font-size: 10px; opacity: .6; margin-top: 3px; text-align: right; }
/* On accent-filled (out) bubbles the ink is already the on-accent colour — dimming it
   below ~.9 drops the 11px sender / 10px time under WCAG AA on bright brand accents. */
.tc-cetan-msg--out .tc-cetan-msg-sender { opacity: 1; }
.tc-cetan-msg--out .tc-cetan-msg-time   { opacity: .9; }

/* Typing indicator — shown after a send while awaiting the first AI reply. */
.tc-cetan-typing { display: flex; align-items: center; gap: 4px; padding: 10px 14px; }
.tc-cetan-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .5;
    animation: tc-cetan-typing-bounce 1.2s infinite ease-in-out;
}
.tc-cetan-typing-dot:nth-child(2) { animation-delay: .15s; }
.tc-cetan-typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes tc-cetan-typing-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: .4; }
    30%           { transform: translateY(-4px); opacity: 1;  }
}
@media (prefers-reduced-motion: reduce) {
    .tc-cetan-typing-dot { animation: none; opacity: .7; }
}

.tc-cetan-chat-ended,
.tc-cetan-chat-note,
.tc-cetan-chat-error {
    padding: 10px 14px;
    font-size: 12.5px;
    text-align: center;
    color: var(--tccc-muted);
    border-top: 1px solid var(--tccc-border);
}
.tc-cetan-chat-error { color: #e02424; border-top: 0; }

.tc-cetan-chat-compose {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--tccc-border);
    background: var(--tccc-bg);
}
/* Composer controls live inside host-page vendor forms (.custom-form etc.) whose
   generic input/button rules (padding, margins, radius, 10-12px fonts, some
   !important) stomp embedded widgets — hence the defensive !important armor. */
.tc-cetan-chat .tc-cetan-chat-compose .tc-cetan-chat-input {
    flex: 1 1 auto;
    min-width: 0; /* let the flex input shrink so the send button never clips */
    float: none !important;
    width: auto !important;
    height: auto !important;
    min-height: 44px;
    margin: 0 !important;
    padding: 10px 16px !important;
    border: 1px solid var(--tccc-border) !important;
    border-radius: 22px !important;
    background: var(--tccc-surface) !important;
    color: var(--tccc-text) !important;
    font-size: 16px !important; /* 16px minimum — iOS Safari zoom guard on focus */
    box-shadow: none !important;
}
.tc-cetan-chat .tc-cetan-chat-compose .tc-cetan-chat-input::placeholder {
    color: var(--tccc-muted) !important;
    font-size: 14px !important;
    font-weight: 400 !important;
}
.tc-cetan-chat-input:disabled { opacity: .5; cursor: not-allowed; }
.tc-cetan-chat .tc-cetan-chat-compose .tc-cetan-chat-send {
    border: 0 !important;
    float: none !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    flex-shrink: 0;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tccc-accent) !important;
    color: var(--tccc-accent-text) !important;
    cursor: pointer;
    transition: filter .15s ease;
}
.tc-cetan-chat .tc-cetan-chat-compose .tc-cetan-chat-send svg { display: block; width: 18px !important; height: 18px !important; }
.tc-cetan-chat-send:hover:not(:disabled) { filter: brightness(1.08); }
.tc-cetan-chat-send:disabled { opacity: .5; cursor: default; }

.tc-cetan-chat-input:focus-visible,
.tc-cetan-chat-send:focus-visible {
    outline: 3px solid var(--tccc-accent);
    outline-offset: 2px;
}

@media (max-width: 575.98px) {
    .tc-cetan-chat { --tccc-max-h: 320px; }
}

/* ============================================================================
   Success flash — when a Cetan thread is live on a confirmation face, the
   thumbs-up icon (+ "message received" line on contact) shows only as a brief
   ~2.5s success cue, then fades/collapses so the conversation owns the face.
   CSS-only (Blackhawk allows no JS animation stacks); when the takeover toggle
   is OFF the chat never renders, :has() never matches, and the permanent
   icon + text behave exactly as before. Collapse animates max-height/margin so
   the card height change is smooth — no flip-face position tricks.
   ============================================================================ */
@keyframes tc-cetan-flash-out {
    0%, 78% { opacity: 1; max-height: 140px; margin-bottom: 16px; visibility: visible; }
    100%    { opacity: 0; max-height: 0;     margin-bottom: 0;    visibility: hidden;  }
}
.confirmation-wrapper:has(.tc-cetan-chat) .icon-ok,
.confirmation-wrapper:has(.tc-cetan-chat) .application-confirmation {
    overflow: hidden;
    animation: tc-cetan-flash-out 3.2s ease forwards;
}
@media (prefers-reduced-motion: reduce) {
    .confirmation-wrapper:has(.tc-cetan-chat) .icon-ok,
    .confirmation-wrapper:has(.tc-cetan-chat) .application-confirmation {
        animation: none; /* keep the success cue permanently visible */
    }
}
