/* ===== 微信风格 · 绿白配色 ===== */
:root {
    --green: #07c160;
    --green-dark: #06ad56;
    --green-light: #e8f8ef;
    --bg: #ededed;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-sub: #888888;
    --border: #ebedf0;
    --me-bubble: #95ec69;
    --me-bubble-text: #1a1a1a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC",
        "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ===== 布局骨架 ===== */
.app {
    max-width: 480px;
    margin: 0 auto;
    height: 100%;
    height: 100dvh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    position: relative;
}

.app-wide { max-width: 960px; }

/* ===== 用户端：手机比例外壳 ===== */
body.user-app { background: #e9ebee; }
@media (min-width: 700px) {
    body.user-app {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        overflow: hidden;
    }
    body.user-app .app {
        width: 390px;
        height: min(844px, calc(100vh - 32px));
        border-radius: 26px;
        overflow: hidden;
        box-shadow: 0 22px 60px rgba(0, 0, 0, .18), 0 0 0 1px rgba(0, 0, 0, .05);
    }
}

.topbar {
    background: var(--green);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
}
.topbar h1 { font-size: 17px; font-weight: 600; }
.topbar .side { font-size: 13px; opacity: .9; }

.body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ===== 卡片与表单 ===== */
.card {
    background: var(--card);
    margin: 16px;
    border-radius: 14px;
    padding: 20px 16px;
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 6px; }
.field input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f7f7f7;
    font-size: 15px;
    outline: none;
}
.field input:focus { border-color: var(--green); background: #fff; }

.btn {
    display: inline-block;
    border: none;
    background: var(--green);
    color: #fff;
    font-size: 15px;
    padding: 11px 18px;
    border-radius: 10px;
    width: 100%;
    text-align: center;
}
.btn:active { background: var(--green-dark); }
.btn-plain {
    background: #fff;
    color: var(--green);
    border: 1px solid var(--green);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 14px;
}
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; width: auto; }
.btn-danger { background: #fa5151; }
.link { color: var(--green); font-size: 13px; text-decoration: none; }
.hint { font-size: 12px; color: var(--text-sub); margin-top: 10px; text-align: center; }

/* ===== 登录入口 ===== */
.entry-list { padding: 24px 16px; }
.entry-item {
    background: var(--card);
    border-radius: 14px;
    padding: 18px 16px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.entry-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--green-light);
    color: var(--green);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex: 0 0 auto;
}
.entry-item .meta { flex: 1; }
.entry-item .meta b { display: block; font-size: 15px; }
.entry-item .meta span { font-size: 12px; color: var(--text-sub); }

/* ===== 客服列表 ===== */
.agent-item {
    display: flex; align-items: center; gap: 12px;
    background: #fff; padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.agent-item .avatar {
    width: 42px; height: 42px; border-radius: 12px;
    background: var(--green); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
}
.agent-item .meta { flex: 1; }
.agent-item .meta b { font-size: 15px; }
.agent-item .meta span { display: block; font-size: 12px; color: var(--text-sub); }

/* ===== 聊天区 ===== */
#view-chat { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#view-chat #chat-panel { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#view-chat #chat-panel .chat-wrap { flex: 1 1 auto; min-height: 0; }
body.chat-mode .app > .topbar { display: none; }
body.chat-mode .body { overflow: hidden; }

.chat-wrap { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* 仿微信会话头部 */
.chat-nav {
    flex: 0 0 auto;
    height: 46px;
    background: #ededed;
    border-bottom: .5px solid #dcdcdc;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 6px;
    position: relative;
    z-index: 2;
}
.chat-nav h1 {
    position: absolute; left: 50%; transform: translateX(-50%);
    max-width: 62%;
    font-size: 17px; font-weight: 600; color: #181818;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-back {
    border: none; background: none; padding: 10px 6px;
    color: #181818; display: flex; align-items: center;
}
.chat-back:active { opacity: .6; }
.chat-nav-side { width: 36px; }

.chat-messages {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 12px;
    display: flex; flex-direction: column; gap: 14px;
    background: var(--bg);
}
.msg { display: flex; gap: 10px; max-width: 85%; }
.msg .avatar {
    width: 40px; height: 40px; border-radius: 4px;
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 15px;
    background: #c7c7cc;
}
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.me .avatar { background: var(--green); }
.msg .bubble {
    background: #fff;
    border-radius: 4px;
    padding: 9px 12px;
    line-height: 1.45;
    word-break: break-word;
}
.msg.me .bubble { background: var(--me-bubble); }
.msg .name { font-size: 11px; color: var(--text-sub); margin-bottom: 4px; }
.msg.me .name { text-align: right; }
.msg .bubble img { max-width: 180px; border-radius: 4px; display: block; }
.msg .bubble audio, .msg .bubble video { max-width: 220px; display: block; }
.msg .bubble .media-label { font-size: 12px; color: var(--text-sub); }

/* ===== 底部聊天栏（用户端 + 客服端共用） ===== */
.cbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px calc(11px + env(safe-area-inset-bottom, 0px));
    background: #f2f2f2;
    border-top: .5px solid #e2e2e2;
}
.cbar-btn {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
    background: #fff;
    color: #1a1a1a;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.cbar-btn:active,
.cbar-btn.active { background: #e6e6e6; }
.cbar-btn.recording { border-color: var(--green); color: var(--green); }

.cbar-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 42px;
    display: flex; align-items: center;
    gap: 4px;
    padding: 0 10px 0 13px;
    background: #fff;
    border-radius: 10px;
}
.cbar-input input {
    flex: 1 1 auto;
    min-width: 0;
    border: none; outline: none;
    background: transparent;
    font-size: 16px;
    color: #181818;
    line-height: 42px;
}
.cbar-input input::placeholder { color: #b2b2b2; }
.cbar-mic {
    flex: 0 0 auto;
    border: none; background: none;
    padding: 2px;
    color: #9a9a9a;
    display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.cbar-mic.recording { color: var(--green); }

.cbar-send {
    flex: 0 0 auto;
    display: none;
    height: 38px;
    min-width: 56px;
    padding: 0 12px;
    border: none;
    border-radius: 8px;
    background: var(--green);
    color: #fff;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}
.cbar-send:active { background: var(--green-dark); }
.cbar.typing .cbar-btn#btn-plus { display: none; }
.cbar.typing .cbar-send { display: block; }
.cbar.recording .cbar-input { background: #ececec; }

/* ===== 表情 / 更多面板 ===== */
.cpanel {
    flex: 0 0 auto;
    display: none;
    background: #ececec;
    border-top: .5px solid #e2e2e2;
    padding: 22px 14px calc(24px + env(safe-area-inset-bottom, 0px));
}
.cpanel.show { display: block; }
.cpanel-attach { height: min(300px, 40vh); overflow-y: auto; }
.cpanel-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 26px 6px;
    justify-items: center;
}
.cpanel-item {
    border: none; background: none; padding: 0;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    color: #8c8c8c; font-size: 13px;
    -webkit-tap-highlight-color: transparent;
}
.cpanel-ico {
    width: 74px; height: 74px;
    border-radius: 18px;
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    color: #1a1a1a;
}
.cpanel-item:active .cpanel-ico { background: #f2f2f2; }

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 12px 4px;
    height: min(230px, 30vh);
    overflow-y: auto;
}
.emoji-grid button {
    border: none; background: none; padding: 0;
    font-size: 24px; line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
}

/* ===== 双栏（客服端） ===== */
#view-work { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.split { display: flex; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.split-side {
    width: 240px; flex: 0 0 auto;
    background: #fff; border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden;
    transition: width .18s ease;
}
.split-side-head {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    gap: 6px;
    padding: 9px 8px 9px 12px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    font-size: 13px; color: var(--text-sub);
    white-space: nowrap;
}
.side-toggle {
    flex: 0 0 auto;
    border: none; background: none;
    color: #666; font-size: 18px; line-height: 1;
    padding: 3px 6px;
    border-radius: 6px;
}
.side-toggle:active { background: #f0f0f0; }
#session-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.split.collapsed .split-side { width: 42px; }
.split.collapsed .side-title { display: none; }
.split.collapsed #session-list { display: none; }
.split.collapsed .split-side-head { justify-content: center; padding: 9px 0; }
.split-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.split-main #chat-panel { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.split-main .chat-wrap { flex: 1 1 auto; min-height: 0; }
.session-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.session-item.active { background: var(--green-light); }
.session-item b { display: block; font-size: 14px; }
.session-item .preview { font-size: 12px; color: var(--text-sub);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .unread {
    display: inline-block; min-width: 18px; height: 18px; line-height: 18px;
    background: #fa5151; color: #fff; border-radius: 9px;
    font-size: 11px; text-align: center; padding: 0 5px;
}

/* ===== 后台 ===== */
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--border); }
.tab {
    flex: 1; text-align: center; padding: 13px 0;
    font-size: 15px; color: var(--text-sub); cursor: pointer;
    border-bottom: 2px solid transparent;
}
.tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

.admin-body { padding: 16px; }
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 12px;
}
.switch { position: relative; width: 48px; height: 28px; }
.switch input { display: none; }
.switch .track {
    position: absolute; inset: 0; background: #d8d8d8; border-radius: 14px; transition: .2s;
}
.switch .track::after {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { left: 23px; }

table.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; }
.admin-table th, .admin-table td { padding: 12px 10px; font-size: 13px; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { background: #f7f7f7; color: var(--text-sub); font-weight: 600; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 12px; }
.tag-on { background: var(--green-light); color: var(--green); }
.tag-off { background: #f2f2f2; color: var(--text-sub); }

/* ===== 弹窗 ===== */
.modal-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-mask.show { display: flex; }
.modal {
    background: #fff; border-radius: 14px;
    width: 92%; max-width: 520px; max-height: 80vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { padding: 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-close { border: none; background: none; font-size: 20px; color: var(--text-sub); }

.empty { text-align: center; color: var(--text-sub); padding: 40px 16px; font-size: 13px; }

@media (max-width: 640px) {
    .split-side { width: 150px; }
    .admin-table th, .admin-table td { padding: 8px 6px; }
}
