:root {
  color: #1f2c30;
  background: #eef1ef;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #1f2c30;
  --muted: #647176;
  --line: #d7ddda;
  --surface: #ffffff;
  --surface-2: #f4f6f4;
  --teal: #187b6d;
  --teal-soft: #e9f5f1;
  --orange: #df642c;
  --danger: #bd453d;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { min-width: 320px; overflow: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.loading-screen { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 14px; background: #f4f6f4; }
.loading-screen img { width: 44px; height: 44px; object-fit: contain; }
.spinner { width: 18px; height: 18px; display: inline-block; border: 2px solid #bdc8c5; border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat-shell, .admin-shell { width: 100%; height: 100%; background: var(--surface); display: grid; grid-template-rows: 58px minmax(0, 1fr); }
.guest-shell { max-width: 920px; height: min(820px, calc(100% - 32px)); margin: 0 auto; position: relative; top: 16px; border: 1px solid #3b4446; border-radius: 6px; box-shadow: 0 18px 55px rgba(27, 35, 37, .18); overflow: hidden; }
.app-header { min-height: 58px; padding: 0 16px; background: #202729; color: #fff; display: flex; align-items: center; justify-content: space-between; }
.brand { min-width: 0; display: flex; align-items: center; gap: 10px; }
.brand img { width: 34px; height: 34px; flex: 0 0 34px; object-fit: contain; }
.brand span, .login-brand span { min-width: 0; display: grid; gap: 2px; }
.brand strong { font-size: 16px; }
.brand small { color: #d3ddda; font-size: 12px; }
.connection-state { display: flex; align-items: center; gap: 7px; color: #d3ddda; font-size: 12px; white-space: nowrap; }
.connection-state i { width: 8px; height: 8px; border-radius: 50%; background: #d6923d; }
.connection-state.connected i { background: #55b889; }
.connection-state.offline i { background: #d85b51; }

.conversation { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.messages { min-height: 0; padding: 18px; overflow-y: auto; background: #f5f7f5; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.message { width: fit-content; max-width: min(82%, 620px); padding: 10px 12px; align-self: flex-start; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.message.own { align-self: flex-end; border-color: #b6d8d0; background: var(--teal-soft); }
.message-meta { margin-bottom: 5px; display: flex; align-items: center; gap: 8px; color: #526064; font-size: 12px; font-weight: 600; }
.message-meta strong { color: var(--ink); font-size: 13px; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.65; }
.history-state { min-height: 24px; display: flex; align-items: center; justify-content: center; }
.history-state .spinner { width: 15px; height: 15px; }
.empty-state { min-height: 140px; margin: auto; color: var(--muted); display: flex; align-items: center; justify-content: center; font-size: 13px; }

.composer { padding: 10px 12px; border-top: 1px solid var(--line); background: #fff; display: grid; gap: 8px; }
.composer textarea { width: 100%; min-height: 74px; max-height: 180px; padding: 10px 11px; resize: vertical; border: 1px solid #bfc9c6; border-radius: 4px; outline: 0; color: var(--ink); font-size: 15px; line-height: 1.55; }
.composer textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(24, 123, 109, .12); }
.composer > div { min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.button { min-height: 34px; padding: 0 14px; border: 1px solid transparent; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.button.primary { min-width: 78px; background: var(--orange); border-color: #c65120; color: #fff; }
.button.primary:hover { background: #c95421; }
.button:disabled { opacity: .55; cursor: wait; }
.button.quiet { background: transparent; border-color: #667174; color: inherit; }
.button.quiet:hover { background: rgba(255,255,255,.09); }
.form-error { min-height: 18px; color: var(--danger); font-size: 12px; }

.login-shell { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; background: #edf0ee; }
.login-panel { width: min(390px, 100%); padding: 26px; border: 1px solid #b8c1be; border-radius: 6px; background: #fff; box-shadow: 0 16px 48px rgba(27, 35, 37, .16); display: grid; gap: 16px; }
.login-brand { margin-bottom: 4px; display: flex; align-items: center; gap: 12px; }
.login-brand img { width: 45px; height: 45px; object-fit: contain; }
.login-brand strong { font-size: 19px; }
.login-brand small { color: var(--muted); font-size: 12px; }
.login-panel label { display: grid; gap: 6px; }
.login-panel label span { color: #3d494d; font-size: 13px; font-weight: 700; }
.login-panel input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #bfc9c6; border-radius: 4px; outline: 0; }
.login-panel input:focus { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(24, 123, 109, .12); }
.login-panel .form-error { margin: -4px 0; }
.button.wide { width: 100%; min-height: 42px; }
.setup-panel { width: min(430px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.setup-qr { width: 196px; height: 196px; margin: 0 auto; padding: 8px; border: 1px solid var(--line); background: #fff; }
.setup-qr svg { width: 100%; height: 100%; display: block; }
.secret-output { min-height: 38px; padding: 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-2); overflow-wrap: anywhere; font: 600 13px/1.45 ui-monospace, Consolas, monospace; user-select: all; }

.admin-header { padding-right: 12px; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.admin-layout { min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.thread-pane { min-height: 0; border-right: 1px solid var(--line); background: var(--surface-2); overflow: hidden; display: grid; grid-template-rows: 52px minmax(0,1fr); }
.thread-toolbar { padding: 0 10px 0 14px; border-bottom: 1px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: space-between; }
.thread-toolbar strong { font-size: 13px; }
.icon-button { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: inherit; display: inline-flex; align-items: center; justify-content: center; font-size: 23px; line-height: 1; }
.icon-button:hover { background: rgba(37, 58, 57, .08); }
.thread-list { min-height: 0; overflow-y: auto; }
.thread-item { width: 100%; min-height: 72px; padding: 9px 10px; position: relative; border: 0; border-bottom: 1px solid var(--line); background: transparent; display: grid; grid-template-columns: 38px minmax(0,1fr) auto; align-items: center; gap: 9px; text-align: left; }
.thread-item:hover, .thread-item.active { background: #e5f0ec; }
.thread-item.active { box-shadow: inset 3px 0 var(--teal); }
.guest-avatar { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 5px; background: #294d51; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; }
.thread-copy { min-width: 0; display: grid; gap: 4px; }
.thread-copy strong, .thread-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-copy strong { font-size: 14px; }
.thread-copy small { color: var(--muted); font-size: 12px; }
.thread-side { align-self: stretch; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; color: var(--muted); font-size: 10px; }
.unread-badge { min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--danger); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; }
.admin-conversation { grid-template-rows: 52px minmax(0,1fr) auto; }
.conversation-header { min-width: 0; padding: 0 12px 0 14px; border-bottom: 1px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.conversation-header > div { min-width: 0; display: flex; align-items: center; gap: 9px; }
.conversation-header > div > span:last-child { min-width: 0; display: grid; gap: 2px; }
.conversation-header strong, .conversation-header small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-header strong { font-size: 14px; }
.conversation-header small { color: var(--muted); font-size: 11px; }
.conversation-header .button.quiet { border-color: var(--line); color: var(--muted); }
.conversation-header .button.quiet:hover { background: var(--surface-2); color: var(--danger); }
.mobile-back { display: none; }

.toast { position: fixed; z-index: 20; right: 18px; bottom: 18px; max-width: 360px; padding: 11px 14px; border: 1px solid #333c3f; border-radius: 5px; background: #202729; color: #fff; box-shadow: 0 10px 32px rgba(0,0,0,.22); font-size: 13px; }

@media (max-width: 680px) {
  .guest-shell { width: 100%; max-width: none; height: 100%; margin: 0; top: 0; border: 0; border-radius: 0; box-shadow: none; }
  .app-header { padding: 0 12px; }
  .brand strong { font-size: 15px; }
  .messages { padding: 10px; }
  .message { max-width: 92%; }
  .admin-layout { position: relative; display: block; overflow: hidden; }
  .thread-pane, .admin-conversation { position: absolute; inset: 0; }
  .thread-pane { border-right: 0; transition: transform .18s ease; }
  .admin-conversation { background: #fff; transform: translateX(100%); transition: transform .18s ease; }
  .admin-shell.viewing-thread .thread-pane { transform: translateX(-24%); }
  .admin-shell.viewing-thread .admin-conversation { transform: translateX(0); }
  .mobile-back { display: inline-flex; flex: 0 0 32px; }
  .conversation-header { padding-left: 6px; }
  .connection-state span { display: none; }
  .header-actions { gap: 8px; }
  .admin-header .button { min-width: 50px; padding: 0 9px; }
}
