:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #1f2937;
  background: #f3f4f6;
  --header-height: 56px;
  --sidebar-width: 280px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100vh; min-height: 100dvh; background: #f3f4f6; }
button, input, select, textarea { font: inherit; }
button { min-height: 40px; border: 0; border-radius: 7px; padding: 8px 14px; background: #2563eb; color: white; cursor: pointer; touch-action: manipulation; }
button:hover { background: #1d4ed8; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.hidden { display: none !important; }
header {
  height: calc(var(--header-height) + var(--safe-top));
  min-height: calc(var(--header-height) + var(--safe-top));
  background: #ffffff;
  color: #1f2937;
  border-bottom: 1px solid #dbe3ef;
  box-shadow: 0 1px 4px #1e3a5f18;
  padding: var(--safe-top) max(16px, var(--safe-right)) 0 max(16px, var(--safe-left));
  display: flex;
  align-items: center;
  gap: 12px;
}
header b { font-size: 18px; white-space: nowrap; }
header span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: auto; color: #4b6480; }
header button { flex: 0 0 auto; }
#login { min-height: calc(100vh - var(--header-height)); min-height: calc(100dvh - var(--header-height)); display: grid; place-items: center; padding: 20px max(16px, var(--safe-right)) calc(20px + var(--safe-bottom)) max(16px, var(--safe-left)); }
.card { width: min(100%, 380px); margin: 0 auto; background: white; padding: 28px; border-radius: 12px; box-shadow: 0 8px 30px #0001; }
.card h1 { margin-top: 0; }
.card input, .card select, .composer textarea { width: 100%; padding: 11px; border: 1px solid #d1d5db; border-radius: 7px; margin: 7px 0; }
.card input, .card select { min-height: 44px; }
.card #loginBtn { width: 100%; margin-top: 6px; }
.error { color: #dc2626; min-height: 22px; }
#workspace { height: calc(100vh - var(--header-height) - var(--safe-top)); height: calc(100dvh - var(--header-height) - var(--safe-top)); min-height: 0; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); overflow: hidden; }
#workspace aside { min-width: 0; background: #fff; border-right: 1px solid #e5e7eb; padding: 12px; overflow: auto; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button { flex: 1 1 auto; min-height: 36px; padding: 6px 8px; font-size: 12px; white-space: nowrap; }
.tabs button[data-tab=settings] { background: #e5eefc; color: #24508d; }
#contactSearch { width: 100%; min-height: 40px; padding: 8px; border: 1px solid #d1d5db; border-radius: 7px; margin-bottom: 10px; }
#contacts { list-style: none; padding: 0; margin: 0; }
#contacts li { min-height: 44px; padding: 11px; border-radius: 7px; cursor: pointer; border-bottom: 1px solid #f3f4f6; overflow-wrap: anywhere; }
#contacts li:hover, #contacts li:focus { background: #eff6ff; }
#contacts small { display: block; color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #f9fafb; }
.empty { margin: auto; padding: 20px; color: #9ca3af; text-align: center; }
.chatHead { min-height: 56px; background: #fff; border-bottom: 1px solid #e5e7eb; padding: 8px max(12px, var(--safe-right)) 8px max(12px, var(--safe-left)); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chatHead > b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatHead > span { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.chatHead button { font-size: 12px; min-height: 36px; padding: 6px 9px; margin: 0; }
.chatHead button:nth-child(3) { background: #f59e0b; }
.chatHead button:nth-child(4) { background: #dc2626; }
.chatHead button:nth-child(5) { background: #dbeafe; color: #24508d; }
#messages { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 14px max(12px, var(--safe-right)) 14px max(12px, var(--safe-left)); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg { display: flex; flex-direction: column; align-items: flex-start; margin: 8px 0; }
.msg span { max-width: min(75%, 720px); background: white; padding: 9px 12px; border-radius: 10px; box-shadow: 0 1px 2px #0001; white-space: pre-wrap; word-break: break-word; }
.msg small { font-size: 10px; color: #9ca3af; margin-top: 3px; }
.msg.mine { align-items: flex-end; }
.msg.mine span { background: #dbeafe; }
.composer { padding: 10px max(12px, var(--safe-right)) calc(10px + var(--safe-bottom)) max(12px, var(--safe-left)); background: #fff; border-top: 1px solid #e5e7eb; display: flex; gap: 8px; align-items: center; }
.composer textarea { flex: 1 1 auto; min-width: 80px; min-height: 42px; margin: 0; resize: none; }
.composer input[type=file] { flex: 0 1 180px; min-width: 0; max-width: 180px; }
.composer #send { flex: 0 0 auto; }
.drawer { position: fixed; z-index: 4; right: var(--safe-right); top: calc(var(--header-height) + var(--safe-top)); width: min(360px, calc(100vw - 16px)); bottom: var(--safe-bottom); background: white; padding: 18px; box-shadow: -5px 0 20px #0002; overflow: auto; -webkit-overflow-scrolling: touch; }
.drawer pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.call { position: fixed; inset: 0; z-index: 5; padding: max(14px, var(--safe-top)) max(14px, var(--safe-right)) max(14px, var(--safe-bottom)) max(14px, var(--safe-left)); background: #f8fbffff; color: #1f2937; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.call video { width: auto; max-width: 90vw; max-height: 62vh; background: #e5edf7; border: 1px solid #cbd5e1; border-radius: 8px; object-fit: contain; }
.call #localVideo { position: absolute; right: max(16px, var(--safe-right)); bottom: calc(100px + var(--safe-bottom)); width: clamp(100px, 28vw, 180px); max-height: 28vh; }
.call > div:last-child { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; text-align: center; }
.call button { min-width: 76px; margin: 0; }
.muted { color: #718096; text-align: center; cursor: default !important; }
@media (max-width: 900px) {
  :root { --sidebar-width: 230px; }
  .chatHead { align-items: flex-start; }
  .chatHead > span { max-width: 60%; }
  .msg span { max-width: 86%; }
}
@media (max-width: 700px) {
  :root { --header-height: 52px; }
  header { padding-left: max(12px, var(--safe-left)); padding-right: max(12px, var(--safe-right)); }
  header b { font-size: 16px; }
  #workspace { grid-template-columns: minmax(92px, 31vw) minmax(0, 1fr); }
  #workspace aside { padding: 8px 6px; }
  .tabs { flex-direction: column; gap: 3px; margin-bottom: 8px; }
  .tabs button { min-height: 38px; font-size: 11px; padding: 5px 4px; }
  #contactSearch { min-height: 40px; padding: 7px 5px; }
  #contacts li { padding: 10px 6px; }
  .chatHead { min-height: 52px; padding: 6px 8px; }
  .chatHead > span { max-width: 72%; }
  .chatHead button { min-height: 34px; padding: 5px 7px; }
  .composer { flex-wrap: wrap; gap: 6px; }
  .composer textarea { flex-basis: calc(100% - 66px); font-size: 16px; }
  .composer #send { flex-basis: 58px; padding-left: 8px; padding-right: 8px; }
  .composer input[type=file] { flex: 1 1 100%; width: 100%; max-width: none; min-height: 38px; }
  .call video { max-width: 96vw; max-height: 56vh; }
  .call #localVideo { right: max(10px, var(--safe-right)); bottom: calc(118px + var(--safe-bottom)); width: 30vw; }
}
@media (max-width: 380px) {
  #workspace { grid-template-columns: 88px minmax(0, 1fr); }
  .chatHead > span { max-width: 68%; }
  .chatHead button { font-size: 11px; padding-left: 5px; padding-right: 5px; }
  .msg span { max-width: 94%; }
  .card { padding: 22px 16px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .card { padding: 16px 20px; }
  .card h1 { font-size: 20px; margin-bottom: 8px; }
  .card input, .card select { margin: 3px 0; min-height: 38px; }
  .call video { max-height: 48vh; }
  .call #localVideo { bottom: calc(72px + var(--safe-bottom)); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }

