/* Chat widget - bottom-right floating */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

.chat-toggle-btn {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.45);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    transition: transform 0.2s, box-shadow 0.2s;
}
.chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}
.chat-toggle-btn .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    background: #e53e3e;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

.chat-panel {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 540px;
    min-width: 380px;
    max-width: 95vw;
    height: 720px;
    min-height: 400px;
    max-height: 95vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    flex-direction: column;
    overflow: hidden;
}
.chat-panel.open {
    display: flex;
}
.chat-panel .chat-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 32px;
    height: 32px;
    cursor: nesw-resize;
    z-index: 100;
    border-radius: 0 0 0 12px;
    /* Resize grip - no gradient to avoid artifacts */
    background: rgba(156, 163, 175, 0.25);
}
.chat-panel .chat-resize-handle:hover {
    background: rgba(102, 126, 234, 0.3);
}
.chat-panel .chat-resize-handle::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 6px;
    width: 8px;
    height: 8px;
    border-left: 2px solid rgba(107, 114, 128, 0.6);
    border-bottom: 2px solid rgba(107, 114, 128, 0.6);
    border-radius: 2px 0 0 0;
}
.chat-panel .chat-resize-handle:hover::after {
    border-color: rgba(102, 126, 234, 0.8);
}

.chat-panel-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-header-title-wrap {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.chat-header-presence {
    font-size: 0.75em;
    font-weight: 500;
    opacity: 0.9;
}
.chat-panel-header .chat-close-btn {
    background: rgba(255,255,255,0.25);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.chat-panel-header .chat-close-btn:hover {
    background: rgba(255,255,255,0.4);
}

.chat-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}
.chat-tab {
    flex: 1;
    padding: 10px 14px;
    border: none;
    background: none;
    font-size: 0.9em;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}
.chat-tab:hover { color: #374151; }
.chat-tab.active {
    color: #667eea;
    background: white;
    border-bottom: 2px solid #667eea;
}

.chat-main-area {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}
.chat-dm-area {
    display: flex;
    flex-shrink: 0;
    min-width: 0;
}
.chat-dm-area[hidden] { display: none !important; }
.chat-dm-sidebar {
    width: 160px;
    min-width: 120px;
    flex-shrink: 0;
    border-right: 1px solid #e5e7eb;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-dm-sidebar-resize {
    width: 6px;
    min-width: 6px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
}
.chat-dm-sidebar-resize:hover {
    background: rgba(102, 126, 234, 0.25);
}
.chat-content-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
.chat-dm-sidebar-title {
    padding: 10px 12px;
    font-size: 0.8em;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.chat-dm-user-list {
    flex: 1;
    overflow-y: auto;
}
.chat-dm-user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
}
.chat-dm-user-row:hover {
    background: #f3f4f6;
}
.chat-dm-user-row.active {
    background: rgba(102, 126, 234, 0.12);
    border-left: 3px solid #667eea;
}
.chat-dm-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.95em;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-dm-name {
    flex: 1;
    font-size: 0.9em;
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-dm-unread {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #e53e3e;
    color: white;
    font-size: 0.75em;
    font-weight: 600;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-messages-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}
.chat-empty {
    position: absolute;
    left: 0; right: 0; top: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-new-messages-banner {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.9em;
    font-weight: 600;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
}
.chat-new-messages-banner:hover {
    opacity: 0.95;
    transform: translateX(-50%) scale(1.02);
}
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.95em;
    line-height: 1.4;
    word-wrap: break-word;
}
.chat-msg.own {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
.chat-msg.other {
    align-self: flex-start;
    background: #f3f4f6;
    color: #374151;
}
.chat-msg .chat-msg-meta {
    font-size: 0.75em;
    opacity: 0.85;
    margin-top: 4px;
}
.chat-msg .chat-msg-edited {
    font-size: 0.7em;
    font-style: italic;
    opacity: 0.8;
    margin-top: 2px;
}
.chat-msg.own .chat-msg-meta { color: rgba(255,255,255,0.9); }
.chat-msg[data-own="true"] {
    cursor: pointer;
}
.chat-msg[data-own="true"]:hover .chat-msg-edit-hint {
    opacity: 1;
}
.chat-msg-edit-hint {
    font-size: 0.7em;
    opacity: 0;
    transition: opacity 0.2s;
}
.chat-msg-status {
    margin-left: 6px;
    font-size: 1em;
    opacity: 1;
    vertical-align: middle;
}
.chat-msg-status-pending {
    opacity: 0.7;
    animation: chat-pulse 1.2s ease-in-out infinite;
}
.chat-msg-status-sent {
    color: rgba(255,255,255,0.95);
}
.chat-msg-status-delivered {
    color: rgba(255,255,255,0.85);
}
.chat-msg-status-read {
    color: #60a5fa;
}
.chat-msg-status-error {
    color: #fbbf24;
}
.chat-msg-pending {
    opacity: 0.92;
}
.chat-msg-error {
    opacity: 1;
    border: 1px solid rgba(251, 191, 36, 0.5);
}
.chat-msg-pending-file {
    opacity: 0.85;
    font-style: italic;
}
@keyframes chat-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}
.chat-msg-att {
    margin-top: 8px;
}
.chat-msg-img {
    max-width: 100%;
    max-height: 280px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}
.chat-msg-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.06);
    border-radius: 8px;
    color: #374151;
    text-decoration: none;
    font-size: 0.9em;
}
.chat-msg-file:hover { background: rgba(0,0,0,0.1); }
.chat-msg.own .chat-msg-file { background: rgba(255,255,255,0.25); color: white; }
.chat-msg.own .chat-msg-file:hover { background: rgba(255,255,255,0.35); }

.chat-input-wrap {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.chat-emoji-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
}
.chat-emoji-btn:hover {
    background: #f3f4f6;
    border-color: #667eea;
}
.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1em;
    resize: none;
    min-height: 80px;
    max-height: 180px;
    font-family: inherit;
    line-height: 1.4;
}
.chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}
.chat-send-btn {
    padding: 10px 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-send-btn:hover {
    opacity: 0.95;
}
.chat-emoji-panel {
    position: absolute;
    bottom: 100%;
    left: 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 320px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.chat-emoji-panel.open { display: flex; }
.chat-emoji-panel span {
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.chat-empty {
    color: #9ca3af;
    text-align: center;
    padding: 24px;
    font-size: 0.95em;
}

/* Toast notification - top-right */
.chat-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
}
.chat-toast {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 22px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
    border-left: 5px solid #667eea;
    font-size: 1.05em;
    animation: chat-toast-in 0.3s ease;
}
.chat-toast-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: #fef3c7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}
.chat-toast-content { flex: 1; }
.chat-toast-sender { font-weight: 700; color: #374151; margin-bottom: 6px; font-size: 1.1em; }
.chat-toast-preview { color: #6b7280; font-size: 1em; line-height: 1.4; }
@keyframes chat-toast-in {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* Tab badge - iOS style red circle */
.chat-tab {
    position: relative;
}
.chat-tab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #e53e3e;
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 480px) {
    .chat-panel { width: calc(100vw - 32px); right: -8px; }
    .chat-widget { right: 16px; bottom: 16px; }
}
