:root {
    --chat-primary: var(--cls-primary, #f59e0b);
    --chat-blue: #2563eb;
    --chat-light-blue: #eff6ff;
    --chat-dark-blue: #002f34;
    --chat-light-gray: #f8fafc;
    --chat-border: #e2e8f0;
    --chat-partner-bg: #ffffff;
    --chat-mine-bg: #e0f2fe;
}

/* Tooltip Styles */
.tooltip { position: relative; display: inline-block; overflow: visible !important; }
.tooltip .tooltiptext {
    visibility: hidden;
    width: 140px;
    background-color: var(--chat-dark-blue);
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px 10px;
    position: absolute;
    z-index: 1000 !important;
    bottom: 140%;
    left: 50%;
    transform: translateX(-50%) translateZ(100px);
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
    font-size: 0.75rem;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    backface-visibility: hidden;
}
.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--chat-dark-blue) transparent transparent transparent;
}
.tooltip:hover .tooltiptext { visibility: visible; opacity: 1; bottom: 125%; }
.tooltip-top .tooltiptext { bottom: 140%; left: 50%; transform: translateX(-50%); }
.tooltip-top:hover .tooltiptext { bottom: 120%; }

/* Modal Styles */
.chat-modal {
    position: fixed;
    z-index: 10000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: none;
    align-items: center; justify-content: center;
    backdrop-filter: blur(8px);
    transition: all 0.3s;
}
.chat-modal.active { display: flex; }
.chat-modal-content {
    background: #fff;
    padding: 40px;
    border-radius: 24px;
    max-width: 440px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    transform: scale(0.7);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.chat-modal.active .chat-modal-content { transform: scale(1); opacity: 1; }
.chat-modal i.modal-icon {
    width: 80px; height: 80px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 24px; font-size: 2.2rem;
}
.chat-modal .icon-danger { background: #fff1f2; color: #ef4444; }
.chat-modal .icon-warning { background: #fffbeb; color: #f59e0b; }
.chat-modal .icon-info { background: #eff6ff; color: #3b82f6; }
.chat-modal h3 { margin-bottom: 12px; color: var(--chat-dark-blue); font-size: 1.4rem; font-weight: 800; }
.chat-modal p { margin-bottom: 32px; color: #64748b; font-size: 1rem; line-height: 1.6; }
.chat-modal-footer { display: flex; gap: 12px; }
.chat-modal-footer button, .chat-modal-footer form { flex: 1; margin: 0; display: flex; }
.chat-modal-footer button, .chat-modal-footer input[type="submit"] {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    border: none;
    transition: all 0.2s;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.btn-cancel { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0 !important; }
.btn-cancel:hover { background: #e2e8f0; }
.btn-confirm { background: var(--chat-primary); color: #fff; box-shadow: 0 10px 15px -3px rgba(245, 158, 11, 0.3); }
.btn-confirm:hover { background: #d97706; transform: translateY(-2px); }
.btn-confirm-danger { background: #ef4444; color: #fff; box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.3); }
.btn-confirm-danger:hover { background: #dc2626; transform: translateY(-2px); }

.chat-container {
    display: flex;
    max-width: 1200px;
    margin: 40px auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    height: 80vh;
    min-height: 600px;
    overflow: visible !important;
}

.chat-sidebar {
    width: 360px;
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    background: #fff;
}

.chat-nav-links {
    display: flex;
    padding: 15px 20px;
    gap: 20px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--chat-border);
}
.chat-nav-links a {
    text-decoration: none;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    transition: color 0.2s;
}
.chat-nav-links a.active, .chat-nav-links a:hover { color: var(--chat-primary); }

.chat-tabs { display: flex; gap: 12px; padding: 20px; background: #fafafa; }
.chat-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    text-decoration: none;
    color: #64748b;
    font-weight: 700;
    font-size: 0.8rem;
    background: #fff;
    transition: all 0.2s;
}
.chat-tab.active {
    background: var(--chat-primary);
    border-color: var(--chat-primary);
    color: #fff;
    box-shadow: 0 4px 10px rgba(245, 158, 11, 0.2);
}

.chat-list-scroller { flex: 1; overflow-y: auto; }

.chat-section-title {
    padding: 15px 20px 5px;
    font-size: 0.7rem;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #fff;
}

.chat-item {
    display: flex;
    gap: 12px;
    padding: 15px 20px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.2s;
    position: relative;
}
.chat-item:hover { background: #f8fafc; }
.chat-item.active { background: #eff6ff; border-left: 4px solid var(--chat-primary); padding-left: 16px; }

.chat-item-avatar { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.chat-item-content { flex: 1; min-width: 0; }
.chat-item-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.chat-item-name { font-weight: 700; color: var(--chat-dark-blue); font-size: 0.9rem; }
.chat-item-date { font-size: 0.7rem; color: #94a3b8; }
.chat-item-message { font-size: 0.8rem; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; }

@keyframes unread-border-pulse {
    0% { border-left-color: #22c55e; box-shadow: inset 5px 0 10px -5px rgba(34,197,94,0.3); }
    50% { border-left-color: #16a34a; box-shadow: inset 15px 0 20px -10px rgba(34,197,94,0.6); }
    100% { border-left-color: #22c55e; box-shadow: inset 5px 0 10px -5px rgba(34,197,94,0.3); }
}
.chat-item.unread {
    background: #f0fdf4 !important;
    border-left: 6px solid #22c55e;
    animation: unread-border-pulse 2s infinite ease-in-out;
}

.status-dot {
    position: absolute;
    bottom: 2px; right: 2px;
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
    z-index: 5;
}
.status-dot.online { background: #22c55e; }
.status-dot.offline { background: #94a3b8; }
.status-dot-header { width: 12px; height: 12px; right: 0; bottom: 0; }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    position: relative;
    overflow: visible !important;
}
.chat-main.empty { justify-content: center; align-items: center; }

.chat-header {
    padding: 15px 25px;
    background: #fff;
    border-bottom: 1px solid var(--chat-border);
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    position: relative !important;
    z-index: 50 !important;
    overflow: visible !important;
}
.chat-header-actions { display: flex; gap: 15px; overflow: visible !important; position: relative; z-index: 101 !important; }
.chat-header-actions button { background: none; border: none; cursor: pointer; color: #94a3b8; font-size: 1.25rem; transition: color 0.2s; padding: 5px; outline: none; }
.chat-header-actions button:hover { color: var(--chat-primary); }
.chat-header-user { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--chat-dark-blue); }
.chat-header-avatar { width: 45px; height: 45px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.chat-header-name { font-weight: 700; font-size: 1.1rem; display: block; line-height: 1.2; }

.chat-listing-context {
    padding: 12px 25px;
    background: #fff;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 40 !important;
    overflow: visible !important;
}

#chatMessages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fdfdfd;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    position: relative;
    z-index: 1 !important;
}

.message-date-divider {
    text-align: center;
    margin: 10px 0;
}
.message-date-divider span {
    background: #e2e8f0;
    color: #64748b;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
}

.message-row { display: flex; gap: 12px; margin-bottom: 5px; }
.message-row.mine { flex-direction: row-reverse; }
.message-row-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; align-self: flex-end; border: 1px solid var(--chat-border); }

.message-bubble {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.message-bubble.mine { align-self: flex-end; background: var(--chat-mine-bg); color: var(--chat-dark-blue); border-bottom-right-radius: 4px; }
.message-bubble.partner { align-self: flex-start; background: var(--chat-partner-bg); border: 1px solid var(--chat-border); color: var(--chat-dark-blue); border-bottom-left-radius: 4px; }
.message-time { font-size: 0.65rem; margin-top: 6px; color: #94a3b8; display: flex; align-items: center; justify-content: flex-end; gap: 4px; }

.chat-footer { padding: 20px 25px; background: #fff; border-top: 1px solid var(--chat-border); }
.chat-input-wrapper { display: flex; gap: 12px; }
.chat-input { flex: 1; padding: 12px 20px; border: 1px solid var(--chat-border); border-radius: 12px; font-size: 0.95rem; outline: none; transition: border-color 0.2s; }
.chat-input:focus { border-color: var(--chat-primary); }
.chat-send-btn { background: var(--chat-primary); border: none; width: 45px; height: 45px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; cursor: pointer; transition: transform 0.2s; }
.chat-send-btn:hover { transform: scale(1.05); background: #d97706; }

@keyframes typingDots { 0% { opacity: 0.2; } 20% { opacity: 1; } 100% { opacity: 0.2; } }
.typing-dots span { animation: typingDots 1.4s infinite; animation-fill-mode: both; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Responsive */
@media (max-width: 900px) {
    .chat-container {
        margin: 10px auto;
        width: 100% !important;
        max-width: 100% !important;
        height: auto;
        min-height: calc(100vh - 100px);
        border-radius: 0;
        border: none;
        box-shadow: none;
        flex-direction: column;
    }
    .chat-sidebar { width: 100% !important; border-right: none; flex: 1; }
    .chat-main { display: none !important; }
    .chat-container.is-viewing .chat-sidebar { display: none !important; }
    .chat-container.is-viewing .chat-main { display: flex !important; width: 100% !important; min-height: calc(100vh - 150px); background: #fff; }
    .mobile-back-btn { display: flex !important; }
    .chat-header { padding: 12px 15px; position: sticky; top: 0; z-index: 10; }
    .chat-header-avatar { width: 38px; height: 38px; }
    .chat-footer { padding: 12px 15px; position: sticky; bottom: 0; border-top: 1px solid var(--chat-border); }
    .message-bubble { max-width: 90%; padding: 10px 15px; font-size: 0.92rem; }
    .chat-modal-content { padding: 30px 20px !important; border-radius: 18px !important; max-width: 310px !important; width: 92% !important; }
    .chat-modal i.modal-icon { width: 60px !important; height: 60px !important; font-size: 1.8rem !important; margin-bottom: 15px !important; }
    .chat-modal-footer { flex-direction: column !important; gap: 10px !important; }
    .chat-modal-footer button { padding: 12px !important; font-size: 0.9rem !important; }
}
