/* websend — 灰度、直角、深浅色自适应 */

:root {
  --bg: #f2f2f2;
  --surface: #ffffff;
  --surface-2: #ebebeb;
  --surface-3: #dedede;
  --text: #111111;
  --muted: #656565;
  --faint: #9a9a9a;
  --border: #d8d8d8;
  --ink: #111111;
  --ink-contrast: #ffffff;
  --ink-hover: #000000;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 14px 34px -24px rgba(0, 0, 0, 0.45);
  --overlay: rgba(255, 255, 255, 0.88);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0a0a0a;
  --surface: #121212;
  --surface-2: #1b1b1b;
  --surface-3: #2a2a2a;
  --text: #eeeeee;
  --muted: #a0a0a0;
  --faint: #6c6c6c;
  --border: #292929;
  --ink: #eeeeee;
  --ink-contrast: #0a0a0a;
  --ink-hover: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 20px 44px -26px rgba(0, 0, 0, 0.95);
  --overlay: rgba(0, 0, 0, 0.86);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

::selection {
  background: var(--text);
  color: var(--bg);
}

#app {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  min-height: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 0;
}

button:disabled {
  cursor: not-allowed;
}

svg {
  display: block;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* ---------- 加入房间 ---------- */

.join {
  display: grid;
  place-items: center;
  padding: 32px 18px calc(32px + env(safe-area-inset-bottom));
}

.join-card {
  width: min(420px, 100%);
  padding: clamp(24px, 5vw, 36px);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: center;
}

.mark {
  width: 50px;
  height: 50px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  color: var(--ink-contrast);
  background: var(--ink);
}

.mark svg {
  width: 28px;
  height: 28px;
}

.join-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.tagline {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 13.5px;
}

.field {
  position: relative;
  margin-bottom: 10px;
}

.field input {
  width: 100%;
  height: 46px;
  padding: 0 62px 0 14px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 0;
  transition: border-color 0.15s, background 0.15s;
}

.field input::placeholder {
  color: var(--faint);
}

.field input:focus {
  outline: none;
  border-color: var(--text);
  background: var(--surface);
}

.reveal {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  padding: 6px 8px;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
}

.reveal:hover {
  color: var(--text);
  background: var(--surface-3);
}

.primary-btn {
  width: 100%;
  height: 46px;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-contrast);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 0;
  transition: background 0.15s, transform 0.06s;
}

.primary-btn:hover:not(:disabled) {
  background: var(--ink-hover);
  border-color: var(--ink-hover);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-btn:disabled {
  opacity: 0.5;
}

.join-error {
  margin: 14px 0 0;
  padding: 8px 11px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--text);
  font-size: 13px;
}

.join-note {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 12px;
  text-align: left;
}

/* ---------- 房间主界面 ---------- */

