/* ================================================
   CHAT UI STYLES
   ================================================ */

/* --- Conversations Search --- */
.conversations-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    width: 100%;
}
.conversations-search .material-icons-outlined {
    font-size: 18px;
    color: var(--color-text-muted);
}
.conversations-search input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.82rem;
    color: var(--color-text);
    width: 100%;
}
.conversations-search input::placeholder {
    color: var(--color-text-muted);
}

/* --- Conversations List --- */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.conversations-list::-webkit-scrollbar { width: 4px; }
.conversations-list::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 4px;
}
.conversations-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
}
.conversations-empty-content {
    text-align: center;
}
.conversations-empty-content .material-icons-outlined {
    font-size: 40px;
    color: var(--color-text-muted);
    opacity: 0.4;
    margin-bottom: 10px;
}
.conversations-empty-content p {
    color: var(--color-text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 4px;
}
.conversations-empty-hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    opacity: 0.7;
}

/* --- Conversation Item --- */
.conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid rgba(0,0,0,0.04);
    position: relative;
}
.conv-item:hover {
    background: rgba(13,148,136,0.04);
}
.conv-item.active {
    background: rgba(13,148,136,0.08);
    border-left: 3px solid var(--color-accent);
}
.conv-item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
    flex-shrink: 0;
}
.conv-item-body {
    flex: 1;
    min-width: 0;
}
.conv-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}
.conv-item-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item-time {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
    margin-left: 6px;
}
.conv-item-preview {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}
.conv-item-preview .material-icons-outlined {
    font-size: 14px;
    color: var(--color-text-muted);
}
.conv-item-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--color-accent);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    flex-shrink: 0;
}
.conv-item-time.has-unread {
    color: var(--color-accent);
    font-weight: 600;
}

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--color-bg);
    position: relative;
}

/* Chat Welcome */
.chat-welcome {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-welcome-inner {
    text-align: center;
    max-width: 400px;
    animation: fadeInChat 0.5s ease;
}
@keyframes fadeInChat {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-welcome-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(13,148,136,0.1), rgba(13,148,136,0.05));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
}
.chat-welcome-icon .material-icons-outlined {
    font-size: 36px;
    color: var(--color-accent);
}
.chat-welcome h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 6px;
}
.chat-welcome-sub {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}
.chat-welcome-hint {
    color: var(--color-text-muted);
    font-size: 0.82rem;
    margin-bottom: 24px;
}

/* WS Status */
.chat-welcome-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(0,0,0,0.04);
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--color-text-secondary);
}
.ws-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.ws-dot--connected {
    background: var(--color-success);
    box-shadow: 0 0 6px rgba(34,197,94,0.5);
    animation: pulseGlow 2s ease-in-out infinite;
}
.ws-dot--connecting {
    background: var(--color-warning);
    animation: blink 1s ease-in-out infinite;
}
.ws-dot--disconnected {
    background: var(--color-error);
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Chat Active */
.chat-active {
    display: flex;
    flex-direction: row;
    height: 100%;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.chat-back-btn {
    display: none;
    color: var(--color-text-secondary);
    transition: color var(--transition-fast);
}
.chat-back-btn:hover { color: var(--color-accent); }
.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f766e, #0d9488);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}
.chat-header-info {
    flex: 1;
    min-width: 0;
}
.chat-header-name {
    display: block;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--color-text);
}
.chat-header-phone {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.chat-header-actions {
    display: flex;
    gap: 4px;
}
.chat-action-btn {
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    transition: all var(--transition-fast);
}
.chat-action-btn:hover {
    background: rgba(0,0,0,0.06);
    color: var(--color-accent);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #efeae2;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
}

/* Date divider */
.chat-date-divider {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}
.chat-date-divider span {
    background: rgba(225,218,208,0.9);
    color: #54656f;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

/* Message Bubbles */
.chat-bubble {
    max-width: 65%;
    padding: 8px 12px 6px;
    border-radius: 10px;
    position: relative;
    animation: bubbleIn 0.2s ease;
    word-wrap: break-word;
    line-height: 1.4;
}
@keyframes bubbleIn {
    from { opacity: 0; transform: translateY(6px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-bubble--inbound {
    align-self: flex-start;
    background: #ffffff;
    border-top-left-radius: 2px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.chat-bubble--outbound {
    align-self: flex-end;
    background: #d9fdd3;
    border-top-right-radius: 2px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.chat-bubble-content {
    font-size: 0.88rem;
    color: #111b21;
}
.chat-bubble-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}
.chat-bubble-time {
    font-size: 0.66rem;
    color: #667781;
}
.chat-bubble-check {
    font-size: 14px;
    color: #53bdeb;
}

/* Media Messages */
.chat-media-img {
    max-width: 100%;
    max-height: 250px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
    object-fit: contain;
}
.chat-media-video {
    max-width: 100%;
    max-height: 250px;
    border-radius: 8px;
    display: block;
}
.chat-media-audio {
    width: 250px;
    max-width: 100%;
    height: 40px;
    outline: none;
}
.chat-media-doc {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    color: var(--color-text);
    text-decoration: none;
    font-weight: 500;
}
.chat-media-doc:hover {
    background: rgba(0,0,0,0.08);
}
.chat-media-doc .material-icons-outlined {
    font-size: 24px;
    color: var(--color-accent);
}

/* Chat Input Bar */
.chat-input-bar {
    padding: 10px 16px;
    background: #f0f2f5;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}
.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--color-bg-card);
    border-radius: 24px;
    padding: 6px 6px 6px 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.9rem;
    color: var(--color-text);
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    padding: 6px 0;
    font-family: var(--font-family);
}
.chat-input::placeholder {
    color: var(--color-text-muted);
}
.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(13,148,136,0.3);
}
.chat-send-btn:hover:not(:disabled) {
    background: var(--color-accent-hover);
    transform: scale(1.05);
}
.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}
.chat-send-btn .material-icons-outlined {
    font-size: 20px;
    transform: rotate(-45deg);
}

/* Loading spinner for chat */
.chat-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-loading::after {
    content: '';
    width: 30px;
    height: 30px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Responsive */
@media (max-width: 900px) {
    .conversations-panel { width: 240px; min-width: 240px; }
}
@media (max-width: 700px) {
    .chat-back-btn { display: block; }
    .conversations-panel { width: 100%; min-width: 100%; }
}
