/* ==================== */
/* CHAT INTERFACE STYLES */
/* Inspired by Chatwoot */
/* ==================== */

.chat-container {
    width: 100%;
    height: 100%;
    background: var(--background-primary);
    border-radius: 0;
    overflow: hidden;
    box-shadow: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.chat-layout {
    display: flex;
    height: 100%;
    width: 100%;
}

/* Chat Sidebar - Conversation List */
.chat-sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--surface-elevated);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-sidebar-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--background-primary);
    flex-shrink: 0;
}

.chat-sidebar-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-sidebar-search {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-sidebar-search input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--background-primary);
    color: var(--text-primary);
    transition: all 0.2s;
}

.chat-sidebar-search input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0;
    min-height: 0;
}

#chat-list-sentinel {
    height: 1px;
    width: 100%;
    visibility: hidden;
    pointer-events: none;
}

.chat-list-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.chat-list-item:hover {
    background: rgba(79, 70, 229, 0.05);
}

.chat-list-item.active {
    background: rgba(79, 70, 229, 0.1);
    border-left: 3px solid var(--primary-color);
}

.chat-list-item-content {
    flex: 1;
    min-width: 0;
}

.chat-list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.25rem;
}

.chat-list-item-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-left: 0.5rem;
}

.chat-list-item-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.chat-list-item-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #2563eb;
    color: #ffffff;
    border: 1px solid #93c5fd;
    border-radius: 9px;
    font-size: 0.6875rem;
    font-weight: 600;
    margin-left: auto;
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background-primary);
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
}

.chat-empty-state svg {
    color: var(--text-disabled);
    margin-bottom: 1rem;
}

.chat-empty-state h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.chat-empty-state p {
    margin: 0;
    font-size: 0.9375rem;
}

