:root {
  color-scheme: light;
  --ink: #192639;
  --muted: #596a7d;
  --line: #dfe6ef;
  --brand: #244fbd;
  --blue: #eaf0ff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(#e8eff9, #f7f9fc 440px);
  color: var(--ink);
  font: 14px/1.55 system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
}
header {
  background: #101d32;
  color: white;
  padding: 14px 16px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, calc((100% - 1120px)/2)) 14px;
  font-size: 16px;
  font-weight: 700;
}
main { max-width: 1152px; margin: 24px auto; padding: 0 16px; }
h1, h2, p { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 15px; }
small, .muted { color: var(--muted); }
button, input { font: inherit; }
button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  padding: 8px 13px;
  font-weight: 600;
  white-space: nowrap;
}
button:hover { background: #1a3b91; }
button:disabled { cursor: default; opacity: .55; }
button.alt { background: white; color: var(--ink); border-color: var(--line); }
button.alt:hover { background: #eef3fa; }
:focus-visible { outline: 2px solid #4974dd; outline-offset: 2px; }
input {
  width: 100%;
  border: 1px solid #d0dae7;
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
}
label { display: block; margin: 12px 0; font-weight: 600; }
label input { display: block; margin-top: 4px; }
.top, .chat-head, .chat-tools, .send-row, #note {
  display: flex;
  align-items: center;
  gap: 8px;
}
.top { justify-content: space-between; margin-bottom: 12px; }
.card {
  padding: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 0;
}
.staff-chat { padding: 0; overflow: hidden; }
.staff-chat .chat-head h1 { min-width: 0; font-size: 16px; }
.staff-list .customer-search { margin-top: 0; }
.client { max-width: 680px; margin: 0 auto; }
.client.auth { max-width: 410px; margin-top: 6vh; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); }
#title { background: transparent; color: var(--ink); white-space: normal; text-align: left; overflow-wrap: anywhere; }
#title:not(:disabled):hover { background: var(--blue); }
#title:not(:disabled)::after { content: " ✎"; color: var(--muted); }
#note { align-items: end; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
#note label { margin: 0; flex: 1; min-width: 130px; }
.list { display: grid; gap: 6px; max-height: 55vh; overflow: auto; }
.person { display: flex; align-items: center; gap: 9px; text-align: left; background: white; color: var(--ink); }
.person:hover, .person.active { background: var(--blue); }
.meta { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.avatar, .pill { border-radius: 7px; background: var(--blue); color: var(--brand); padding: 2px 7px; }
.pill { font-size: 11px; }
.thread {
  height: 55vh;
  height: clamp(220px, 55vh, 620px);
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: #f1f5fa;
}
.client .thread { border: 1px solid var(--line); border-radius: 8px; }
.bubble {
  max-width: 88%;
  align-self: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 7px 10px;
  overflow-wrap: anywhere;
}
.bubble.self { align-self: flex-end; background: var(--blue); }
.bubble small { display: block; font-size: 11px; }
.bubble img { display: block; max-width: 100%; max-height: 270px; object-fit: contain; border-radius: 6px; }
.message-text { white-space: pre-wrap; }
.compose { display: grid; gap: 8px; padding: 10px 16px; }
.client .compose { padding: 10px 0 0; }
.chat-tools { flex-wrap: wrap; }
.chat-tools button, .emoji-grid button { padding: 5px 9px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(36px,1fr)); gap: 5px; }
.send-row input { flex: 1; min-width: 0; }
.file-name { overflow-wrap: anywhere; }
.notice { color: var(--brand); margin-top: 8px; }
.notice:empty { display: none; }
.error { color: #a52b43; }
@media (max-width: 590px) {
  main { margin: 10px auto; padding: 0 10px; padding: 0 10px max(10px, env(safe-area-inset-bottom)); }
  .staff-list .list { max-height: 75vh; }
  input { font-size: 16px; }
  .send-row button, .send-row input { min-height: 44px; }
  .customer-chat .thread, .staff-chat .thread { height: 55vh; height: clamp(165px, calc(100dvh - 220px), 700px); }
}

@supports not (gap: 8px) {
  .top > * + *, .chat-tools > * + *, .send-row > * + *, #note > * + * { margin-left: 8px; }
  .thread > * + * { margin-top: 9px; }
}

.header-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.staff-chat #chat-sound { margin-left: auto; }

.archive-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.archive-tabs button[aria-pressed="true"] { background: var(--blue); color: var(--brand); }
.staff-chat .chat-head { flex-wrap: wrap; }
.staff-chat .header-actions { margin-left: auto; }

.customer-heading { min-width: 0; }
.customer-name, .customer-phone { display: block; overflow: hidden; text-overflow: ellipsis; }
.customer-phone { color: var(--muted); font-size: 13px; font-weight: 400; }
.customer-heading .customer-phone { padding-left: 13px; }
