/* ══════════════════════════════════════════════════════════════
   ETICAR CRM — PREMIUM GLASSMORPHISM CHAT SYSTEM
   ══════════════════════════════════════════════════════════════ */

:root {
    --chat-primary: #6366f1;
    --chat-primary-light: #818cf8;
    --chat-primary-dark: #4f46e5;
    --chat-accent: #06b6d4;
    --chat-bg-dark: rgba(15, 23, 42, 0.95);
    --chat-bg-glass: rgba(255, 255, 255, 0.08);
    --chat-border-glass: rgba(255, 255, 255, 0.12);
    --chat-text-primary: #f1f5f9;
    --chat-text-secondary: #94a3b8;
    --chat-text-muted: #64748b;
    --chat-online: #22c55e;
    --chat-bubble-mine: linear-gradient(135deg, #6366f1, #8b5cf6);
    --chat-bubble-other: rgba(30, 41, 59, 0.8);
    --chat-radius: 18px;
    --chat-widget-width: 400px;
    --chat-widget-height: 580px;
    --chat-transition: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ─── FAB BUTTON ─── */
#chat-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 10000;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--chat-primary), #8b5cf6);
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.45), 0 0 0 0 rgba(99, 102, 241, 0.4);
    transition: all 0.4s var(--chat-transition);
    animation: chat-fab-pulse 3s ease-in-out infinite;
}

#chat-fab:hover {
    transform: scale(1.08) rotate(-5deg);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.6);
}

#chat-fab:active {
    transform: scale(0.95);
}

#chat-fab .chat-fab-icon {
    transition: transform 0.4s var(--chat-transition);
}

#chat-fab.active .chat-fab-icon {
    transform: rotate(90deg);
}

#chat-fab.active .fa-comments {
    display: none;
}

#chat-fab:not(.active) .fa-xmark {
    display: none;
}

@keyframes chat-fab-pulse {

    0%,
    100% {
        box-shadow: 0 8px 32px rgba(99, 102, 241, 0.45), 0 0 0 0 rgba(99, 102, 241, 0.3);
    }

    50% {
        box-shadow: 0 8px 32px rgba(99, 102, 241, 0.45), 0 0 0 14px rgba(99, 102, 241, 0);
    }
}

/* ─── UNREAD BADGE ─── */
#chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ef4444, #f97316);
    color: white;
    font-size: 11px;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.5);
    animation: chat-badge-bounce 0.6s var(--chat-transition);
    font-family: 'Inter', sans-serif;
}

#chat-fab-badge.visible {
    display: flex;
}

@keyframes chat-badge-bounce {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

/* ─── CHAT WIDGET CONTAINER ─── */
#chat-widget {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: 9999;
    width: var(--chat-widget-width);
    height: var(--chat-widget-height);
    border-radius: var(--chat-radius);
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.45s var(--chat-transition);
    display: flex;
    flex-direction: column;
    background: var(--chat-bg-dark);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid var(--chat-border-glass);
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    font-family: 'Inter', sans-serif;
}

#chat-widget.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ─── WIDGET HEADER ─── */
.chat-header {
    flex-shrink: 0;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.15));
    border-bottom: 1px solid var(--chat-border-glass);
    position: relative;
    overflow: hidden;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(99, 102, 241, 0.15), transparent 50%);
    pointer-events: none;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.chat-header-back {
    display: none;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: var(--chat-bg-glass);
    color: var(--chat-text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 14px;
}

.chat-header-back:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-header.in-chat .chat-header-back {
    display: flex;
}

.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 15px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    text-transform: uppercase;
    flex-shrink: 0;
}

.chat-header-info h3 {
    color: var(--chat-text-primary);
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
    font-family: 'Outfit', sans-serif;
}

.chat-header-info p {
    color: var(--chat-text-secondary);
    font-size: 11px;
    font-weight: 500;
    margin: 2px 0 0 0;
}

.chat-header-actions {
    display: flex;
    gap: 6px;
    z-index: 1;
}

.chat-header-actions button {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: var(--chat-bg-glass);
    color: var(--chat-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 13px;
}

.chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

/* Hidden by default, shown by mobile media query */
.chat-header-close-mobile {
    display: none !important;
}

/* ─── SEARCH BAR ─── */
.chat-search-wrap {
    padding: 12px 16px;
    flex-shrink: 0;
}

.chat-search {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border-radius: 12px;
    border: 1px solid var(--chat-border-glass);
    background: rgba(30, 41, 59, 0.6);
    color: var(--chat-text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    transition: all 0.3s ease;
    outline: none;
    box-sizing: border-box;
}

.chat-search:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chat-search::placeholder {
    color: var(--chat-text-muted);
}

.chat-search-wrap {
    position: relative;
}

.chat-search-wrap i {
    position: absolute;
    left: 30px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chat-text-muted);
    font-size: 13px;
    pointer-events: none;
}

/* ─── CONVERSATION LIST ─── */
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.3) transparent;
}

.chat-conv-list::-webkit-scrollbar {
    width: 5px;
}

.chat-conv-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-conv-list::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 10px;
}

.chat-conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    margin-bottom: 2px;
}

.chat-conv-item:hover {
    background: var(--chat-bg-glass);
}

.chat-conv-item.has-unread {
    background: rgba(99, 102, 241, 0.08);
}

.chat-conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
    text-transform: uppercase;
    position: relative;
}

