/* ── Chat Widget ─────────────────────────────────────────── */

/* Floating chat button */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #01A1DD;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    overflow: visible;
}
.chat-fab:hover { transform: scale(1.08); }
.chat-fab svg { width: 28px; height: 28px; fill: #fff; }

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    border-radius: 10px;
    text-align: center;
    padding: 0 5px;
    display: none;
    z-index: 9991;
    pointer-events: none;
}

/* Chat panel */
.chat-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    z-index: 9991;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.chat-panel.open { display: flex; }

.chat-panel-header {
    padding: 14px 16px;
    background: #01A1DD;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
}
.chat-panel-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.chat-panel-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.8;
}
.chat-panel-header button:hover { opacity: 1; }
.chat-back-btn { margin-right: 8px; font-size: 18px; }

/* Conversation list */
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    margin: 0;
    list-style: none;
}
.chat-conv-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    transition: background 0.15s;
}
.chat-conv-item:hover { background: #f8f9fa; }
.chat-conv-item.unread { background: #e8f4ff; }

.chat-conv-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #01A1DD;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-conv-info { flex: 1; min-width: 0; }
.chat-conv-subject {
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-conv-preview {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.chat-conv-meta {
    font-size: 11px;
    color: #999;
    text-align: right;
    flex-shrink: 0;
}
.chat-conv-unread-badge {
    background: #01A1DD;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    border-radius: 9px;
    text-align: center;
    display: inline-block;
    margin-top: 4px;
}

/* New conversation button */
.chat-new-btn {
    display: block;
    width: calc(100% - 24px);
    margin: 12px;
    padding: 10px;
    background: #01A1DD;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
}
.chat-new-btn:hover { background: #0190c5; }

/* Messages view */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
}
.chat-msg.outgoing {
    align-self: flex-end;
    background: #01A1DD;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.incoming {
    align-self: flex-start;
    background: #f0f0f0;
    color: #333;
    border-bottom-left-radius: 4px;
}
.chat-msg.system {
    align-self: center;
    background: #fff8e1;
    color: #666;
    font-size: 12px;
    font-style: italic;
    border-radius: 8px;
    max-width: 90%;
    text-align: center;
}

.chat-msg-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.8;
}
.chat-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

/* Chat input area */
.chat-input-area {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.chat-input-area textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    resize: none;
    max-height: 80px;
    min-height: 36px;
    line-height: 1.4;
    outline: none;
}
.chat-input-area textarea:focus { border-color: #01A1DD; }
.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #01A1DD;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-send-btn:disabled { opacity: 0.4; cursor: default; }
.chat-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* Staff invite bar */
.chat-invite-bar {
    padding: 8px 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: center;
}
.chat-invite-bar select {
    flex: 1;
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
}
.chat-invite-btn {
    font-size: 12px;
    padding: 4px 12px;
    background: #01A1DD;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Empty state */
.chat-empty {
    padding: 40px 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

/* Loading */
.chat-loading {
    padding: 40px 20px;
    text-align: center;
    color: #999;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .chat-fab {
        bottom: 16px;
        right: 16px;
    }
}

/* MAUI app adjustment — avoid overlapping the native bottom tab bar */
body.is-maui .chat-fab { bottom: 72px; }
body.is-maui .chat-panel { bottom: 136px; }
@media (max-width: 480px) {
    body.is-maui .chat-panel { bottom: 60px; max-height: calc(100vh - 60px); }
}

/* ── Staff chat page (/WebShop/Chat) ─────────────────────── */

/* Conversation list items */
.chat-staff-conv-main {
    min-width: 0;
    flex: 1;
}
.chat-staff-conv-subject { font-size: 13px; }
.chat-staff-conv-meta { font-size: 12px; }
.chat-staff-conv-preview { font-size: 11px; }
.chat-staff-conv-side {
    flex-shrink: 0;
    font-size: 11px;
}
.chat-staff-empty { font-size: 14px; }

/* Detail panel */
#chatDetail { display: none; }
#chatInviteSelect {
    width: auto;
    min-width: 160px;
}
#chatContextBanner {
    display: none;
    font-size: 12px;
}
#chatMessages {
    height: 400px;
    overflow-y: auto;
    background: #fafafa;
}
#chatInput { resize: none; }

/* Message bubbles */
.chat-staff-sender { font-size: 11px; }
.chat-staff-bubble {
    max-width: 70%;
    font-size: 13px;
}
.chat-staff-time {
    font-size: 10px;
    opacity: 0.6;
    text-align: right;
}