.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  padding: 10px clamp(12px, 3vw, 20px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--ink-contrast);
  background: var(--ink);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-name {
  font-weight: 650;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.chip svg {
  width: 14px;
  height: 14px;
  opacity: 0.85;
}

.chip.conn {
  background: transparent;
  border: 1px solid var(--border);
}

.chip .dot {
  width: 6px;
  height: 6px;
  background: var(--muted);
  flex: 0 0 auto;
}

.chip.conn[data-state="open"] .dot {
  background: var(--text);
}

.chip.conn[data-state="connecting"] .dot,
.chip.conn[data-state="down"] .dot {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  transition: background 0.14s, color 0.14s;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.icon-btn:disabled {
  opacity: 0.4;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.theme-btn svg {
  display: none;
}

.theme-btn[data-mode="system"] .i-system,
.theme-btn[data-mode="light"] .i-light,
.theme-btn[data-mode="dark"] .i-dark {
  display: block;
}

/* ---------- 消息区 ---------- */

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 20px clamp(12px, 3vw, 24px) 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.messages::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border: 3px solid var(--bg);
}

.messages > .msg,
.messages > .empty {
  width: 100%;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 5px 0;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.msg.mine {
  flex-direction: row-reverse;
}

.avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  user-select: none;
}

.msg.mine .avatar {
  color: var(--text);
  border-color: var(--text);
}

.msg .body {
  min-width: 0;
  max-width: min(76%, 620px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.msg.mine .body {
  align-items: flex-end;
}

.meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 0 2px;
  font-size: 11.5px;
  color: var(--faint);
}

.meta .who {
  color: var(--muted);
  font-weight: 550;
}

.msg.mine .meta {
  flex-direction: row-reverse;
}

.bubble {
  max-width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: none;
}

.msg.mine .bubble {
  color: var(--ink-contrast);
  background: var(--ink);
  border-color: var(--ink);
}

.bubble .text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 14.5px;
}

/* 文件气泡 */

.bubble.file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: min(268px, 62vw);
}

.file-icon {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}

.msg.mine .file-icon {
  color: inherit;
  border-color: rgba(255, 255, 255, 0.4);
}

.file-icon svg {
  width: 17px;
  height: 17px;
}

.file-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-name {
  font-size: 13.5px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.msg.mine .file-sub {
  color: rgba(255, 255, 255, 0.72);
}

.file-status::before {
  content: "·";
  margin-right: 6px;
}

.bubble.file.is-failed .file-status {
  text-decoration: underline;
}

.bubble.file.is-stale {
  opacity: 0.7;
}

.bubble.file.is-stale .file-icon {
  color: var(--faint);
}

.bar {
  height: 2px;
  margin-top: 5px;
  background: var(--surface-3);
  overflow: hidden;
}

.msg.mine .bar {
  background: rgba(255, 255, 255, 0.3);
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--text);
  transition: width 0.12s linear;
}

.msg.mine .bar > i {
  background: var(--ink-contrast);
}

.file-action {
  flex: 0 0 auto;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 550;
  color: inherit;
  text-decoration: none;
  background: transparent;
  border: 1px solid currentColor;
  transition: background 0.14s;
}

.file-action:hover {
  background: var(--surface-2);
}

.msg.mine .file-action:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* 空状态 */

.empty {
  margin: auto;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 50px;
  height: 50px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  color: var(--faint);
  background: transparent;
  border: 1px solid var(--border);
}

.empty-icon svg {
  width: 24px;
  height: 24px;
}

.empty h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.empty p {
  margin: 0;
  font-size: 13px;
}

/* ---------- 输入区 ---------- */

.composer {
  flex: 0 0 auto;
  padding: 10px clamp(12px, 3vw, 24px) calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

.composer .icon-btn {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  background: var(--surface-2);
}

.composer .icon-btn:hover:not(:disabled) {
  background: var(--surface-3);
}

#input {
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 168px;
  padding: 10px 13px;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 0;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.15s, background 0.15s;
}

#input::placeholder {
  color: var(--faint);
}

#input:focus {
  outline: none;
  border-color: var(--text);
  background: var(--surface);
}

#input:disabled {
  opacity: 0.6;
}

.send-btn {
  flex: 0 0 auto;
  height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-contrast);
  background: var(--ink);
  border: 1px solid var(--ink);
  transition: background 0.15s, opacity 0.15s;
}

.send-btn svg {
  width: 16px;
  height: 16px;
}

.send-btn:hover:not(:disabled) {
  background: var(--ink-hover);
  border-color: var(--ink-hover);
}

.send-btn:disabled {
  opacity: 0.4;
}

.hint {
  width: 100%;
  max-width: 860px;
  margin: 0 auto 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  border-left: 2px solid var(--text);
}

.jump-btn {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: rise 0.16s ease-out;
}

/* ---------- 拖拽覆盖层 ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 14px;
  background: var(--overlay);
}

.drop-box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text);
  background: transparent;
  border: 2px dashed var(--text);
  font-size: 17px;
  font-weight: 600;
}

.drop-box svg {
  width: 40px;
  height: 40px;
}

.drop-box p {
  margin: 0;
}

/* ---------- 提示 ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(460px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: 8px 13px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast.is-error {
  border-color: var(--text);
  font-weight: 600;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 响应式 ---------- */

@media (max-width: 640px) {
  body {
    font-size: 14.5px;
  }

  .msg .body {
    max-width: 84%;
  }

  .chip {
    padding: 0 8px;
    font-size: 12px;
  }

  .brand-name {
    display: none;
  }

  .send-btn {
    padding: 0 12px;
  }

  .send-btn span {
    display: none;
  }

  .send-btn svg {
    width: 18px;
    height: 18px;
  }

  .join-note {
    font-size: 11.5px;
  }
}

@media (max-width: 380px) {
  .chip.conn #conn-text {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
