/* ==================== */
/* 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-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--brand-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
    position: relative;
}

.chat-list-item-avatar.online::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--success-color);
    border: 2px solid var(--surface-elevated);
    border-radius: 50%;
}

.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: var(--primary-color);
    color: white;
    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;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--brand-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.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: flex-end;
    gap: 0.75rem;
    background: var(--surface-elevated);
    flex-shrink: 0;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input-wrapper textarea {
    width: 100%;
    height: auto;
    min-height: 40px;
    max-height: 120px;
    padding: 0.5rem 1rem;
    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-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: var(--primary-color);
    color: white;
}

.btn-send:hover {
    background: var(--primary-dark);
    color: white;
}

.btn-send:disabled {
    opacity: 0.5;
    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;
}

.whatsapp-setup-card {
    position: relative;
    background: var(--bg-secondary, #1e1e2e);
    border-radius: 16px;
    padding: 2.5rem;
    max-width: 440px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color, #2d2d3d);
}

.whatsapp-setup-icon {
    color: #25D366;
    margin-bottom: 1.5rem;
}

.whatsapp-setup-icon svg {
    fill: #25D366;
}

.whatsapp-setup-card h3 {
    color: var(--text-primary, #e0e0e0);
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.ws-subtitle {
    color: var(--text-muted, #999);
    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(--text-muted, #888);
    font-size: 0.75rem;
    margin-top: 0.5rem;
    line-height: 1.5;
}

/* Spinner */
.ws-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color, #2d2d3d);
    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: #25D366;
    color: white;
    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: #1da851;
}

.ws-close-management {
    position: absolute;
    top: 0.75rem;
    right: 0.9rem;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.75rem;
    line-height: 1;
}

.ws-ai-policy {
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

.ws-ai-policy summary {
    cursor: pointer;
    font-weight: 600;
}

.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(--text-secondary);
    font-size: .8rem;
    font-weight: 600;
}

.ws-connection-picker select {
    width: 100%;
    min-width: 0;
    padding: .7rem .8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.ws-connection-form label,
.ws-copy-field {
    display: grid;
    gap: .35rem;
    color: var(--text-secondary);
    font-size: .8rem;
    font-weight: 600;
}

.ws-connection-form input,
.ws-copy-field input {
    width: 100%;
    box-sizing: border-box;
    padding: .7rem .8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.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-color);
    border-radius: 8px;
    padding: 0 .8rem;
    cursor: pointer;
}

.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-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;
}
