/* ========================================
   @layer components — chat sidebar + messages + voice notes + typing.
   ======================================== */
@layer components {

/* ========================================
   LIVE CHAT SIDEBAR
   ======================================== */

.chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    font-size: 1.7rem;
    cursor: pointer;
    z-index: 90; /* Sit behind modals */
    box-shadow: 0 4px 20px rgba(var(--secondary-alt-rgb),0.45), 0 0 0 0 rgba(var(--secondary-alt-rgb),0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-toggle-btn:hover {
    animation: chat-pulse 1.5s ease-in-out infinite;
}

/* Hide chat bubble ONLY in Therapy tab to prevent overlap.
   No !important needed — body[...] .X (0,1,1) already outspecs the base
   .chat-toggle-btn (0,1,0) and both live in @layer components. */
body[data-active-tab="therapy"] .chat-toggle-btn {
    display: none;
}

@keyframes chat-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(var(--secondary-alt-rgb),0.45), 0 0 0 0 rgba(var(--secondary-alt-rgb),0.3); }
    50% { box-shadow: 0 4px 20px rgba(var(--secondary-alt-rgb),0.45), 0 0 0 10px rgba(var(--secondary-alt-rgb),0); }
}

.chat-toggle-btn::after {
    content: 'Live Chat';
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    background: rgba(20, 16, 40, 0.95);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    border: 1px solid rgba(var(--secondary-rgb),0.3);
    font-family: inherit;
}

.chat-toggle-btn:hover::after {
    opacity: 1;
    transform: translateY(0);
}

.chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(var(--secondary-alt-rgb),0.6);
    animation: none;
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Lock body scroll when chat is open — mobile only, allow scroll on desktop */
@media (max-width: 768px) {
    body.chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

.chat-sidebar {
    position: fixed;
    top: 0; right: -360px; bottom: 0;
    width: 350px;
    max-width: 100vw;
    background: rgba(13, 11, 30, 0.97);
    backdrop-filter: blur(8px);
    border-left: 1px solid rgba(var(--secondary-rgb),0.3);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-sidebar.open {
    right: 0;
}

.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.chat-sidebar-header h3 {
    color: var(--accent-primary);
    font-weight: 700;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Verified shield (Phase 1.1 SAS verification). Only shown once the user
   has compared the 6-word code with their partner out-of-band via the
   profile modal's "Secure chat code" row. Themed green — semantic for
   success/safe, matches the connect-Google pill. */
.chat-verified-shield {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #22c55e;
    filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.45));
}

.chat-verified-shield[hidden] { display: none; }

.chat-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.chat-close-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

#chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#chat-body.hidden {
    display: none;
}

.chat-name-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 16px;
    padding: var(--spacing-lg);
    text-align: center;
}

.chat-name-prompt.hidden {
    display: none;
}

.chat-name-prompt p {
    color: rgba(255,255,255,0.8);
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-name-input-area {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 250px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.chat-bubble {
    max-width: 80%;
    padding: 8px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: fadeIn 0.2s ease;
    word-break: break-word;
}

.chat-bubble.mine {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(var(--secondary-dark-rgb),0.25), rgba(var(--secondary-rgb),0.15));
    border: 1px solid rgba(var(--secondary-rgb),0.35);
    border-bottom-right-radius: 4px;
}

.chat-bubble.theirs {
    align-self: flex-start;
    background: linear-gradient(135deg, rgba(var(--primary-rgb),0.15), rgba(var(--primary-rgb),0.08));
    border: 1px solid rgba(var(--primary-rgb),0.25);
    border-bottom-left-radius: 4px;
}

.chat-bubble.reaction {
    padding: 4px 10px;
}

.chat-sender {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    margin-bottom: 2px;
}

.chat-text {
    color: rgba(255,255,255,0.9);
}

.chat-time {
    display: block;
    font-size: 0.6rem;
    /* Phase 8.5 contrast — 0.3 → 0.55. Timestamp is non-essential so
       sits below the body text muted (0.6) to maintain hierarchy. */
    color: var(--text-placeholder);
    text-align: right;
    margin-top: 3px;
}

.chat-tag {
    display: inline-block;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--secondary-alt);
    background: rgba(var(--secondary-alt-rgb),0.12);
    padding: 1px 5px;
    border-radius: 4px;
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-reaction-display {
    font-size: 1.5rem;
}

.chat-reaction-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    font-family: inherit;
}

.chat-reaction-btn:hover {
    background: rgba(var(--secondary-alt-rgb),0.15);
    border-color: rgba(var(--secondary-alt-rgb),0.25);
}