.chat-conv-avatar.av-1 {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.chat-conv-avatar.av-2 {
    background: linear-gradient(135deg, #06b6d4, #14b8a6);
}

.chat-conv-avatar.av-3 {
    background: linear-gradient(135deg, #f97316, #eab308);
}

.chat-conv-avatar.av-4 {
    background: linear-gradient(135deg, #ec4899, #f43f5e);
}

.chat-conv-avatar.av-5 {
    background: linear-gradient(135deg, #22c55e, #10b981);
}

.chat-conv-body {
    flex: 1;
    min-width: 0;
}

.chat-conv-name {
    color: var(--chat-text-primary);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-preview {
    color: var(--chat-text-muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.chat-conv-time {
    color: var(--chat-text-muted);
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
}

.chat-conv-unread {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), #8b5cf6);
    color: white;
    font-size: 10px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: chat-badge-bounce 0.5s var(--chat-transition);
}

/* ─── NEW CHAT USER LIST ─── */
.chat-new-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chat-new-user:hover {
    background: var(--chat-bg-glass);
}

.chat-new-user-name {
    color: var(--chat-text-primary);
    font-size: 14px;
    font-weight: 600;
}

.chat-new-user-role {
    color: var(--chat-text-muted);
    font-size: 11px;
    margin-top: 1px;
}

/* ─── MESSAGES PANEL ─── */
.chat-panel-list,
.chat-panel-chat,
.chat-panel-new {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-panel-list.active,
.chat-panel-chat.active,
.chat-panel-new.active {
    display: flex;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.2) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 10px;
}

/* ─── MESSAGE BUBBLES ─── */
.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: chat-msg-in 0.35s var(--chat-transition);
}

@keyframes chat-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.mine {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg.theirs {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-msg-bubble {
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.chat-msg.mine .chat-msg-bubble {
    background: var(--chat-bubble-mine);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.chat-msg.theirs .chat-msg-bubble {
    background: var(--chat-bubble-other);
    color: var(--chat-text-primary);
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-msg-time {
    font-size: 10px;
    color: var(--chat-text-muted);
    margin-top: 3px;
    padding: 0 4px;
}

.chat-msg.mine .chat-msg-time {
    text-align: right;
}

/* ─── DATE SEPARATOR ─── */
.chat-date-sep {
    text-align: center;
    padding: 12px 0;
}

.chat-date-sep span {
    background: rgba(99, 102, 241, 0.12);
    color: var(--chat-text-secondary);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── TYPING INDICATOR ─── */
.chat-typing-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    color: var(--chat-text-muted);
    font-size: 12px;
    font-style: italic;
}

.chat-typing-indicator.visible {
    display: flex;
}

.chat-typing-dots {
    display: flex;
    gap: 3px;
}

.chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-primary-light);
    animation: chat-typing-dot 1.4s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chat-typing-dot {

    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: scale(0.8);
    }

    30% {
        opacity: 1;
        transform: scale(1.1);
    }
}

/* ─── INPUT BAR ─── */
.chat-input-bar {
    flex-shrink: 0;
    padding: 12px 16px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: rgba(15, 23, 42, 0.5);
    border-top: 1px solid var(--chat-border-glass);
}

.chat-input-wrap {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid var(--chat-border-glass);
    border-radius: 14px;
    padding: 4px;
    transition: all 0.3s ease;
}

.chat-input-wrap:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--chat-text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    padding: 8px 12px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    scrollbar-width: none;
}

#chat-input::-webkit-scrollbar {
    display: none;
}

#chat-input::placeholder {
    color: var(--chat-text-muted);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary), #8b5cf6);
    color: white;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ─── EMPTY STATE ─── */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 30px;
    text-align: center;
}

.chat-empty-icon {
    width: 70px;
    height: 70px;
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(6, 182, 212, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--chat-primary-light);
    margin-bottom: 16px;
    border: 1px solid rgba(99, 102, 241, 0.15);
}

.chat-empty-state h4 {
    color: var(--chat-text-primary);
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 6px 0;
    font-family: 'Outfit', sans-serif;
}

.chat-empty-state p {
    color: var(--chat-text-muted);
    font-size: 12px;
    line-height: 1.6;
    margin: 0;
}

/* ─── NEW CHAT BUTTON ─── */
.chat-new-btn {
    margin: 0 16px 8px;
    padding: 10px;
    border-radius: 12px;
    border: 1px dashed rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.05);
    color: var(--chat-primary-light);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
}

.chat-new-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--chat-primary);
}

/* ─── PANEL TRANSITIONS ─── */
.chat-slide-enter {
    animation: chat-slide-in 0.35s var(--chat-transition);
}

@keyframes chat-slide-in {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ─── LOADING SKELETON ─── */
.chat-skeleton {
    padding: 12px;
}

.chat-skeleton-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
}

.chat-skeleton-circle {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 200% 100%;
    animation: chat-shimmer 1.5s infinite;
    flex-shrink: 0;
}

.chat-skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.chat-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 200% 100%;
    animation: chat-shimmer 1.5s infinite;
}

.chat-skeleton-line:first-child {
    width: 60%;
}

.chat-skeleton-line:last-child {
    width: 40%;
}

@keyframes chat-shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    #chat-widget {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        top: 0;
    }

    #chat-widget.open {
        transform: translateY(0) scale(1);
    }

    #chat-fab {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        font-size: 22px;
    }

    /* Hide FAB when chat is open so it doesn't overlap send button */
    #chat-fab.active {
        display: none !important;
    }

    /* Show close button in header on mobile */
    .chat-header-close-mobile {
        display: flex !important;
    }

    .chat-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .chat-input-bar {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-msg {
        max-width: 88%;
    }
}

/* Landscape on small devices */
@media (max-height: 500px) and (orientation: landscape) {
    #chat-widget {
        height: 100vh;
        height: 100dvh;
        bottom: 0;
        top: 0;
        border-radius: 0;
    }

    .chat-messages {
        padding: 8px 16px;
    }

    #chat-fab.active {
        display: none !important;
    }

    .chat-header-close-mobile {
        display: flex !important;
    }
}