/*
 * ChatFlotte - Floating Chat Widget CSS
 * Compatible with Dolibarr 22.x
 * @package chatflotte
 */

/* ── Variables ──────────────────────────────────────────── */
:root {
    --cf-primary:      #3b5998;
    --cf-primary-dark: #2d4372;
    --cf-accent:       #25d366;
    --cf-bg:           #ffffff;
    --cf-surface:      #f0f2f5;
    --cf-border:       #dde1e7;
    --cf-text:         #1c1e21;
    --cf-text-muted:   #65676b;
    --cf-mine-bg:      #0084ff;
    --cf-mine-text:    #ffffff;
    --cf-their-bg:     #e4e6eb;
    --cf-their-text:   #1c1e21;
    --cf-shadow:       0 4px 24px rgba(0,0,0,0.18);
    --cf-radius:       16px;
    --cf-w:            340px;
    --cf-h:            480px;
    --cf-toggle-size:  56px;
}

/* ── Container ───────────────────────────────────────────── */
#chatflotte-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
}

/* ── Toggle Button ───────────────────────────────────────── */
#chatflotte-toggle {
    width:  var(--cf-toggle-size);
    height: var(--cf-toggle-size);
    border-radius: 50%;
    background: var(--cf-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--cf-shadow);
    position: relative;
    transition: background 0.2s, transform 0.2s;
    font-size: 22px;
    user-select: none;
}

#chatflotte-toggle:hover,
#chatflotte-toggle.chatflotte-active {
    background: var(--cf-primary-dark);
    transform: scale(1.08);
}

/* Badge */
.chatflotte-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: #fff;
    border-radius: 999px;
    min-width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
    animation: cf-pop 0.3s ease;
    line-height: 1;
}

@keyframes cf-pop {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ── Chat Window ─────────────────────────────────────────── */
#chatflotte-window {
    position: absolute;
    bottom: calc(var(--cf-toggle-size) + 12px);
    left: 0;
    width: var(--cf-w);
    height: var(--cf-h);
    background: var(--cf-bg);
    border-radius: var(--cf-radius);
    box-shadow: var(--cf-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: cf-slide-up 0.22s ease;
    border: 1px solid var(--cf-border);
}

@keyframes cf-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ──────────────────────────────────────────────── */
#chatflotte-header {
    background: var(--cf-primary);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-radius: var(--cf-radius) var(--cf-radius) 0 0;
}

#chatflotte-title {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.chatflotte-header-actions {
    display: flex;
    gap: 6px;
}

.chatflotte-btn-icon {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}

.chatflotte-btn-icon:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* ── User List Panel ─────────────────────────────────────── */
#chatflotte-userlist-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#chatflotte-search-box {
    padding: 10px 12px;
    border-bottom: 1px solid var(--cf-border);
    background: var(--cf-surface);
    flex-shrink: 0;
}

#chatflotte-search {
    width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--cf-border);
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    background: #fff;
    color: var(--cf-text);
}

#chatflotte-search:focus {
    border-color: var(--cf-primary);
}

#chatflotte-users {
    overflow-y: auto;
    flex: 1;
}

.chatflotte-user-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 10px;
    position: relative;
}

.chatflotte-user-item:hover {
    background: var(--cf-surface);
}

.chatflotte-user-item.chatflotte-has-unread {
    background: #eef4ff;
}

.chatflotte-avatar {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
}

.chatflotte-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chatflotte-avatar-initials {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--cf-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.chatflotte-user-info {
    flex: 1;
    min-width: 0;
}

.chatflotte-user-name {
    font-weight: 500;
    color: var(--cf-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.chatflotte-user-badge {
    background: #e74c3c;
    color: #fff;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.chatflotte-empty {
    text-align: center;
    padding: 30px 14px;
    color: var(--cf-text-muted);
    font-size: 13px;
}

/* ── Messages Panel ──────────────────────────────────────── */
#chatflotte-messages-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#chatflotte-messages-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--cf-border);
    gap: 8px;
    background: var(--cf-surface);
    flex-shrink: 0;
}

.chatflotte-btn-back {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--cf-primary);
    font-size: 16px;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s;
}

.chatflotte-btn-back:hover {
    background: var(--cf-border);
}

#chatflotte-peer-name {
    font-weight: 600;
    color: var(--cf-text);
    flex: 1;
}

.chatflotte-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #aaa;
    display: inline-block;
}

#chatflotte-messages-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #fff;
}

/* Message bubbles */
.chatflotte-msg {
    display: flex;
    margin-bottom: 2px;
    animation: cf-msg-in 0.18s ease;
}

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

.chatflotte-msg-mine    { justify-content: flex-end; }
.chatflotte-msg-theirs  { justify-content: flex-start; }

.chatflotte-bubble {
    max-width: 78%;
    padding: 8px 12px;
    border-radius: 16px;
    word-break: break-word;
}

.chatflotte-msg-mine .chatflotte-bubble {
    background: var(--cf-mine-bg);
    color: var(--cf-mine-text);
    border-bottom-right-radius: 4px;
}

