/* ── Chat Widget: Floating Action Button ───────────────────── */

.chat-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--green);
    color: var(--white);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-fab:hover {
    background: var(--green-dark);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(22,113,74,0.3);
}

/* ── Badge ──────────────────────────────────── */

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--red);
    color: var(--white);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* ── Chat Panel ─────────────────────────────── */

.chat-panel {
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    width: 360px;
    max-height: 500px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Chat Header ────────────────────────────── */

.chat-header {
    padding: 1rem 1.2rem;
    background: linear-gradient(160deg, var(--green-dark), var(--green));
    color: var(--white);
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}
.chat-title {
    font-weight: 600;
    font-size: 0.95rem;
    display: block;
}
.chat-status {
    font-size: 0.78rem;
    opacity: 0.7;
    margin-top: 0.15rem;
    display: block;
}
.chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}
.chat-close:hover { color: var(--white); }

/* ── Messages Area ──────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 340px;
    min-height: 200px;
}

/* ── Bubbles ────────────────────────────────── */

.chat-bubble {
    max-width: 80%;
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}
.chat-bubble--user {
    align-self: flex-end;
    background: var(--green);
    color: var(--white);
    border-bottom-right-radius: 4px;
}
.chat-bubble--admin {
    align-self: flex-start;
    background: var(--green-light);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.chat-time {
    display: block;
    font-size: 0.68rem;
    opacity: 0.55;
    margin-top: 0.25rem;
    text-align: right;
}

/* ── Empty state ────────────────────────────── */

.chat-empty {
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
    padding: 2rem 1rem;
}

/* ── Input Row ──────────────────────────────── */

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}
.chat-input-row input {
    flex: 1;
    padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 0.88rem;
    font-family: inherit;
    background: var(--white);
    color: var(--text);
}
.chat-input-row input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 4px var(--green-glow);
}
.chat-input-row .btn {
    padding: 0.55rem 0.8rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Responsive ─────────────────────────────── */

@media (max-width: 480px) {
    .chat-panel {
        right: 0.5rem;
        left: 0.5rem;
        bottom: 5rem;
        width: auto;
    }
    .chat-fab {
        bottom: 1rem;
        right: 1rem;
    }
}


/* ═══════════════════════════════════════════════
   Admin Page
   ═══════════════════════════════════════════════ */

.chat-admin-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
    max-width: 1000px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 55vh;
}

/* ── Sidebar ────────────────────────────────── */

.chat-admin-sidebar {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.chat-admin-sidebar-title {
    padding: 1rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    max-height: 55vh;
}
.chat-conv-item {
    padding: 0.8rem 1.2rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-conv-item:hover { background: var(--green-light); }
.chat-conv-item.active { background: var(--green-light); border-left: 3px solid var(--green); }
.chat-conv-pseudo {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text);
}
.chat-conv-preview {
    font-size: 0.78rem;
    color: var(--text-light);
    margin-top: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}
.chat-conv-meta {
    text-align: right;
    flex-shrink: 0;
}
.chat-conv-time {
    font-size: 0.7rem;
    color: var(--text-light);
}
.chat-conv-badge {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--red);
    color: var(--white);
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
    line-height: 18px;
    padding: 0 4px;
    margin-top: 0.3rem;
}

/* ── Thread Panel ───────────────────────────── */

.chat-admin-thread {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-admin-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-light);
    font-size: 0.9rem;
}
.chat-admin-thread-header {
    padding: 0.8rem 1.2rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.95rem;
    background: var(--green-light);
    color: var(--green-dark);
}
.chat-admin-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 45vh;
    min-height: 200px;
}
.chat-admin-reply {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}
.chat-admin-reply input {
    flex: 1;
    padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 0.88rem;
    font-family: inherit;
}
.chat-admin-reply input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 4px var(--green-glow);
}
.chat-admin-reply .btn {
    padding: 0.55rem 1rem;
    border-radius: 10px;
}

@media (max-width: 768px) {
    .chat-admin-layout {
        grid-template-columns: 1fr;
    }
    .chat-conv-list { max-height: 30vh; }
    .chat-admin-messages { max-height: 35vh; }
}

/* ── WhatsApp group messages ───────────── */
.wa-messages-area {
    max-height: 50vh;
    overflow-y: auto;
    padding: 0.5rem 0;
}
.wa-msg {
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid var(--border);
}
.wa-msg--me {
    background: #f0f7f0;
}
.wa-msg-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.2rem;
}
.wa-msg-sender {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--green-dark);
}
.wa-msg--me .wa-msg-sender {
    color: var(--text-light);
}
.wa-msg-time {
    font-size: 0.75rem;
    color: var(--text-light);
}
.wa-msg-body {
    font-size: 0.88rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}
.wa-msg-media {
    font-style: italic;
    color: var(--text-light);
    font-size: 0.8rem;
}