/* Chat Conversation */
.chat-conversation {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-elevated);
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-width: 0;
    padding: 0.25rem 0.5rem 0.25rem 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.chat-header-info:hover {
    background: color-mix(in srgb, var(--primary-color, #2563eb) 10%, transparent);
}

.chat-header-info:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-header-details h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-status {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.chat-status.online {
    color: var(--success-color);
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--background-primary);
}

.chat-message-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: messageSlideIn 0.2s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.outgoing {
    flex-direction: row-reverse;
    margin-left: auto;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--brand-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.chat-message.outgoing .chat-message-avatar {
    background: var(--secondary-color);
}

.chat-message-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-size: 0.9375rem;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chat-message.outgoing .chat-message-bubble {
    background: var(--brand);
    color: var(--brand-foreground);
    border-top-right-radius: 4px;
}

.chat-message.incoming .chat-message-bubble {
    border-top-left-radius: 4px;
}

.chat-message-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0 0.25rem;
}

.chat-message.outgoing .chat-message-meta {
    justify-content: flex-end;
}

.chat-message-time {
    font-size: 0.75rem;
}

.chat-message-status {
    display: flex;
    align-items: center;
}

.chat-message-status svg {
    width: 14px;
    height: 14px;
}

/* ── Optimistic / pending message ── */
.chat-message.msg-pending .chat-message-bubble {
    opacity: 0.75;
}
.chat-message-status .pending-clock {
    animation: spin-clock 1.2s linear infinite;
    color: var(--text-secondary);
}
@keyframes spin-clock {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Failed message ── */
.chat-message.msg-failed .chat-message-bubble {
    opacity: 0.65;
    border: 1px solid #e74c3c44;
}
.chat-resend-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid #e74c3c88;
    border-radius: 4px;
    padding: 1px 5px;
    cursor: pointer;
    color: #e74c3c;
    font-size: 0.7rem;
    gap: 2px;
    margin-left: 2px;
    transition: background 0.15s;
}
.chat-resend-btn:hover {
    background: #e74c3c18;
}

/* Sender Name (for groups and incoming messages) */
.chat-message-sender {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
    padding: 0 0.25rem;
}

.chat-message.outgoing .chat-message-sender {
    color: var(--text-secondary);
}

/* Message Text */
.chat-message-text {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message-text a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.9;
}

.chat-message.outgoing .chat-message-text a {
    color: var(--brand-foreground);
}

/* Media Messages */
.chat-message-media {
    max-width: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.chat-message-image img {
    max-width: 320px;
    max-height: 400px;
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
    border-radius: 8px;
    transition: opacity 0.2s;
}

.chat-message-image img:hover {
    opacity: 0.9;
}

.chat-message-video video {
    max-width: 320px;
    width: 100%;
    border-radius: 8px;
    background: #000;
}

.chat-message-audio audio {
    width: 280px;
    height: 40px;
}

.chat-message-document {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    min-width: 200px;
}

.chat-message.outgoing .chat-message-document {
    background: rgba(var(--brand-rgb), 0.1);
}

.document-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.chat-message.outgoing .document-icon {
    background: rgba(var(--brand-rgb), 0.15);
}

.document-info {
    flex: 1;
    min-width: 0;
}

.document-name {
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.document-download {
    font-size: 0.75rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.chat-message.outgoing .document-download {
    color: var(--brand-foreground);
    opacity: 0.9;
}

.document-download:hover {
    text-decoration: underline;
}

/* Sticker Message */
.chat-message-sticker {
    background: transparent;
    padding: 0;
}

.chat-message-sticker img {
    display: block;
    border-radius: 8px;
}

/* Media placeholder for unavailable/encrypted media */
.chat-message-media-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--hover-bg);
    border-radius: 8px;
    color: var(--text-secondary);
    text-align: center;
    gap: 0.5rem;
}

.chat-message-media-placeholder i {
    font-size: 2rem;
    opacity: 0.5;
}

.chat-message-media-placeholder span {
    font-weight: 500;
}

.chat-message-media-placeholder small {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Location Message */
.chat-message-location {
    max-width: 300px;
}

.location-preview {
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.location-name {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.location-address {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.location-live {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--success-color);
    color: white;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.location-link {
    display: inline-block;
    font-size: 0.8125rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.chat-message.outgoing .location-link {
    color: var(--brand-foreground);
    opacity: 0.9;
}

.location-link:hover {
    text-decoration: underline;
}

/* Contact Message */
.chat-message-contact {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
}

.contact-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--secondary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.contact-icon svg {
    opacity: 0.7;
}

.contact-info {
    flex: 1;
}

.contact-text {
    font-weight: 500;
    font-size: 0.875rem;
}

/* Poll Message */
.chat-message-poll {
    padding: 0.5rem;
}

.poll-title {
    font-weight: 600;
    font-size: 0.9375rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.chat-message.outgoing .poll-title {
    border-bottom-color: rgba(var(--brand-rgb), 0.2);
}

.poll-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.poll-option {
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    font-size: 0.875rem;
}

.chat-message.outgoing .poll-option {
    background: rgba(var(--brand-rgb), 0.1);
}

/* Media Caption */
.chat-message-caption {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 0.875rem;
}

.chat-message.outgoing .chat-message-caption {
    border-top-color: rgba(255, 255, 255, 0.2);
}

/* Date Separator */
.chat-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0.5rem 0;
    background: linear-gradient(to bottom, var(--background-primary) 0%, var(--background-primary) 80%, transparent 100%);
}

.chat-date-separator span {
    padding: 0.375rem 0.875rem;
    background: var(--surface-elevated);
    border-radius: 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Typing Indicator */
.chat-typing {
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-elevated);
    border-top: 1px solid var(--border-color);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 0.75rem;
    background: var(--background-primary);
    border-radius: 12px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.typing-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Chat Input */
.chat-input-container {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface-elevated);
    flex-shrink: 0;
}

.chat-input-wrapper {
    flex: 1;
    min-width: 0;
    position: relative;
}

.chat-input-wrapper textarea {
    width: 100%;
    height: auto;
    min-height: 44px;
    margin: 0;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--background-primary);
    resize: none;
    overflow-y: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.5;
    display: block;
    box-sizing: border-box;
}

.chat-input-container > .btn-icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    margin: 0;
    padding: 0;
}

.chat-input-wrapper textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.chat-input-wrapper textarea::placeholder {
    color: var(--text-disabled);
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary-color);
}

/* Reload button spin animation */
#reload-chats-btn.spinning svg {
    animation: spin-reload 0.8s linear infinite;
}
@keyframes spin-reload {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.btn-send {
    background: #2563eb;
    color: #ffffff;
    border: 1px solid #60a5fa;
}

.chat-header-details {
    min-width: 0;
}

.btn-send:hover {
    background: #1d4ed8;
    color: #ffffff;
}

.btn-send:disabled {
    background: var(--surface-muted, #d4d4d8);
    border-color: var(--border-color, #a1a1aa);
    color: var(--text-secondary, #52525b);
    opacity: 1;
    cursor: not-allowed;
}

/* Chat Details Sidebar */
.chat-details {
    width: 320px;
    min-width: 320px;
    background: var(--surface-elevated);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-details-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-details-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-details-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.chat-detail-section {
    margin-bottom: 1.5rem;
}

.chat-detail-section h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-detail-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-detail-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.chat-detail-value {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .chat-sidebar {
        width: 280px;
        min-width: 280px;
    }
    
    .chat-details {
        display: none;
    }
}

@media (max-width: 768px) {
    .chat-sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }
    
    .chat-sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .chat-main {
        width: 100%;
    }
}

/* Scrollbar Styling for Chat */
.chat-messages::-webkit-scrollbar,
.chat-list::-webkit-scrollbar,
.chat-details-content::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-list::-webkit-scrollbar-track,
.chat-details-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb,
.chat-details-content::-webkit-scrollbar-thumb {
    background: var(--text-disabled);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-list::-webkit-scrollbar-thumb:hover,
.chat-details-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
/* ==================== */
/* LOADING STATES */
/* ==================== */

/* Loading Spinner */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    width: 100%;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Skeleton Loading for Chat List */
.chat-list-skeleton {
    padding: 0.75rem 1.25rem;
    display: flex;
    gap: 0.75rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--border-color);
    flex-shrink: 0;
}

.skeleton-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 0.25rem;
}

.skeleton-line {
    height: 12px;
    background: var(--border-color);
    border-radius: 4px;
}

.skeleton-line-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.skeleton-line-name {
    flex: 1;
    height: 14px;
    background: var(--border-color);
    border-radius: 4px;
}

.skeleton-line-time {
    width: 50px;
    height: 12px;
    background: var(--border-color);
    border-radius: 4px;
}

.skeleton-line-message {
    width: 70%;
    height: 12px;
    background: var(--border-color);
    border-radius: 4px;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Messages Loading State */
.messages-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    gap: 1rem;
}

.messages-loading-text {
    font-size: 0.875rem;
}

/* Load older messages sentinel */
.load-older-trigger {
    display: flex;
    justify-content: center;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}

.load-older-trigger span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    background: var(--bg-secondary, #f0f2f5);
    user-select: none;
    transition: background 0.15s;
}

.load-older-trigger span:hover {
    background: var(--border-color, #e0e0e0);
}

.load-older-spinner {
    display: flex;
    justify-content: center;
    padding: 0.5rem;
}

/* Message Skeleton */
.message-skeleton {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.message-skeleton.outgoing {
    flex-direction: row-reverse;
}

.message-skeleton-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--border-color);
    flex-shrink: 0;
}

.message-skeleton-content {
    max-width: 65%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message-skeleton-bubble {
    background: var(--border-color);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message-skeleton-line {
    height: 12px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.message-skeleton-line-short {
    width: 60%;
}

.message-skeleton-line-long {
    width: 100%;
}

/* ========================================
   WHATSAPP SETUP OVERLAY
   ======================================== */

.whatsapp-setup-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 0;
    padding: 1rem;
    overflow: auto;
}

.whatsapp-setup-card {
    position: relative;
    background: var(--card, #fff);
    color: var(--card-foreground, #0a0a0a);
    border-radius: 8px;
    padding: 1.75rem;
    max-width: 480px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    width: 100%;
    text-align: center;
    border: 1px solid var(--border, #e5e7eb);
    margin: auto;
    box-sizing: border-box;
}

.whatsapp-setup-icon {
    color: #25D366;
    margin-bottom: 1rem;
}

.whatsapp-setup-icon svg {
    fill: #25D366;
    width: 32px;
    height: 32px;
}

.whatsapp-setup-card h3 {
    color: var(--card-foreground, #0a0a0a);
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.ws-subtitle {
    color: var(--muted-foreground, #6b7280);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.ws-state {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* QR Code */
.ws-qrcode-container {
    position: relative;
    background: white;
    border-radius: 12px;
    padding: 1rem;
    margin: 1.25rem auto;
    display: inline-block;
}

.ws-qrcode-container img {
    width: 320px;
    height: 320px;
    display: block;
    border-radius: 8px;
}

.ws-qrcode-expired {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.ws-qrcode-expired p {
    color: #666;
    font-size: 0.875rem;
    font-weight: 500;
}

.ws-hint {
    color: var(--muted-foreground, #6b7280);
    font-size: 0.75rem;
    margin-top: 0.5rem;
    line-height: 1.5;
}

/* Spinner */
.ws-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border, #e5e7eb);
    border-top-color: #25D366;
    border-radius: 50%;
    animation: ws-spin 0.8s linear infinite;
    margin: 1.5rem auto;
}

@keyframes ws-spin {
    to { transform: rotate(360deg); }
}

/* Success */
.ws-success-icon {
    margin-bottom: 1rem;
}

/* Error */
.ws-error-msg {
    color: #e74c3c !important;
}

/* Buttons in overlay */
.whatsapp-setup-card .btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.whatsapp-setup-card .btn-primary:hover {
    background: var(--brand-light);
}

.whatsapp-setup-card [hidden] { display: none !important; }
.whatsapp-setup-card button:disabled { cursor: not-allowed; opacity: .6; }
.whatsapp-setup-card button:focus-visible { outline: 2px solid var(--ring, #16634b); outline-offset: 3px; }
.whatsapp-setup-card .ws-form-result { overflow-wrap: anywhere; font-size: .8125rem; line-height: 1.5; margin: 0; }
.ws-connection-summary { text-align: left; margin: 1.5rem 0; }
.ws-connection-summary > strong { display: block; font-size: 1.125rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ws-connection-summary > span { display: block; font-size: .875rem; color: var(--muted-foreground, #52525b); margin-top: .25rem; overflow-wrap: anywhere; }
.ws-connection-summary dl { margin: 1rem 0 0; padding: .75rem 0; border-block: 1px solid var(--border, #e4e4e7); }
.ws-connection-summary dl > div { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: .75rem; padding: .25rem 0; font-size: .8125rem; }
.ws-connection-summary dt { color: var(--muted-foreground, #52525b); }
.ws-connection-summary dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.ws-connection-summary dd[data-status="healthy"] { color: #16634b; }
.dark .ws-connection-summary dd[data-status="healthy"] { color: #86efac; }
.whatsapp-setup-card .ws-customer-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ws-customer-actions #ws-open-conversations { grid-column: 1 / -1; }
.ws-customer-actions button { min-width: 0; white-space: normal; }
.whatsapp-setup-card .ws-coexistence-choice .btn-primary { min-height: 42px; }
@media (max-width: 520px) {
    .whatsapp-setup-overlay { padding: .75rem; }
    .whatsapp-setup-card { padding: 1.5rem 1rem; }
    .whatsapp-setup-card .ws-connection-picker { grid-template-columns: minmax(0, 1fr); }
}
:where(html[data-motion-reduced="true"]) { .whatsapp-setup-card .ws-state { animation: none; } }

.ws-close-management {
    position: absolute;
    top: 0.75rem;
    right: 0.9rem;
    border: 0;
    background: transparent;
    color: var(--muted-foreground, #6b7280);
    cursor: pointer;
    font-size: 1.75rem;
    line-height: 1;
}

.ws-ai-policy {
    margin-top: 1rem;
    border-top: 1px solid var(--border, #e5e7eb);
    padding-top: 0.75rem;
}

.ws-ai-policy summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--card-foreground, #0a0a0a);
}

.ws-policy-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
}

.ws-check {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
}

.ws-check input {
    width: auto !important;
}

.ws-connection-form {
    display: grid;
    gap: .8rem;
    margin-top: 1rem;
    text-align: left;
}

.ws-connection-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: .6rem;
    margin-top: 1rem;
    text-align: left;
}

.ws-connection-picker label {
    display: grid;
    gap: .35rem;
    color: var(--muted-foreground, #6b7280);
    font-size: .8rem;
    font-weight: 600;
}

.ws-connection-picker select {
    width: 100%;
    min-width: 0;
    padding: .7rem .8rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    background-color: var(--background, #fff);
    color: var(--foreground, #0a0a0a);
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 12px;
}

.ws-connection-form label,
.ws-copy-field {
    display: grid;
    gap: .35rem;
    color: var(--muted-foreground, #6b7280);
    font-size: .8rem;
    font-weight: 600;
}

.ws-connection-form input,
.ws-connection-form textarea,
.ws-copy-field input {
    width: 100%;
    box-sizing: border-box;
    padding: .7rem .8rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    background-color: var(--background, #fff);
    color: var(--foreground, #0a0a0a);
}

.ws-coexistence-choice {
    display: grid;
    gap: 10px;
    margin: 16px 0;
}

.ws-coexistence-choice small {
    color: var(--muted-foreground, #52525b);
    line-height: 1.4;
}

.ws-manual-toggle {
    border: 0;
    background: transparent;
    color: var(--muted-foreground, #52525b);
    cursor: pointer;
    padding: 6px;
    text-decoration: underline;
}

.whatsapp-setup-card input::placeholder {
    color: var(--muted-foreground, #6b7280);
    opacity: .82;
}

.whatsapp-setup-card .btn-secondary,
.ws-copy-field button {
    background: var(--secondary, #f4f4f5);
    color: var(--secondary-foreground, #18181b);
    border-color: var(--border, #e5e7eb);
}

.ws-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
}

.ws-copy-field {
    margin: .8rem 0;
    text-align: left;
}

.ws-copy-field span {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .4rem;
}

.ws-copy-field button {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 0 .8rem;
    cursor: pointer;
}

.ws-meta-review-card {
    margin-top: 1.25rem;
    padding: 1rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    background:
        linear-gradient(135deg, rgba(37, 211, 102, .08), transparent 46%),
        var(--card, #fff);
    color: var(--foreground, #0a0a0a);
}

.ws-meta-review-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
}

.ws-meta-review-heading h4 {
    margin: 0 0 .25rem;
    color: var(--foreground, #0a0a0a);
}

.ws-meta-review-heading p {
    margin: 0;
    color: var(--muted-foreground, #6b7280);
    line-height: 1.45;
}

.ws-meta-review-heading span {
    flex: 0 0 auto;
    padding: .25rem .55rem;
    border-radius: 999px;
    background: rgba(37, 211, 102, .14);
    color: #128c4a;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
}

.ws-meta-review-card .ws-copy-field span {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
}

.ws-meta-review-card textarea {
    width: 100%;
    min-height: 4.25rem;
    resize: vertical;
    box-sizing: border-box;
    padding: .7rem .8rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    background-color: var(--background, #fff);
    color: var(--foreground, #0a0a0a);
    font: inherit;
    line-height: 1.45;
}

.ws-meta-screencast {
    margin-top: .9rem;
    padding-top: .75rem;
    border-top: 1px solid var(--border, #e5e7eb);
    color: var(--muted-foreground, #6b7280);
}

.ws-meta-screencast h5 {
    margin: 0 0 .5rem;
    color: var(--foreground, #0a0a0a);
}

.ws-meta-screencast ol {
    margin: 0;
    padding-left: 1.2rem;
}

.ws-meta-screencast li {
    margin: .35rem 0;
    line-height: 1.45;
}

@media (max-width: 720px) {
    .ws-meta-review-heading {
        display: grid;
    }

    .ws-meta-review-heading span {
        justify-self: start;
    }

    .ws-meta-review-card .ws-copy-field span {
        grid-template-columns: 1fr;
    }

    .ws-meta-review-card .ws-copy-field button {
        min-height: 2.4rem;
    }
}

.chat-inbox-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .4rem;
    padding: 0 .75rem .65rem;
}

.chat-inbox-filters select,
.chat-template-select {
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: .4rem;
    font-size: .75rem;
}

.chat-inbox-filters label {
    grid-column: 1 / -1;
    color: var(--text-secondary);
    font-size: .75rem;
}

.chat-attachment-preview {
    padding: .55rem .8rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: .8rem;
}

.chat-template-components {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color, #fff);
}

.chat-template-components label {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.chat-template-components textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid var(--border-color);
    border-radius: 0.4rem;
    padding: 0.45rem;
    font: 0.8rem/1.3 monospace;
}

.chat-template-composer {
    display: grid;
    grid-template-columns: auto minmax(150px, 240px);
    align-items: center;
    gap: .55rem;
    padding: .45rem .75rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color, #fff);
}

.chat-template-composer[hidden] {
    display: none !important;
}

.chat-template-composer label {
    color: var(--text-muted);
    font-size: .75rem;
}

.ws-template-manager,
.ws-review-readiness {
    margin-top: 1.25rem;
    padding: 1rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    background: var(--card, #fff);
    color: var(--foreground, #0a0a0a);
}

.ws-review-checks {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .45rem;
    margin-top: .9rem;
}

.ws-review-check {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .6rem .7rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 9px;
    color: var(--muted-foreground, #6b7280);
    font-size: .78rem;
}

.ws-review-check.passed {
    border-color: #86efac;
    background: #f0fdf4;
    color: #166534;
}

.ws-review-summary {
    grid-column: 1 / -1;
    margin: .2rem 0 0;
    color: #92400e;
    font-size: .8rem;
}

.ws-review-summary.passed { color: #166534; }

.ws-template-manager-header,
.ws-template-form-actions,
.ws-template-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
}

.ws-template-manager h4 {
    margin: 0 0 .25rem;
}

.ws-template-manager-header p,
.ws-template-empty {
    margin: 0;
    color: var(--muted-foreground, #6b7280);
    font-size: .82rem;
}

.ws-template-create-form {
    display: grid;
    gap: .75rem;
    margin: 1rem 0;
    padding: 1rem 0;
    border-top: 1px solid var(--border, #e5e7eb);
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.ws-template-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: .7rem;
}

.ws-template-create-form label {
    display: grid;
    gap: .3rem;
    color: var(--muted-foreground, #6b7280);
    font-size: .78rem;
    font-weight: 600;
}

.ws-template-create-form input,
.ws-template-create-form select,
.ws-template-create-form textarea {
    width: 100%;
    box-sizing: border-box;
    padding: .65rem .75rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    background-color: var(--background, #fff);
    color: var(--foreground, #0a0a0a);
    font: inherit;
}

.ws-template-create-form select {
    padding-right: 2rem;
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 12px;
}

.ws-template-list {
    display: grid;
    gap: .5rem;
}

.ws-template-row {
    padding: .75rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
}

.ws-template-row > div,
.ws-template-state {
    display: grid;
    gap: .2rem;
}

.ws-template-row span,
.ws-template-row small {
    color: var(--muted-foreground, #6b7280);
    font-size: .74rem;
}

.ws-template-state {
    justify-items: end;
}

.ws-template-status {
    padding: .2rem .45rem;
    border-radius: 999px;
    background: var(--secondary, #f4f4f5);
    color: var(--secondary-foreground, #18181b) !important;
    font-weight: 700;
}

.ws-template-status-approved { background: #dcfce7; color: #166534 !important; }
.ws-template-status-pending { background: #fef3c7; color: #92400e !important; }
.ws-template-status-rejected { background: #fee2e2; color: #991b1b !important; }

@media (max-width: 760px) {
    .ws-template-form-grid { grid-template-columns: 1fr; }
    .ws-template-manager-header,
    .ws-template-form-actions,
    .ws-template-row { align-items: stretch; flex-direction: column; }
    .ws-template-state { justify-items: start; }
    .ws-review-checks { grid-template-columns: 1fr; }
}

.chat-saved-attachments {
    flex: 0 0 auto;
    min-width: 0;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    font-size: 12px;
}

.chat-saved-attachments summary { cursor: pointer; }

#chat-saved-attachment-list {
    max-height: min(420px, 50vh);
    overflow: auto;
    padding-top: 6px;
}

#chat-document-checklist-list { max-height: min(540px, 65vh); overflow: auto; padding-top: 6px; }
.chat-checklist-form { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chat-checklist-form input { flex: 1 1 130px; min-width: 0; }
.chat-checklist-actions { display: flex; flex: 0 1 50% !important; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.chat-checklist-actions select { min-width: 0; width: 100%; }
.chat-saved-attachments input, .chat-saved-attachments select {
    max-width: 100%; padding: 5px; border: 1px solid var(--border-color); border-radius: 4px;
    background: var(--bg-primary); color: var(--text-primary); font-size: 12px;
}

.chat-saved-toolbar { display: flex; justify-content: flex-end; }

.chat-saved-row {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-color);
}

.chat-saved-row > div { flex: 1; min-width: 0; }
.chat-saved-row strong, .chat-saved-row span { display: block; overflow-wrap: anywhere; }
.chat-saved-row strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.chat-saved-row span { color: var(--text-secondary); margin-top: 3px; }
.chat-saved-attachments button {
    flex: 0 0 auto;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 12px;
}
.chat-saved-attachments button:disabled { opacity: .55; cursor: default; }
.chat-attachment-preview > span { overflow-wrap: anywhere; }

.chat-attachment-preview progress {
    width: 100%;
    margin-top: .35rem;
}

/* Browser-native rendering virtualization for long message histories. */
.chat-messages .chat-message {
    content-visibility: auto;
    contain-intrinsic-size: 72px;
}

.chat-batch-modal {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(0, 0, 0, .55);
}

.chat-batch-card {
    width: min(560px, 96vw);
    max-height: 85vh;
    overflow: auto;
    padding: 1.25rem;
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 18px 60px rgba(0, 0, 0, .3);
}

.chat-batch-card > label {
    display: grid;
    gap: .35rem;
    margin: .75rem 0;
    font-size: .8rem;
}

.chat-batch-card select,
.chat-batch-card textarea {
    padding: .6rem;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.chat-batch-contacts {
    max-height: 280px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.chat-batch-contacts label {
    display: flex;
    gap: .55rem;
    padding: .55rem .7rem;
    border-bottom: 1px solid var(--border-color);
    font-size: .8rem;
}

/* ===================== */
/* BOT TOGGLE CONTROLS   */
/* ===================== */

/* --- Sidebar global toggle --- */
.global-bot-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.global-bot-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 3px 8px 3px 6px;
    cursor: default;
}

.global-bot-icon {
    opacity: 0.55;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.global-bot-toggle:has(input:checked) .global-bot-icon {
    opacity: 1;
    color: var(--primary-color);
}

/* --- Pill toggle switch --- */
.bot-switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.bot-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.bot-switch-slider {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 18px;
    transition: background 0.2s;
}

.bot-switch-slider::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.bot-switch input:checked + .bot-switch-slider {
    background: var(--primary-color);
}

.bot-switch input:checked + .bot-switch-slider::before {
    transform: translateX(16px);
}

/* --- Per-conversation bot button in chat header --- */
.conv-bot-btn,
.conv-bot-list-btn {
    position: relative;
    transition: color 0.2s, opacity 0.2s;
}

/* List-item bot button sizing & layout */
.conv-bot-list-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    align-self: center;
    flex-shrink: 0;
    padding: 0;
}

.conv-bot-list-btn:hover {
    background: rgba(79, 70, 229, 0.1);
}

/* Active state: colored icon */
.conv-bot-btn.bot-on,
.conv-bot-list-btn.bot-on {
    color: var(--primary-color);
    opacity: 1;
}

/* Inactive state: muted icon with slash overlay */
.conv-bot-btn.bot-off,
.conv-bot-list-btn.bot-off {
    color: var(--text-muted);
    opacity: 0.7;
}

.conv-bot-btn.bot-off::after,
.conv-bot-list-btn.bot-off::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 2px;
    background: var(--text-muted);
    transform: translate(-50%, -50%) rotate(-45deg);
    border-radius: 2px;
    pointer-events: none;
}

/* Disabled by global master switch: dimmed + tooltip hint */
.conv-bot-btn.bot-global-off,
.conv-bot-list-btn.bot-global-off {
    color: var(--text-muted);
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Chat list loading overlay ─────────────────────────────────── */
.chat-list {
    position: relative;   /* anchor for the overlay */
}

.chat-list-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: color-mix(in srgb, var(--surface-elevated, #fff) 80%, transparent);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    pointer-events: none;          /* let user scroll / click through while loading */
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-list-loading-overlay.visible {
    opacity: 1;
}

.chat-list-loading-overlay .overlay-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.chat-list-loading-overlay .overlay-text {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0;
}
.chat-upload-request { border-top: 1px solid var(--border-color, #d8dce2); padding: 10px 0; min-width: 0; }
.chat-upload-request > label { display: grid; gap: 4px; font-size: 12px; margin: 8px 0; }
.chat-upload-request input:not([type=checkbox]) { width: 100%; min-width: 0; }
.chat-has-upload { flex-wrap: wrap; }
.chat-has-upload > details { flex: 1 0 100%; min-width: 0; }
.chat-has-upload summary { cursor: pointer; font-size: 12px; }
.chat-saved-row > .chat-portal-files { flex: 1 0 100%; }
.chat-portal-files > div { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.chat-portal-files span { flex: 1; min-width: 0; }
#chat-handoff-task-list { max-height: min(420px, 55vh); overflow: auto; padding-top: 8px; }
.chat-handoff-row { padding: 12px 0; border-top: 1px solid var(--border-color); margin-top: 8px; }
.chat-handoff-row strong, .chat-handoff-row p { overflow-wrap: anywhere; font-size: 12px; }
.chat-handoff-row p { color: var(--text-secondary); margin: 4px 0; }
.chat-handoff-row form { margin-top: 8px; }
.chat-handoff-high { color: #9f254a; }
.chat-handoff-queue { flex-shrink: 0; border-bottom: 1px solid var(--border-color); padding: 10px 16px; }
.chat-handoff-queue summary { cursor: pointer; font-size: 13px; font-weight: 600; }
#chat-work-queue-kind { width: 100%; min-width: 0; margin-top: 10px; padding: 6px; font-size: 12px; }
.chat-handoff-queue-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 28px; gap: 6px; margin-top: 10px; }
.chat-handoff-queue-filters select { width: 100%; min-width: 0; padding: 6px; font-size: 12px; }
.chat-handoff-queue button { padding: 5px 8px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--surface-elevated); color: var(--text-primary); font-size: 12px; cursor: pointer; }
.chat-handoff-queue button:disabled { opacity: .6; cursor: default; }
.chat-handoff-queue-filters button { display: grid; place-items: center; width: 28px; height: 32px; padding: 0; }
#chat-handoff-queue-list { max-height: min(320px, 40vh); overflow: auto; margin-top: 8px; }
.chat-handoff-queue-row { padding: 10px 0; border-top: 1px solid var(--border-color); }
.chat-handoff-queue-row strong, .chat-handoff-queue-row p, .chat-handoff-queue-row time { display: block; font-size: 12px; overflow-wrap: anywhere; }
.chat-handoff-queue-row p, .chat-handoff-queue-row time { margin: 5px 0; color: var(--text-secondary); }
#chat-handoff-queue-more { margin-top: 8px; }
#chat-structured-intake-content { max-height: min(440px, 55vh); overflow: auto; padding-top: 8px; }
#chat-structured-intake-content label { display: block; font-size: 12px; margin-top: 8px; }
#chat-structured-intake-content input:not([type="checkbox"]), #chat-structured-intake-content select { width: 100%; min-width: 0; max-width: 100%; padding: 6px; font-size: 12px; }
#chat-structured-intake-content button { padding: 5px 8px; margin: 6px 6px 0 0; font-size: 12px; }
#chat-structured-intake-content fieldset { border: 1px solid var(--border-color); padding: 8px; margin: 8px 0; min-width: 0; }
#chat-structured-intake-content legend, #chat-structured-intake-content span { overflow-wrap: anywhere; font-size: 12px; }
.chat-structured-row { border-top: 1px solid var(--border-color); margin-top: 10px; padding-top: 8px; }
.chat-structured-row h4 { font-size: 13px; overflow-wrap: anywhere; margin: 4px 0; }
.chat-analysis-text { max-height: 240px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; padding: 8px; background: #f1f4f5; color: #20292c; }
.chat-media-analysis { padding: 8px 0; font-size: 12px; }
.chat-media-analysis summary { cursor: pointer; font-weight: 600; }
.chat-media-analysis button { min-height: 32px; padding: 6px 10px; border: 1px solid #bfc8cc; border-radius: 4px; background: #147866; color: #fff; font: inherit; cursor: pointer; }
.chat-media-analysis button:disabled { opacity: .55; cursor: default; }
.chat-document-requirements section {
    border-top: 1px solid #dce1e5;
    padding: 12px 0;
}
.chat-document-requirements button {
    border: 1px solid #b9c6c0;
    background: #f8faf9;
    color: #20563c;
    border-radius: 4px;
    padding: 5px 8px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}
.chat-document-requirements button:disabled { opacity: 0.5; cursor: default; }
.chat-booking fieldset { min-width: 0; width: 100%; box-sizing: border-box; }
.chat-booking label[hidden] { display: none; }
#chat-structured-intake-content label[hidden] { display: none; }
.chat-document-requirements h4 {
    font-size: 14px;
    margin: 8px 0;
}
.chat-document-requirements p,
.chat-document-requirements h4,
.chat-document-requirements label,
.chat-document-requirements summary {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.chat-document-requirements textarea {
    min-height: 72px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    resize: vertical;
}
.chat-intake-crm section { border-top: 1px solid #dce1e5; padding: 8px 0; }
.chat-intake-crm p, .chat-intake-crm strong { overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-intake-crm h4 { font-size: 13px; margin: 8px 0; }
.chat-intake-crm textarea { width: 100%; min-width: 0; max-width: 100%; min-height: 60px; box-sizing: border-box; resize: vertical; }

/* Keep conversation tools out of the reading and reply surface. */
.chat-layout { position: relative; min-height: 0; }
.chat-main, .chat-conversation { min-width: 0; min-height: 0; }
.chat-header { gap: 12px; }
.chat-header-info { min-width: 0; flex: 1; cursor: pointer; }
.chat-header-details h4 { overflow-wrap: anywhere; }
.chat-header-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.chat-office-ai-status { margin: 0; padding: 8px 20px 0; color: var(--muted-foreground); font-size: 12px; }
.chat-inbox-form { display: grid; gap: 8px; margin: 12px 0; }
.chat-inbox-form label { display: grid; gap: 6px; font-size: 12px; }
.chat-inbox-form label.chat-ai-switch { display: flex; align-items: flex-start; }
.chat-inbox-form input:not([type="checkbox"]), .chat-inbox-form select { width: 100%; min-width: 0; min-height: 34px; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--background); color: var(--foreground); font: inherit; font-size: 13px; }
.chat-inbox-form select { appearance: auto; background-image: none !important; }
html.dark .chat-inbox-form select { color-scheme: dark; }
.chat-inbox-form p { margin: 0; }
.chat-inbox-form textarea { box-sizing: border-box; width: 100%; min-width: 0; resize: vertical; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--background); color: var(--foreground); font: inherit; }
.chat-reply-preview { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--border); background: var(--secondary); font-size: 12px; }
.chat-reply-preview[hidden], .chat-message[hidden] { display: none !important; }
.chat-reply-preview span { flex: 1; min-width: 0; overflow-wrap: anywhere; max-height: 60px; overflow: auto; }
.chat-reply-preview .btn-icon, .chat-message-actions .btn-icon { width: 32px; height: 32px; flex: 0 0 32px; }
.chat-message-quote { margin: 0 0 8px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-message-meta { flex-wrap: wrap; }
.chat-message-actions { display: inline-flex; gap: 4px; align-items: center; }
.chat-message-actions select { max-width: 140px; min-height: 32px; padding: 4px; appearance: auto; background: var(--background); color: var(--foreground); border: 1px solid var(--border); border-radius: 4px; background-image: none !important; font-size: 12px; }
html.dark .chat-message-actions { color-scheme: dark; }
html.dark .chat-message-actions img, html.dark .chat-reply-preview img, html.dark .chat-choice-row img { filter: invert(1); }
.chat-message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chat-message-reactions span { border: 1px solid var(--border); background: var(--secondary); padding: 2px 6px; border-radius: 6px; }
.chat-message-bubble pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.chat-message-bubble small { display: block; overflow-wrap: anywhere; }
.chat-shared-contact { padding: 8px 0; border-bottom: 1px solid var(--border); }
.chat-shared-contact p { margin: 4px 0; }
.chat-choice-fields { display: grid; gap: 12px; }
.chat-choice-row { display: grid; gap: 6px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.chat-choice-row .btn-icon { justify-self: end; }
#ws-profile-form[hidden], #ws-profile-picture-form[hidden], #ws-profile-picture[hidden] { display: none !important; }
#ws-profile-fields { margin: 0; padding: 0; border: 0; min-width: 0; }
#ws-profile-fields:disabled { opacity: .75; }
#ws-profile-picture { object-fit: cover; border-radius: 6px; }
.ws-business-profile { margin-top: 24px; padding: 16px 0; border-top: 1px solid var(--border); }
#ws-profile-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
#ws-profile-fields input, #ws-profile-fields select { min-height: 38px; box-sizing: border-box; }
#ws-profile-fields label:has(textarea) { grid-column: 1 / -1; }
#ws-profile-form .ws-profile-review, #ws-profile-picture-form .ws-profile-review { display: flex; align-items: center; gap: 8px; }
.ws-profile-review input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; padding: 0; margin: 0; flex: 0 0 16px; accent-color: var(--brand); }
#ws-profile-form button, #ws-profile-picture-form button { justify-self: start; border-radius: 6px; min-height: 36px; }
@media (max-width: 600px) { #ws-profile-fields { grid-template-columns: minmax(0, 1fr); } }
.chat-browser-result { padding: 12px 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.chat-browser-result p { margin: 6px 0; white-space: pre-wrap; }
.chat-browser-result small { color: var(--muted-foreground); font-size: 11px; }
.chat-connection-notice { flex: 0 0 auto; margin: 0; padding: 10px 16px; color: var(--foreground); background: var(--secondary); border-top: 1px solid var(--border); font-size: 12px; }
.chat-connection-notice[hidden] { display: none; }
.chat-browser-result .chat-message { max-width: 100%; }
.chat-browser-result .chat-message-content { min-width: 0; max-width: 100%; }
.chat-header-actions .btn-icon { width: 36px; height: 36px; }
.chat-details { width: 336px; min-width: 336px; min-height: 0; background: var(--card); }
.chat-details-header { padding: 12px 16px; min-height: 60px; box-sizing: border-box; }
.chat-details-header h3 { font-size: 15px; }
.chat-details-content { padding: 0; min-height: 0; }
.chat-contact-summary, .chat-service-controls, .chat-task-tools { padding: 16px; border-bottom: 1px solid var(--border); }
.chat-contact-summary h4, .chat-service-controls h4 { font-size: 14px; margin: 0 0 8px; overflow-wrap: anywhere; }
.chat-contact-summary p, .chat-service-controls p { font-size: 12px; margin: 8px 0; color: var(--muted-foreground); overflow-wrap: anywhere; }
.chat-service-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.chat-details button:not(.btn-icon) { min-height: 34px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--secondary); color: var(--foreground); font: inherit; font-size: 12px; cursor: pointer; }
.chat-details button:disabled { opacity: .55; cursor: not-allowed; }
.chat-details button:hover:not(:disabled) { background: var(--muted); }
.chat-ai-switch { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.chat-ai-switch input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.chat-details .chat-saved-attachments { padding: 12px 16px; background: transparent; border-top: 0; border-bottom: 1px solid var(--border); }
.chat-details .chat-task-tools .chat-saved-attachments { padding: 12px 0 0; border: 0; }
.chat-details summary { min-height: 24px; font-weight: 600; }
.chat-saved-attachments select { appearance: auto; background-image: none !important; background-repeat: no-repeat; background-position: right 10px center; background-size: 12px; padding-right: 10px; min-height: 34px; }
html.dark .chat-saved-attachments select { color-scheme: dark; }
.chat-details .chat-checklist-form { margin-top: 12px; gap: 8px; }
.chat-details .chat-checklist-form select { flex: 1 1 100px; width: auto; }
.chat-details .chat-handoff-row { padding: 12px 0; overflow-wrap: anywhere; }
.chat-details [hidden] { display: none !important; }
.chat-input-container { align-items: flex-end; padding: 12px 16px; gap: 8px; }
.chat-input-wrapper textarea { min-height: 44px; max-height: 144px; line-height: 22px; padding: 10px 12px; overflow-y: auto; }
.chat-input-container > .btn-icon { flex: 0 0 44px; }
.chat-message.notice .chat-message-bubble { background: var(--secondary); color: var(--muted-foreground); border: 1px solid var(--border); font-size: 13px; }
.chat-history-label { color: var(--muted-foreground); font-size: 11px; }
.chat-message-load-error { padding: 16px; font-size: 13px; color: var(--foreground); }
.chat-details :focus-visible, .chat-header :focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
html.dark .chat-header-actions img { filter: invert(1); }
@media (max-width: 1200px) {
    .chat-details { position: absolute; right: 0; top: 0; bottom: 0; z-index: 30; width: min(360px, 100%); min-width: 0; box-shadow: -8px 0 24px rgb(0 0 0 / 12%); }
}
@media (max-width: 600px) {
    .chat-header { padding: 12px; gap: 8px; }
    .chat-header-info { gap: 8px; }
    .chat-header-details h4 { font-size: 14px; }
    .chat-header-details .chat-status { font-size: 11px; }
    .chat-input-container { padding: 8px; gap: 4px; }
    .chat-input-container > .btn-icon { width: 40px; min-width: 40px; flex-basis: 40px; }
}
