/* ===== INTIMURA Support Chat Widget ===== */
#chat-widget-root { --chat-green:#25D366; --chat-green-dark:#1ebe5d; }

.chat-bubble{
    position: fixed; bottom: 20px; right: 20px; z-index: 9998;
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--chat-green); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 18px rgba(37, 211, 102, 0.45), 0 2px 6px rgba(0,0,0,0.15);
    animation: chat-bounce 5s ease-in-out infinite;
    transition: transform 0.18s ease, background 0.18s ease;
}
.chat-bubble:hover{ transform: scale(1.08); background: var(--chat-green-dark); }
.chat-bubble:active{ transform: scale(0.94); }
.chat-bubble svg{ display:block; }
@keyframes chat-bounce{
    0%, 88%, 100% { transform: translateY(0); }
    91% { transform: translateY(-6px); }
    94% { transform: translateY(0); }
    97% { transform: translateY(-3px); }
}
.chat-bubble-dot{
    position: absolute; top: -2px; right: -2px;
    min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
    background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 2px #fff;
}

.chat-panel{
    position: fixed; bottom: 90px; right: 20px; z-index: 9999;
    width: 340px; height: 480px; max-height: calc(100vh - 120px);
    background: #fff; color: #111;
    border-radius: 16px; overflow: hidden;
    display: flex; flex-direction: column;
    box-shadow: 0 16px 48px rgba(0,0,0,0.22), 0 4px 12px rgba(0,0,0,0.08);
    animation: chat-pop 0.18s ease-out;
}
@keyframes chat-pop{ from{ opacity:0; transform: translateY(10px) scale(0.98);} to{opacity:1; transform:none;} }

