/* Premium Chat Widget Design System & Styles */

:root {
    --chat-primary: #007bff;
    --chat-primary-rgb: 0, 123, 255;
    --chat-success: #28a745;
    --chat-warning: #ffc107;
    --chat-danger: #dc3545;
    --chat-bg: rgba(255, 255, 255, 0.85);
    --chat-border: rgba(0, 0, 0, 0.08);
    --chat-text-main: #2d3748;
    --chat-text-muted: #718096;
    --chat-bubble-self: #e2f0fd;
    --chat-bubble-other: #f1f3f5;
    --chat-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

/* Floating Chat Icon Launcher */
.chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff, #0056b3);
    box-shadow: 0 4px 16px rgba(0, 123, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    cursor: pointer;
    z-index: 1050;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-launcher:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 20px rgba(0, 123, 255, 0.6);
}

.chat-launcher .badge-counter {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--chat-danger);
    color: white;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 99px;
    border: 2px solid white;
    font-weight: bold;
}

/* Chat Main Panel Container */
.chat-panel {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 420px;
    height: calc(100vh - 110px);
    max-height: 600px;
    min-height: 350px;
    background: var(--chat-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 16px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1040;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.075, 0.82, 0.165, 1);
}

.chat-panel.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Hide launcher when chat panel is open to prevent overlapping controls */
.chat-panel.active ~ .chat-launcher {
    display: none !important;
}

/* Header styling */
.chat-header {
    background: linear-gradient(90deg, #1f2937, #111827);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
}

.chat-header .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    position: relative;
}

.chat-header .avatar .status-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #111827;
}

.status-indicator.online { background-color: var(--chat-success); }
.status-indicator.away { background-color: var(--chat-warning); }
.status-indicator.offline { background-color: var(--chat-text-muted); }

/* Panes: Navigation list vs chat window */
.chat-body {
    flex: 1;
    display: flex;
    position: relative;
    background: #fdfdfd;
}

.chat-pane {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    background: white;
    transition: transform 0.3s ease-in-out;
}

.pane-list {
    z-index: 10;
}

.pane-window {
    transform: translateX(100%);
    z-index: 20;
}

.chat-panel.window-open .pane-window {
    transform: translateX(0);
}

.chat-panel.window-open .pane-list {
    transform: translateX(-100%);
}

/* User / Group search bar */
.search-wrapper {
    padding: 12px;
    border-bottom: 1px solid var(--chat-border);
    background: #fafafa;
}

.search-input {
    border-radius: 20px;
    padding-left: 15px;
    font-size: 0.9rem;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Conversations List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conv-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--chat-border);
    cursor: pointer;
    transition: background 0.2s ease;
    gap: 12px;
}

.conv-item:hover {
    background: rgba(var(--chat-primary-rgb), 0.05);
}

.conv-item .conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #4a5568;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    position: relative;
    flex-shrink: 0;
}

.conv-item .conv-details {
    flex: 1;
    min-width: 0;
}

.conv-item .conv-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--chat-text-main);
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conv-item .conv-time {
    font-size: 0.75rem;
    color: var(--chat-text-muted);
    font-weight: normal;
}

.conv-item .conv-preview {
    font-size: 0.8rem;
    color: var(--chat-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item .conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.unread-badge {
    background-color: var(--chat-primary);
    color: white;
    font-size: 0.75rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: bold;
}

/* Chat Message Window Area */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f7f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    position: relative;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message-bubble.self {
    align-self: flex-end;
    background-color: var(--chat-bubble-self);
    color: #1e3a8a;
    border-top-right-radius: 2px;
}

.message-bubble.other {
    align-self: flex-start;
    background-color: var(--chat-bubble-other);
    color: #1f2937;
    border-top-left-radius: 2px;
}

.message-bubble .message-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #94a3b8;
    margin-top: 4px;
}

.message-bubble.self .message-meta {
    color: #93c5fd;
}

.message-bubble .sender-label {
    font-weight: bold;
    font-size: 0.75rem;
    margin-bottom: 3px;
    color: #64748b;
}

.message-bubble.system-msg {
    align-self: center;
    background: rgba(0,0,0,0.05);
    color: #64748b;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 20px;
    box-shadow: none;
    text-align: center;
}

/* Attachment & File Preview UI */
.file-attachment-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.03);
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 5px;
    border: 1px solid rgba(0,0,0,0.05);
}

.file-attachment-preview i {
    font-size: 24px;
    color: var(--chat-primary);
}

/* Audio Player styling for Voice Notes */
.audio-player-vn {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
    padding: 5px 0;
}

.audio-player-vn button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.2rem;
    color: inherit;
}

/* Chat Input Footer Area */
.chat-footer {
    padding: 12px;
    border-top: 1px solid var(--chat-border);
    background: white;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-input-field {
    flex: 1;
    border-radius: 20px;
    border: 1px solid rgba(0,0,0,0.1);
    padding: 8px 16px;
    resize: none;
    max-height: 80px;
    font-size: 0.9rem;
    color: #2d3748 !important;
    background-color: #ffffff !important;
}

.chat-input-field::placeholder {
    color: #a0aec0 !important;
}

.chat-input-field:focus {
    outline: none !important;
    border-color: var(--chat-primary) !important;
    box-shadow: 0 0 0 2px rgba(var(--chat-primary-rgb), 0.2) !important;
    background-color: #ffffff !important;
    color: #2d3748 !important;
}

.chat-footer-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--chat-text-muted);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-footer-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--chat-primary);
}

.chat-footer-btn.send-btn {
    background: var(--chat-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(0,123,255,0.3);
}

.chat-footer-btn.send-btn:hover {
    background: #0056b3;
    color: white;
}

/* Voice Recording Panel */
.voice-record-panel {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    background: rgba(220, 53, 69, 0.05);
    border: 1px dashed var(--chat-danger);
    padding: 6px 15px;
    border-radius: 20px;
}

.voice-record-panel .timer {
    font-weight: bold;
    color: var(--chat-danger);
    font-size: 0.9rem;
    animation: blinker 1s linear infinite;
}

@keyframes blinker {
    50% { opacity: 0.3; }
}

/* Group moderation options sidebar */
.group-meta-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 30;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.chat-panel.meta-open .group-meta-panel {
    transform: translateX(0);
}

/* Typing Indicator Animation */
.typing-indicator-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    align-self: flex-start;
    background: var(--chat-bubble-other);
    padding: 10px 15px;
    border-radius: 15px;
    margin-left: 16px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Responsive Mobile Layout adjustments */
@media (max-width: 480px) {
    .chat-panel {
        bottom: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
    }
    
    .chat-header {
        border-radius: 0 !important;
    }
}
