/* =============================================
   Direct Chat — 1:1 messaging panel
   Premium design matching speaker/session detail pages
   ============================================= */

/* --- Split layout --- */

.connect-split-layout {
    display: flex;
    gap: 1.5rem;
    min-height: 600px;
}

.connect-profile-column {
    flex: 0 0 45%;
    max-width: 45%;
}

.connect-chat-column {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding-left: 1.5rem;
    border-left: 1px solid #e5e7eb;
}

/* --- Chat panel container --- */

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 500px;
    max-height: 700px;
    position: relative;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

/* --- Chat header --- */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--community-primary, #6A4A9E) 5%, #fff) 0%,
        #fff 50%,
        color-mix(in srgb, var(--community-accent, #7BCED7) 4%, #fff) 100%
    );
    border-bottom: 1px solid #e5e7eb;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-header-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2px color-mix(in srgb, #10b981 20%, transparent);
    flex-shrink: 0;
}

.chat-header-name {
    font-family: "IBM Plex Sans Condensed", sans-serif;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary, #1f2937);
}

.chat-header-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary, #4B5563);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.6;
}

/* --- Messages area --- */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.12) transparent;
    background: linear-gradient(
        180deg,
        color-mix(in srgb, var(--community-primary, #6A4A9E) 2%, #fafafa) 0%,
        #f9fafb 100%
    );
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 10px;
}

.chat-empty {
    text-align: center;
    color: var(--text-secondary, #4B5563);
    padding: 3rem 1rem;
    font-size: 0.875rem;
    opacity: 0.7;
}

.chat-loading {
    display: flex;
    justify-content: center;
    padding: 2rem;
}

/* --- Pinned banner --- */

.chat-pinned-banner {
    padding: 0.5rem 1rem;
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--community-primary, #6A4A9E) 6%, #fff),
        color-mix(in srgb, var(--community-accent, #7BCED7) 4%, #fff)
    );
    border-bottom: 1px solid color-mix(in srgb, var(--community-primary, #6A4A9E) 12%, transparent);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary, #4B5563);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-pinned-banner i {
    color: var(--community-primary, #6A4A9E);
    font-size: 0.6875rem;
}

/* --- Message bubbles --- */

.chat-bubble-wrapper {
    display: flex;
    position: relative;
    max-width: 80%;
    animation: chatBubbleIn 0.2s ease-out;
}

@keyframes chatBubbleIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-bubble-wrapper:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
    border-radius: 1.125rem;
}

.chat-bubble-right {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-bubble-left {
    align-self: flex-start;
}

.chat-bubble {
    padding: 0.625rem 0.875rem;
    border-radius: 1.125rem;
    max-width: 100%;
    word-wrap: break-word;
    position: relative;
    transition: box-shadow 0.15s ease;
}

.chat-bubble-outgoing {
    background: linear-gradient(
        135deg,
        var(--community-primary, #6A4A9E),
        color-mix(in srgb, var(--community-primary, #6A4A9E) 80%, var(--community-accent, #7BCED7))
    );
    color: #fff;
    border-bottom-right-radius: 0.25rem;
    box-shadow: 0 1px 4px color-mix(in srgb, var(--community-primary, #6A4A9E) 25%, transparent);
}

.chat-bubble-incoming {
    background: #fff;
    color: var(--text-primary, #1f2937);
    border-bottom-left-radius: 0.25rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.chat-bubble-deleted {
    opacity: 0.45;
}

.chat-bubble-pinned {
    border-left: 3px solid color-mix(in srgb, var(--community-accent, #7BCED7) 80%, #fff);
}

.chat-bubble-outgoing.chat-bubble-pinned {
    border-left-color: rgba(255, 255, 255, 0.5);
}

.chat-bubble-text {
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
    white-space: pre-wrap;
}

.chat-bubble-deleted-text {
    font-size: 0.8125rem;
    font-style: italic;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    opacity: 0.7;
}

/* --- Quote --- */

.chat-bubble-quote {
    padding: 0.375rem 0.625rem;
    margin-bottom: 0.5rem;
    border-left: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 0.25rem;
    background: rgba(0, 0, 0, 0.12);
    font-size: 0.75rem;
}

.chat-bubble-incoming .chat-bubble-quote {
    border-left-color: var(--community-primary, #6A4A9E);
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 5%, #f9fafb);
}

.chat-quote-author {
    font-weight: 600;
    display: block;
    margin-bottom: 0.125rem;
}

.chat-quote-text {
    opacity: 0.75;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --- Media content --- */

.chat-bubble-image {
    cursor: pointer;
    border-radius: 0.5rem;
    overflow: hidden;
    transition: transform 0.15s ease;
}

.chat-bubble-image:hover {
    transform: scale(0.98);
}

.chat-bubble-image img,
.chat-bubble-gif img {
    max-width: 250px;
    max-height: 200px;
    border-radius: 0.5rem;
    display: block;
}

.chat-bubble-file {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    padding: 0.25rem 0;
}

.chat-bubble-file i {
    font-size: 1.125rem;
    opacity: 0.8;
}

.chat-file-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-height: 28px;
    border-radius: 50%;
    color: inherit;
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.15s ease, transform 0.15s ease;
    margin-left: 0.25rem;
}

.chat-file-download:hover {
    opacity: 1;
    transform: translateY(-1px);
}

.chat-file-download i {
    font-size: 0.8125rem;
}

/* --- Meta (time + edited) --- */

.chat-bubble-meta {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.625rem;
    margin-top: 0.25rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.chat-bubble-outgoing .chat-bubble-meta {
    color: rgba(255, 255, 255, 0.8);
}

.chat-bubble-incoming .chat-bubble-meta {
    color: var(--text-secondary, #4B5563);
}

.chat-edited-label {
    font-style: italic;
}

.chat-pin-icon {
    font-size: 0.5rem;
}

/* --- Emoji reactions --- */

.chat-bubble-emojis {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.375rem;
}

.chat-emoji-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 100px;
    border: 1.5px solid #e5e7eb;
    background: #fff;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    min-height: 28px;
}

.chat-emoji-badge:hover {
    background: #f3f4f6;
    transform: scale(1.05);
}

.chat-emoji-badge.chat-emoji-mine {
    border-color: var(--community-primary, #6A4A9E);
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 6%, #fff);
}

.chat-emoji-badge span {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-secondary, #4B5563);
}

/* --- Action bar (hover) --- */

.chat-action-bar {
    position: absolute;
    top: -0.625rem;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0.125rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.125rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    z-index: 10;
}

.chat-bubble-left .chat-action-bar {
    left: auto;
    right: -0.5rem;
}

.chat-action-btn {
    width: 30px;
    height: 30px;
    min-height: 30px;
    min-width: 30px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #4B5563);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: background 0.1s ease, color 0.1s ease;
}

.chat-action-btn:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 8%, #f3f4f6);
    color: var(--community-primary, #6A4A9E);
}

.chat-action-more {
    position: relative;
}

.chat-action-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 0.375rem;
    z-index: 20;
    min-width: 150px;
}

.chat-action-dropdown button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.625rem;
    border: none;
    background: transparent;
    color: var(--text-primary, #1f2937);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    text-align: left;
    transition: background 0.1s ease;
}

.chat-action-dropdown button:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 6%, #f3f4f6);
}

.chat-action-dropdown button i {
    width: 1rem;
    text-align: center;
    color: var(--text-secondary, #4B5563);
    font-size: 0.75rem;
}

/* --- Emoji picker popover --- */

.chat-emoji-popover {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 0.375rem;
    display: flex;
    gap: 0.125rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    z-index: 20;
}

.chat-emoji-item {
    width: 34px;
    height: 34px;
    min-height: 34px;
    border: none;
    background: transparent;
    font-size: 1.125rem;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s ease, transform 0.1s ease;
}

.chat-emoji-item:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 8%, #f3f4f6);
    transform: scale(1.15);
}

/* --- Input area --- */

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.chat-media-buttons {
    display: flex;
    gap: 0.125rem;
}

.chat-media-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #4B5563);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    transition: background 0.1s ease, color 0.1s ease;
}

.chat-media-btn:hover {
    background: color-mix(in srgb, var(--community-primary, #6A4A9E) 8%, #f3f4f6);
    color: var(--community-primary, #6A4A9E);
}

.chat-media-btn:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
}

.chat-bubble-image:focus-visible {
    outline: 2px solid var(--community-primary, #6A4A9E);
    outline-offset: 2px;
    border-radius: 0.5rem;
}

.chat-input {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1.5px solid #e5e7eb;
    border-radius: 100px;
    font-size: 0.875rem;
    color: var(--text-primary, #1f2937);
    background: #f9fafb;
    outline: none;
    min-height: 40px;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.chat-input:focus {
    border-color: var(--community-primary, #6A4A9E);
    background: #fff;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--community-primary, #6A4A9E) 10%, transparent);
}

.chat-input::placeholder {
    color: #9ca3af;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
    min-width: 40px;
    border: none;
    background: linear-gradient(
        135deg,
        var(--community-primary, #6A4A9E),
        color-mix(in srgb, var(--community-primary, #6A4A9E) 75%, var(--community-accent, #7BCED7))
    );
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--community-primary, #6A4A9E) 25%, transparent);
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 16px color-mix(in srgb, var(--community-primary, #6A4A9E) 35%, transparent);
}

.chat-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

/* --- Reply/Edit bar --- */

.chat-reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--community-primary, #6A4A9E) 5%, #fff),
        color-mix(in srgb, var(--community-accent, #7BCED7) 3%, #fff)
    );
    border-top: 1px solid color-mix(in srgb, var(--community-primary, #6A4A9E) 10%, transparent);
    font-size: 0.75rem;
    color: var(--community-primary, #6A4A9E);
    font-weight: 600;
}

.chat-reply-close {
    width: 26px;
    height: 26px;
    min-height: 26px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #4B5563);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.1s ease;
}

.chat-reply-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* --- Giphy picker --- */

.chat-giphy-popover {
    position: relative;
    max-height: 250px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
    flex-shrink: 0;
    margin: 0 0.5rem;
}

.chat-giphy-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.chat-giphy-input {
    flex: 1;
    min-width: 0;
    padding: 0.375rem 0.875rem;
    border: 1.5px solid #e5e7eb;
    border-radius: 100px;
    font-size: 0.8125rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.chat-giphy-input:focus {
    border-color: var(--community-primary, #6A4A9E);
}

.chat-giphy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 0.25rem;
    padding: 0.5rem;
    overflow-y: auto;
    flex: 1;
}

.chat-giphy-grid img {
    width: 100%;
    height: 75px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.1s ease, border-radius 0.1s ease;
}

.chat-giphy-grid img:hover {
    transform: scale(1.06);
    border-radius: 4px;
}

.chat-giphy-close {
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #4B5563);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    flex-shrink: 0;
    transition: background 0.1s ease, color 0.1s ease;
}

.chat-giphy-close:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary, #1f2937);
}

/* --- Image Lightbox --- */

.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.lightbox-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90vw;
    max-height: 90vh;
    cursor: default;
    transform: scale(0.92);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.3s ease;
}

.lightbox-container.active {
    transform: scale(1);
    opacity: 1;
}

.lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 0.25rem 0.75rem;
}

.lightbox-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.lightbox-sender {
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.01em;
}

.lightbox-time {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    font-weight: 400;
}

.lightbox-close {
    width: 36px;
    height: 36px;
    min-height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s ease, transform 0.15s ease;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.lightbox-close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.lightbox-image-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 0.75rem;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(255, 255, 255, 0.06);
}

.lightbox-image {
    display: block;
    max-width: 85vw;
    max-height: 75vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 0.75rem;
    user-select: none;
    -webkit-user-drag: none;
}

.lightbox-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 0 0;
}

.lightbox-action-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.lightbox-action-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    transform: scale(1.1);
}

.lightbox-action-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* --- Responsive --- */

@media (max-width: 768px) {
    .connect-split-layout {
        flex-direction: column;
    }

    .connect-profile-column {
        flex: none;
        max-width: 100%;
    }

    .connect-chat-column {
        border-left: none;
        padding-left: 0;
        border-top: 1px solid #e5e7eb;
        padding-top: 1rem;
    }

    .chat-panel {
        max-height: none;
        min-height: 400px;
    }

    .chat-bubble-wrapper {
        max-width: 90%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-bubble-wrapper {
        animation: none !important;
    }

    .chat-giphy-grid img,
    .chat-emoji-badge,
    .chat-emoji-item,
    .chat-action-btn,
    .chat-send-btn,
    .chat-media-btn,
    .chat-bubble-image,
    .chat-file-download,
    .lightbox-overlay,
    .lightbox-container,
    .lightbox-close,
    .lightbox-action-btn {
        transition: none !important;
        transform: none !important;
    }
}