.chat-panel-header{
    background: linear-gradient(135deg, #25D366 0%, #1ebe5d 100%);
    color: #fff; padding: 12px 14px;
    display:flex; align-items:center; justify-content: space-between;
    flex-shrink: 0;
}
.chat-panel-title{ display:flex; align-items:center; gap:10px; }
.chat-panel-avatar{
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display:flex; align-items:center; justify-content:center;
}
.chat-title-main{ font-weight:700; font-size:15px; line-height:1.2; }
.chat-title-sub{ font-size:11px; opacity:0.85; display:flex; align-items:center; gap:5px; }
.chat-title-sub::before{
    content:""; width:7px; height:7px; border-radius:50%;
    background:#b9f4c8; box-shadow:0 0 0 2px rgba(185,244,200,0.4);
    display:inline-block;
}
.chat-close{
    background: transparent; border:none; color:#fff;
    font-size: 24px; line-height:1; cursor:pointer;
    width:30px; height:30px; border-radius:50%;
    display:flex; align-items:center; justify-content:center;
    transition: background 0.15s;
}
.chat-close:hover{ background: rgba(255,255,255,0.18); }

.chat-messages{
    flex:1; overflow-y: auto; padding: 14px 12px;
    background: #ece5dd;
    display: flex; flex-direction: column; gap: 6px;
    background-image: linear-gradient(180deg, #ece5dd 0%, #ddd6cc 100%);
}
.chat-empty{
    color: #555; background: #fff;
    padding: 10px 14px; border-radius: 10px;
    font-size: 13px; align-self: center; margin-top: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-msg{
    max-width: 78%; display:flex; flex-direction: column;
    animation: chat-msg-in 0.14s ease-out;
}
@keyframes chat-msg-in{ from{opacity:0; transform: translateY(4px);} to{opacity:1; transform:none;} }
.chat-msg-user{ align-self: flex-end; align-items: flex-end; }
.chat-msg-admin{ align-self: flex-start; align-items: flex-start; }

.chat-msg-label{
    font-size: 10px; font-weight: 600;
    color: #25D366; padding: 0 8px; margin-bottom: 2px;
}
.chat-bubble-msg{
    padding: 8px 12px; border-radius: 16px;
    font-size: 14px; line-height: 1.4;
    word-wrap: break-word; word-break: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}
.chat-msg-user .chat-bubble-msg{
    background: #dcf8c6; color: #111;
    border-bottom-right-radius: 4px;
}
.chat-msg-admin .chat-bubble-msg{
    background: #fff; color: #111;
    border-bottom-left-radius: 4px;
}
.chat-msg-time{
    font-size: 10px; color: #8f8f8f;
    margin: 2px 6px 0;
}
.chat-msg-pending{ opacity: 0.7; }
.chat-msg-failed .chat-bubble-msg{ background: #fee; color: #c00; }

.chat-form{
    background: #f7f7f7; padding: 10px 10px 10px;
    display:flex; flex-direction: column; gap: 8px;
    flex-shrink: 0; border-top: 1px solid #e5e5e5;
}
.chat-intro-fields{
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.chat-intro-fields input{
    font-size: 12px; padding: 7px 10px;
    border: 1px solid #ddd; border-radius: 8px;
    background: #fff; color: #111;
    outline: none; min-width: 0;
}
.chat-intro-fields input:focus{ border-color: #25D366; }

.chat-input-row{
    display:flex; gap:8px; align-items: flex-end;
}
#chat-input{
    flex:1; min-height: 36px; max-height: 120px;
    padding: 9px 12px; font-size: 14px;
    border: 1px solid #ddd; border-radius: 18px;
    resize: none; outline: none; font-family: inherit;
    background: #fff; color: #111; line-height: 1.3;
}
#chat-input:focus{ border-color: #25D366; }

.chat-send{
    width: 38px; height: 38px; flex-shrink: 0;
    background: var(--chat-green); color: #fff;
    border: none; border-radius: 50%; cursor: pointer;
    display:flex; align-items:center; justify-content:center;
    transition: background 0.15s, transform 0.1s;
}
.chat-send:hover{ background: var(--chat-green-dark); }
.chat-send:active{ transform: scale(0.92); }
.chat-send svg{ margin-left: -2px; }

/* Dark mode */
html.dark .chat-panel{ background: #1e293b; color: #f1f5f9; }
html.dark .chat-messages{ background: #0f172a; background-image: linear-gradient(180deg, #0f172a 0%, #111827 100%); }
html.dark .chat-msg-admin .chat-bubble-msg{ background: #334155; color: #f1f5f9; }
html.dark .chat-msg-user .chat-bubble-msg{ background: #166534; color: #ecfdf5; }
html.dark .chat-msg-time{ color: #94a3b8; }
html.dark .chat-empty{ background: #1e293b; color: #cbd5e1; }
html.dark .chat-form{ background: #1e293b; border-top-color: #334155; }
html.dark #chat-input, html.dark .chat-intro-fields input{
    background: #0f172a; color: #f1f5f9; border-color: #334155;
}
html.dark #chat-input:focus, html.dark .chat-intro-fields input:focus{ border-color: #25D366; }

/* Mobile */
@media (max-width: 600px){
    .chat-panel{
        width: calc(100vw - 20px); right: 10px; left: 10px;
        bottom: 80px; height: 85vh; max-height: 85vh;
    }
    .chat-bubble{ bottom: 16px; right: 16px; }
}

/* ===== Admin chats page ===== */
.admin-chats-wrap{
    display: grid; grid-template-columns: 320px 1fr;
    gap: 16px; height: calc(100vh - 100px); min-height: 500px;
}
.admin-chat-list{
    background: var(--card, #fff); border: 1px solid var(--border, #e5e5e5);
    border-radius: 12px; overflow-y: auto; padding: 6px;
}
.admin-chat-list-empty{ padding: 24px; color: var(--text-muted, #888); text-align: center; font-size: 14px; }
.admin-chat-list-item{
    display:block; padding: 10px 12px; border-radius: 8px;
    text-decoration: none; color: var(--text, #111);
    border-bottom: 1px solid var(--border, #eee);
    transition: background 0.1s;
    position: relative;
}
.admin-chat-list-item:hover{ background: rgba(37,211,102,0.08); }
.admin-chat-list-item.active{ background: rgba(37,211,102,0.15); }
.admin-chat-list-item .chat-list-name{ font-weight: 600; font-size: 14px; }
.admin-chat-list-item .chat-list-preview{
    font-size: 12px; color: var(--text-muted, #888);
    overflow:hidden; text-overflow: ellipsis; white-space: nowrap;
    margin-top: 2px;
}
.admin-chat-list-item .chat-list-meta{
    font-size: 11px; color: var(--text-muted, #999); margin-top: 3px;
}
.admin-chat-list-unread{
    position: absolute; right: 10px; top: 12px;
    background: #ef4444; color: #fff;
    min-width: 20px; height: 20px; border-radius: 10px;
    padding: 0 6px; font-size: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
}

.admin-chat-thread{
    background: var(--card, #fff); border: 1px solid var(--border, #e5e5e5);
    border-radius: 12px; display: flex; flex-direction: column; overflow: hidden;
}
.admin-chat-thread-header{
    padding: 12px 16px; border-bottom: 1px solid var(--border, #eee);
    display:flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
}
.admin-chat-thread-header h3{ margin: 0; font-size: 16px; }
.admin-chat-thread-header .meta{ font-size: 12px; color: var(--text-muted, #888); }
.admin-chat-thread-messages{
    flex: 1; overflow-y: auto; padding: 16px;
    background: #ece5dd;
    display:flex; flex-direction: column; gap: 6px;
}
html.dark .admin-chat-thread-messages{ background: #0f172a; }
.admin-chat-thread-empty{
    align-self: center; margin-top: 40px; color: #888; font-size: 14px;
}
.admin-chat-reply-form{
    border-top: 1px solid var(--border, #eee); padding: 10px;
    display: flex; gap: 8px;
}
.admin-chat-reply-form textarea{
    flex: 1; min-height: 40px; max-height: 120px;
    padding: 9px 12px; border: 1px solid var(--border, #ddd);
    border-radius: 12px; resize: none; font-family: inherit; font-size: 14px;
    background: var(--bg, #fff); color: var(--text, #111);
}
.admin-chat-reply-form button{
    padding: 0 18px; background: var(--chat-green, #25D366); color: #fff;
    border: none; border-radius: 12px; cursor: pointer; font-weight: 600;
}
.admin-chat-reply-form button:hover{ background: #1ebe5d; }

@media (max-width: 800px){
    .admin-chats-wrap{ grid-template-columns: 1fr; height: auto; }
    .admin-chat-list{ max-height: 300px; }
    .admin-chat-thread{ min-height: 500px; }
}

/* Admin panel: flip bubble styles — admin=green right, visitor=gray left */
.admin-chat-thread-messages .chat-msg-user{ align-self: flex-start; align-items: flex-start; }
.admin-chat-thread-messages .chat-msg-admin{ align-self: flex-end; align-items: flex-end; }
.admin-chat-thread-messages .chat-msg-user .chat-bubble-msg{
    background: #f1f5f9; color: #111;
    border-bottom-left-radius: 4px; border-bottom-right-radius: 16px;
}
.admin-chat-thread-messages .chat-msg-admin .chat-bubble-msg{
    background: #dcf8c6; color: #111;
    border-bottom-right-radius: 4px; border-bottom-left-radius: 16px;
}
