/**
 * 在线客服：前台悬浮组件样式
 * 颜色通过 --chat-* CSS 变量在 chat_widget.php 里按主题注入
 */

:root {
    --chat-accent:      #00d8c0;
    --chat-bg:          #16161a;
    --chat-bg-soft:     #1f1f25;
    --chat-text:        #e8e8ea;
    --chat-text-muted:  #9a9aa6;
    --chat-line:        rgba(255,255,255,.08);
    --chat-bubble-visitor:  #00d8c0;
    --chat-bubble-admin:    #1f1f25;
    --chat-bubble-admin-text: #e8e8ea;
    --chat-bubble-system:   #2a2a30;
    --chat-bubble-system-text: #9a9aa6;
}

/* =============== 悬浮按钮 =============== */
.chat-float { position: fixed; right: 20px; bottom: 20px; z-index: 9999; font-family: inherit; }

.chat-fab {
    display: inline-flex; align-items: center; gap: 10px;
    height: 48px; padding: 0 14px 0 12px;
    background: var(--chat-accent); color: #04110f;
    border: 0; border-radius: 24px; cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,0,0,.25), 0 2px 6px rgba(0,0,0,.15);
    font-size: 14px; font-weight: 600; letter-spacing: .2px;
    transition: transform .2s ease, box-shadow .2s ease, border-radius .2s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,.32); }
.chat-fab.active { border-radius: 24px 24px 6px 6px; }
.chat-fab:active { transform: translateY(0); }
.chat-fab-label { white-space: nowrap; }
.chat-fab-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.25);
    transition: background .3s, box-shadow .3s;
}
.chat-fab-dot.offline { background: #9a9aa6; box-shadow: 0 0 0 3px rgba(154,154,166,.25); }

@media (max-width: 640px) {
    .chat-float { right: 14px; bottom: 72px; }
    .chat-fab { padding: 0; width: 50px; height: 50px; border-radius: 50%; justify-content: center; }
    .chat-fab-label { display: none; }
}

/* =============== 弹窗 =============== */
.chat-panel {
    position: absolute; right: 0; bottom: 62px;
    width: 370px; height: 540px;
    background: var(--chat-bg);
    border: 1px solid var(--chat-line);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35), 0 4px 12px rgba(0,0,0,.15);
    display: flex; flex-direction: column; overflow: hidden;
    animation: chat-fade .18s ease-out;
}
@media (max-width: 640px) {
    .chat-panel { right: 0; left: 0; bottom: 62px; width: auto; height: 58vh; max-height: 520px; border-radius: 14px 14px 4px 4px; }
}
.chat-panel.hidden { display: none; }
@keyframes chat-fade { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* 头部 */
.chat-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--chat-line);
    background: var(--chat-bg);
}
.chat-head-left { display: flex; align-items: center; gap: 10px; }
.chat-head-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--chat-accent); color: #04110f;
    display: grid; place-items: center; flex-shrink: 0;
}
.chat-head-text { display: flex; flex-direction: column; }
.chat-head-title { font-size: 14px; font-weight: 600; color: var(--chat-text); }
.chat-head-sub { font-size: 11px; color: var(--chat-text-muted); margin-top: 1px; }
.chat-head-actions { display: flex; gap: 4px; }
.chat-head-btn {
    width: 28px; height: 28px; border: 0; background: transparent;
    color: var(--chat-text-muted); border-radius: 6px;
    cursor: pointer; display: grid; place-items: center;
    transition: background .15s, color .15s;
}
.chat-head-btn:hover { background: var(--chat-bg-soft); color: var(--chat-text); }

/* 消息区 */
.chat-log {
    flex: 1; overflow-y: auto;
    padding: 14px 14px 16px;
    display: flex; flex-direction: column; gap: 8px;
    scroll-behavior: smooth;
}
.chat-log::-webkit-scrollbar { width: 6px; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px; }
html[data-theme="light"] .chat-log::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); }