.chatflotte-msg-theirs .chatflotte-bubble {
    background: var(--cf-their-bg);
    color: var(--cf-their-text);
    border-bottom-left-radius: 4px;
}

.chatflotte-msg-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 3px;
    opacity: 0.75;
}

.chatflotte-msg-text {
    font-size: 13.5px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.chatflotte-msg-text a {
    color: inherit;
    text-decoration: underline;
}

.chatflotte-msg-meta {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.65;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
}

.chatflotte-msg-mine .chatflotte-msg-meta  { color: rgba(255,255,255,0.75); }
.chatflotte-msg-theirs .chatflotte-msg-meta { color: var(--cf-text-muted); }

.chatflotte-file-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12.5px;
    padding: 4px 8px;
    background: rgba(0,0,0,0.08);
    border-radius: 8px;
    margin-top: 5px;
    text-decoration: none !important;
    color: inherit;
}

.chatflotte-file-link:hover {
    background: rgba(0,0,0,0.16);
}

.chatflotte-voice {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
    padding: 0;
    border-radius: 0;
    background: transparent;
}

.chatflotte-voice-btn {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    background: #1e88e5;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatflotte-msg-theirs .chatflotte-voice-btn {
    background: #1e88e5;
}

.chatflotte-voice-wave {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 16px;
    flex: 1;
    min-width: 96px;
    position: relative;
}

.chatflotte-voice-wave span {
    width: 3px;
    border-radius: 3px;
    background: rgba(255,255,255,0.85);
}

.chatflotte-msg-theirs .chatflotte-voice-wave span {
    background: rgba(255,255,255,0.85);
}

.chatflotte-voice-wave::after {
    content: "";
    position: absolute;
    inset: 0;
    width: var(--p, 0%);
    background: rgba(255,255,255,0.35);
    pointer-events: none;
    mix-blend-mode: screen;
}

.chatflotte-msg-theirs .chatflotte-voice-wave::after {
    background: rgba(255,255,255,0.35);
    mix-blend-mode: screen;
}

.chatflotte-voice-range {
    width: 0;
    flex: 0;
    opacity: 0;
    pointer-events: none;
}

.chatflotte-voice-time {
    font-size: 10px;
    opacity: 0.85;
    flex-shrink: 0;
    min-width: 30px;
    text-align: right;
}

.chatflotte-voice audio {
    display: none;
}

.chatflotte-no-messages {
    text-align: center;
    color: var(--cf-text-muted);
    font-size: 13px;
    margin: auto;
    padding: 20px;
}

/* Typing indicator */
#chatflotte-typing-indicator {
    padding: 6px 14px;
    flex-shrink: 0;
}

.chatflotte-typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 16px;
}

.chatflotte-typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--cf-text-muted);
    border-radius: 50%;
    animation: cf-bounce 1.2s infinite;
}

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

@keyframes cf-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* ── Input Area ──────────────────────────────────────────── */
#chatflotte-input-area {
    border-top: 1px solid var(--cf-border);
    background: var(--cf-bg);
    flex-shrink: 0;
    padding: 8px;
}

#chatflotte-file-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--cf-surface);
    border-radius: 8px;
    padding: 5px 10px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--cf-text-muted);
}

#chatflotte-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chatflotte-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.chatflotte-btn-attach {
    cursor: pointer;
    color: var(--cf-text-muted);
    font-size: 17px;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-bottom: 2px;
    border: none;
    background: transparent;
}

.chatflotte-btn-attach:hover {
    background: var(--cf-surface);
    color: var(--cf-primary);
}

/* Voice recording state */
#chatflotte-voice-btn.chatflotte-recording {
    background: rgba(231, 76, 60, 0.12);
    color: #e74c3c;
}

#chatflotte-input {
    flex: 1;
    border: 1px solid var(--cf-border);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13.5px;
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 36px;
    max-height: 100px;
    line-height: 1.4;
    overflow-y: hidden; /* hide scrollbar; JS auto-resizes */
    background: var(--cf-surface);
    color: var(--cf-text);
    transition: border-color 0.15s;
    box-sizing: border-box;
}

#chatflotte-input:focus {
    border-color: var(--cf-primary);
    background: #fff;
}

#chatflotte-send-btn {
    background: var(--cf-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
}

#chatflotte-send-btn:hover {
    background: var(--cf-primary-dark);
    transform: scale(1.08);
}

/* ── Scrollbar ───────────────────────────────────────────── */
#chatflotte-messages-body::-webkit-scrollbar,
#chatflotte-users::-webkit-scrollbar { width: 5px; }

#chatflotte-messages-body::-webkit-scrollbar-thumb,
#chatflotte-users::-webkit-scrollbar-thumb {
    background: var(--cf-border);
    border-radius: 3px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
    :root {
        --cf-w: calc(100vw - 20px);
        --cf-h: 75vh;
    }

    #chatflotte-container {
        bottom: 12px;
        left: 10px;
    }

    #chatflotte-window {
        left: 0;
        right: 0;
    }
}
