:root {
  --brand: #356df3;
  --brand-dark: #2457d4;
  --brand-pale: #eaf0ff;
  --ink: #172033;
  --muted: #75809a;
  --line: #e8ebf2;
  --surface: #ffffff;
  --canvas: #f3f5f9;
  --success: #20b486;
  --shadow: 0 18px 50px rgba(30, 47, 86, .15);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.visitor-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 16% 12%, rgba(103, 140, 255, .20), transparent 30%),
    radial-gradient(circle at 86% 88%, rgba(76, 216, 184, .16), transparent 30%),
    #f4f6fb;
}

.chat-shell {
  width: min(100%, 780px);
  height: min(820px, calc(100vh - 48px));
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: var(--surface);
  border: 1px solid rgba(221, 226, 239, .85);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 19px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.95);
}

.brand-mark {
  width: 43px;
  height: 43px;
  border-radius: 13px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 20px;
  background: linear-gradient(145deg, #5684fb, #285edb);
  box-shadow: 0 7px 16px rgba(53,109,243,.27);
}

.brand-mark.large { width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 17px; }
.brand-copy { min-width: 0; }
.brand-copy h1, .staff-brand h1 { margin: 0; font-size: 17px; }
.brand-copy p, .staff-brand p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.online-dot { display: inline-block; width: 7px; height: 7px; margin-right: 3px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(32,180,134,.12); }
.visitor-account { margin-left: auto; color: #66728d; font-size: 12px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; white-space: nowrap; }

.message-list { overflow-y: auto; padding: 26px 24px 12px; background: linear-gradient(#fbfcfe, #f8faff); scroll-behavior: smooth; }
.welcome-card { margin: 0 auto 28px; text-align: center; color: var(--muted); font-size: 13px; }
.welcome-card strong { display: block; margin: 8px 0 6px; color: #48536c; font-size: 14px; }
.welcome-card p { margin: 0; }
.welcome-icon { font-size: 25px; }

.message-row { display: flex; gap: 9px; align-items: flex-end; margin: 11px 0; }
.message-row.mine { flex-direction: row-reverse; }
.message-avatar, .visitor-avatar { width: 34px; height: 34px; border-radius: 11px; flex: 0 0 auto; display: grid; place-items: center; color: #fff; background: #9baccb; font-size: 12px; font-weight: 700; }
.message-row.mine .message-avatar { background: var(--brand); }
.message-content { max-width: min(74%, 540px); }
.message-bubble { padding: 11px 14px; border-radius: 16px 16px 16px 5px; background: #fff; border: 1px solid var(--line); box-shadow: 0 3px 12px rgba(31,48,80,.05); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 14px; }
.message-row.mine .message-bubble { color: white; background: var(--brand); border-color: var(--brand); border-radius: 16px 16px 5px 16px; }
.message-time { margin-top: 5px; color: #a0a8b9; font-size: 10px; }
.message-row.mine .message-time { text-align: right; }
.day-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: #a2aabc; font-size: 11px; }
.day-divider::before, .day-divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 14px 18px 8px; border-top: 1px solid var(--line); background: white; }
.composer textarea { width: 100%; max-height: 120px; resize: none; padding: 11px 13px; border: 1px solid #dde2ec; border-radius: 13px; outline: none; color: var(--ink); background: #f9fafc; line-height: 1.45; transition: .18s; }
.composer textarea:focus { background: #fff; border-color: #94aff8; box-shadow: 0 0 0 3px rgba(53,109,243,.10); }
.composer textarea::placeholder { color: #a2a9b8; }
.send-button { width: 43px; height: 43px; border: 0; border-radius: 13px; display: grid; place-items: center; color: #fff; background: var(--brand); transition: transform .15s, background .15s; }
.send-button:hover { background: var(--brand-dark); transform: translateY(-1px); }
.send-button:disabled { opacity: .5; cursor: default; transform: none; }
.send-button svg { width: 20px; fill: currentColor; }
.composer-note { padding: 0 20px 10px; text-align: center; color: #a2a9b8; font-size: 10px; background: #fff; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 30; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; padding: 10px 15px; border-radius: 10px; color: #fff; background: rgba(23,32,51,.92); font-size: 13px; transition: .22s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 接待端 */
.staff-page { min-height: 100vh; background: #edf0f5; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 20%, #e1e9ff, #f4f6fa 46%); }
.login-card { width: min(100%, 390px); padding: 36px; border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; text-align: center; font-size: 22px; }
.login-card > p { margin: 9px 0 26px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.login-card input { width: 100%; padding: 12px 13px; border: 1px solid #dce1eb; border-radius: 11px; outline: none; }
.login-card input:focus { border-color: #94aff8; box-shadow: 0 0 0 3px rgba(53,109,243,.1); }
.primary-button { width: 100%; margin-top: 15px; padding: 12px; border: 0; border-radius: 11px; color: #fff; background: var(--brand); font-weight: 700; }
.form-error { min-height: 18px; margin-top: 10px; color: #e24c4c; text-align: center; font-size: 12px; }

.staff-shell { height: 100vh; display: grid; grid-template-columns: 350px 1fr; background: #fff; }
.conversation-panel { min-width: 0; display: grid; grid-template-rows: auto auto 1fr; border-right: 1px solid var(--line); background: #fff; }
.staff-brand { min-height: 78px; display: flex; align-items: center; gap: 12px; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.staff-brand > div:nth-child(2) { min-width: 0; flex: 1; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: #fff; }
.list-toolbar { display: flex; align-items: center; padding: 18px 18px 9px; font-size: 14px; }
.count-chip { margin-left: 7px; padding: 2px 7px; border-radius: 10px; color: var(--brand); background: var(--brand-pale); font-size: 11px; }
.conversation-list { padding: 4px 9px 14px; overflow-y: auto; }
.no-conversations { padding: 60px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 13px 10px; border: 0; border-radius: 13px; text-align: left; background: transparent; }
.conversation-item:hover { background: #f6f8fc; }
.conversation-item.active { background: var(--brand-pale); }
.conversation-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: var(--brand); background: #e6edff; font-weight: 700; }
.conversation-copy { min-width: 0; }
.conversation-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; }
.conversation-preview { margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.conversation-side { text-align: right; align-self: stretch; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; }
.conversation-time { color: #a2a9b8; font-size: 10px; }
.unread-badge { min-width: 19px; height: 19px; padding: 0 5px; display: grid; place-items: center; border-radius: 10px; color: #fff; background: var(--brand); font-size: 10px; }
.closed-dot { width: 6px; height: 6px; border-radius: 50%; background: #aab1c0; }

.staff-chat-panel { min-width: 0; background: #f8f9fc; }
.empty-conversation { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.empty-conversation h2 { margin: 13px 0 5px; color: #59657e; font-size: 18px; }
.empty-conversation p { margin: 0; font-size: 13px; }
.empty-icon { width: 68px; height: 68px; display: grid; place-items: center; border-radius: 22px; background: #e9edf5; font-size: 28px; }
.active-conversation { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.active-header { min-height: 78px; display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: #fff; }
.active-info { min-width: 0; flex: 1; }
.active-info h2 { margin: 0; font-size: 15px; }
.active-info p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.status-button { padding: 8px 12px; border: 1px solid #dce1ec; border-radius: 9px; color: #69748b; background: #fff; font-size: 12px; }
.status-button.reopen { color: var(--success); border-color: rgba(32,180,134,.35); }
.staff-messages { padding-left: max(24px, 8vw); padding-right: max(24px, 8vw); }
.staff-composer { padding: 15px max(20px, 7vw) 18px; }
.back-button { display: none; border: 0; background: transparent; font-size: 32px; color: var(--muted); }

@media (max-width: 720px) {
  .visitor-page { padding: 0; }
  .chat-shell { height: 100vh; min-height: 0; border: 0; border-radius: 0; }
  .chat-header { padding: 14px 15px; }
  .visitor-account { max-width: 116px; overflow: hidden; text-overflow: ellipsis; }
  .message-list { padding: 20px 14px 10px; }
  .message-content { max-width: 82%; }
  .composer { padding: 11px 12px 7px; }

  .staff-shell { grid-template-columns: 1fr; }
  .staff-chat-panel { display: none; }
  .staff-shell.chat-open .conversation-panel { display: none; }
  .staff-shell.chat-open .staff-chat-panel { display: block; }
  .back-button { display: block; }
  .active-header { padding: 11px 12px; }
  .status-button { padding: 7px 9px; }
  .staff-messages { padding: 18px 13px 10px; }
  .staff-composer { padding: 11px 12px 14px; }
}

.settings-link{margin-left:auto;font-size:13px;color:var(--brand);text-decoration:none}.welcome-card .welcome-image{display:block;max-width:min(100%,320px);max-height:360px;object-fit:contain;margin:16px auto;border-radius:12px}.welcome-card strong{white-space:pre-wrap;line-height:1.8}

/* Allow grid message panes to shrink with the software keyboard. */
.message-list,.staff-chat-panel,.active-conversation{min-height:0;min-width:0}
.chat-shell{grid-template-rows:auto minmax(0,1fr) auto auto}
.active-conversation{grid-template-rows:auto minmax(0,1fr) auto}
@media(max-width:720px){
 html,body{height:100%;overflow:hidden;overscroll-behavior-y:none}
 .visitor-page,.staff-page{min-height:0}
 .chat-shell,.staff-shell{position:fixed;left:0;right:0;top:var(--chat-top,0px);height:var(--chat-height,100dvh);min-height:0;width:100%;margin:0}
 .message-list{scroll-behavior:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
 .composer textarea{font-size:16px;max-height:96px}
 .composer-note{padding-bottom:max(6px,env(safe-area-inset-bottom))}
 .staff-composer{padding-bottom:max(12px,env(safe-area-inset-bottom))}
}

.sound-toggle{border:1px solid #dce2ef;border-radius:8px;background:#f6f9ff;color:#356df3;padding:7px 9px;font-size:11px;white-space:nowrap;margin-left:8px}.chat-header{flex-wrap:wrap}@media(max-width:720px){.chat-header .sound-toggle{margin-left:auto}.chat-header .visitor-account{font-size:10px;padding:5px}.chat-header{gap:8px}}

/* Chat alignment: avatar tracks the bubble top, not timestamp baseline. */
.message-row{align-items:flex-start;margin:9px 0;gap:10px}
.message-avatar{margin-top:2px}
.message-content{min-width:0}
.message-time{line-height:1.3;margin-top:4px}
.staff-messages{padding-left:28px;padding-right:28px}
.message-bubble.image-bubble{padding:5px;border-radius:12px;line-height:0;background:#fff;border-color:var(--line);box-shadow:0 2px 8px #1f30500a}
.message-row.mine .message-bubble.image-bubble{padding:5px;background:#fff;border-color:#dce5fa;border-radius:12px}
.image-bubble .chat-photo{border-radius:8px}
@media(max-width:720px){.staff-messages{padding-left:14px;padding-right:14px}.message-row{gap:8px;margin:8px 0}}

.conversation-avatar{position:relative}.avatar-unread-dot{position:absolute;right:-3px;top:-3px;width:11px;height:11px;border:2px solid white;border-radius:50%;background:#f04452;box-shadow:0 0 0 1px #f0445210}.unread-badge{background:#f04452;color:#fff;font-weight:700}