.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg-visitor { align-self: flex-end; align-items: flex-end; }
.chat-msg-admin   { align-self: flex-start; align-items: flex-start; }
.chat-msg-system  { align-self: center; max-width: 92%; }

.chat-who { font-size: 11px; color: var(--chat-text-muted); margin-bottom: 2px; padding: 0 4px; }

.chat-bubble {
    padding: 9px 12px; border-radius: 12px;
    font-size: 13.5px; line-height: 1.55; color: var(--chat-text);
    word-wrap: break-word; white-space: pre-wrap;
}
.chat-msg-visitor .chat-bubble { background: var(--chat-bubble-visitor); color: #04110f; border-bottom-right-radius: 4px; }
.chat-msg-admin   .chat-bubble { background: var(--chat-bubble-admin); color: var(--chat-bubble-admin-text); border: 1px solid var(--chat-line); border-bottom-left-radius: 4px; }
.chat-bubble-system {
    background: transparent; color: var(--chat-bubble-system-text);
    font-size: 12px; text-align: center; padding: 4px 10px;
    border-radius: 10px;
}

.chat-time { font-size: 10px; color: var(--chat-text-muted); margin-top: 3px; padding: 0 4px; display: inline-flex; align-items: center; gap: 4px; }

/* 已读回执：访客自己发的消息右下角显示送达/已读 */
.chat-read {
    display: inline-flex; align-items: center; gap: 2px;
    font-size: 10px; color: var(--chat-text-muted);
    margin-top: 2px; padding: 0 4px;
}
.chat-read-icon { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chat-read.delivered .chat-read-icon { color: var(--chat-text-muted); }
.chat-read.seen      .chat-read-icon { color: #10b981; }
.chat-read .chat-read-label { margin-left: 2px; }

/* 撤回占位 */
.chat-bubble-recalled {
    display: inline-block;
    padding: 8px 12px; border-radius: 12px;
    font-size: 12.5px; color: var(--chat-text-muted);
    background: transparent;
    font-style: italic;
    opacity: .75;
}
.chat-bubble-recalled svg { width: 12px; height: 12px; margin-right: 4px; vertical-align: -2px; opacity: .8; }

/* 撤回按钮（悬浮到自己消息上出现） */
.chat-msg .chat-recall-btn {
    opacity: 0; transition: opacity .15s;
    background: transparent; border: 0; color: var(--chat-text-muted);
    font-size: 11px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.chat-msg:hover .chat-recall-btn { opacity: 1; }
.chat-msg .chat-recall-btn:hover { color: #fb7185; background: rgba(251,113,133,.1); }
.chat-msg .chat-recall-btn:disabled { opacity: 0; cursor: default; }

/* 输入区 */
.chat-form {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--chat-line);
    background: var(--chat-bg);
}
.chat-input {
    flex: 1; resize: none; border: 1px solid var(--chat-line);
    background: var(--chat-bg-soft); color: var(--chat-text);
    border-radius: 10px; padding: 8px 12px;
    font-size: 13.5px; line-height: 1.5; max-height: 120px;
    outline: none; transition: border-color .15s, background .15s;
    font-family: inherit;
}
.chat-input::placeholder { color: var(--chat-text-muted); }
.chat-input:focus { border-color: var(--chat-accent); }
.chat-input:disabled { opacity: .5; cursor: not-allowed; }

.chat-send {
    width: 36px; height: 36px; flex-shrink: 0;
    border: 0; border-radius: 10px;
    background: var(--chat-accent); color: #04110f;
    display: grid; place-items: center; cursor: pointer;
    transition: opacity .15s, transform .15s;
}
.chat-send:hover:not(:disabled) { opacity: .9; }
.chat-send:active:not(:disabled) { transform: scale(.94); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }

/* 状态条 */
.chat-foot {
    padding: 0 14px 10px; display: flex; align-items: center;
    border-top: 1px solid var(--chat-line);
}
.chat-foot-status { font-size: 11px; color: var(--chat-text-muted); padding: 6px 0; }