.chat-typing-indicator {
    padding: 6px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-typing-indicator.hidden { display: none; }
.chat-typing-name {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    font-weight: 500;
    white-space: nowrap;
}
.chat-typing-bubble {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.chat-typing-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    animation: typingBounce 1.4s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.chat-no-session {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 16px;
    color: rgba(255,255,255,0.5);
    font-size: 0.9rem;
    text-align: center;
    padding: 20px;
}
.chat-no-session.hidden { display: none; }
.chat-no-session p { margin: 0; }
.chat-connect-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: none;
    color: #0d0b1e;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.chat-connect-btn:hover { transform: scale(1.05); }

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: var(--spacing-md);
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    padding: 10px 16px;
    color: white;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
}

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

.chat-send-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    color: #0d0b1e;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.1);
}

/* Voice Note Mic Button */
.chat-mic-btn {
    background: transparent;
    border: none;
    color: var(--secondary);
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    font-size: 1.05rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}
.chat-mic-btn:hover {
    background: rgba(var(--secondary-rgb),0.1);
    transform: scale(1.05);
}
.chat-mic-btn.recording {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    animation: micPulse 1s ease infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
}

/* Recording overlay in input area */
.chat-recording-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    padding: 0 12px;
    color: #e74c3c;
    font-size: 0.85rem;
    font-weight: 600;
}
.chat-recording-bar .rec-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e74c3c;
    animation: recBlink 1s ease infinite;
}
@keyframes recBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}
.chat-recording-bar .rec-timer {
    font-variant-numeric: tabular-nums;
}
.chat-recording-bar .rec-cancel {
    margin-left: auto;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 0.8rem;
}
.chat-recording-bar .rec-cancel:hover { color: #fff; }

/* Voice note in chat bubble */
.chat-voice-note {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 180px;
}
.chat-voice-note .vn-play-btn {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.chat-voice-note .vn-waveform {
    flex: 1;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 2px;
}
.chat-voice-note .vn-bar {
    width: 3px;
    background: currentColor;
    border-radius: 2px;
    opacity: 0.5;
    transition: opacity 0.1s;
}
.chat-voice-note .vn-bar.played { opacity: 1; }
.chat-voice-note .vn-duration {
    font-size: 0.7rem;
    opacity: 0.6;
    min-width: 30px;
    text-align: right;
}
.chat-voice-note .vn-speed-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 0.65rem;
    font-weight: 700;
    width: 30px;
    text-align: center;
    padding: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.2;
    transition: background 0.15s;
    flex-shrink: 0;
}
.chat-voice-note .vn-speed-btn:hover {
    background: rgba(255,255,255,0.2);
}
.chat-voice-note .vn-speed-btn.active {
    background: rgba(var(--primary-rgb),0.25);
    color: var(--secondary-alt);
}

@media (max-width: 480px) {
    .chat-sidebar {
        width: 100vw;
        right: -100vw;
    }
    .chat-toggle-btn {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
    }
}

/* ========================================
   CHAT REACTION BUTTONS — consistent sizing
   ======================================== */
.chat-reactions {
    display: flex;
    gap: 6px;
    padding: 8px var(--spacing-md);
    overflow-x: auto;
    border-top: 1px solid rgba(255,255,255,0.05);
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.chat-reactions::-webkit-scrollbar {
    display: none;
}
.chat-reactions:hover {
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--secondary-rgb),0.3) transparent;
}
.chat-reactions:hover::-webkit-scrollbar {
    display: block;
    height: 4px;
}
.chat-reactions:hover::-webkit-scrollbar-thumb {
    background: rgba(var(--secondary-rgb),0.3);
    border-radius: 2px;
}
.chat-reactions:hover::-webkit-scrollbar-track {
    background: transparent;
}

.chat-reaction-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    font-family: inherit;
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Call log entries */
.chat-call-entry {
    text-align: center;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 8px 14px;
    margin: 8px auto;
    max-width: 80%;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.chat-call-icon {
    font-size: 1rem;
    vertical-align: middle;
}
.chat-call-label {
    vertical-align: middle;
}

/* Media reaction groups */
.chat-media-group {
    background: rgba(var(--secondary-rgb),0.08);
    border: 1px solid rgba(var(--secondary-rgb),0.15);
    border-radius: 12px;
    margin: 8px 0;
    padding: 6px 0;
    overflow: hidden;
}
.chat-media-header {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 4px 12px 6px;
    border-bottom: 1px solid rgba(var(--secondary-rgb),0.1);
}
.chat-media-header strong {
    color: var(--text-primary);
}
.chat-media-msgs {
    padding: 4px 8px;
}
.chat-bubble.mini {
    padding: 3px 10px;
    margin: 2px 0;
    font-size: 0.8rem;
    border-radius: 10px;
}


} /* end @layer components */
