/* websend — 极简、响应式、深浅色自适应 */

:root {
  --bg: #eef1f6;
  --bg-glow: rgba(37, 99, 235, 0.10);
  --surface: #ffffff;
  --surface-2: #e8ecf3;
  --surface-3: #dde3ec;
  --text: #15181e;
  --muted: #667085;
  --faint: #98a2b3;
  --border: #dde2ea;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-weak: rgba(37, 99, 235, 0.10);
  --mine: #2563eb;
  --mine-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 10px 30px -12px rgba(16, 24, 40, 0.28);
  --radius-lg: 18px;
  --radius: 13px;
  --radius-sm: 9px;
  --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: #0c0f14;
  --bg-glow: rgba(79, 131, 255, 0.14);
  --surface: #161a22;
  --surface-2: #1e232d;
  --surface-3: #282f3c;
  --text: #e7eaf0;
  --muted: #98a2b3;
  --faint: #6b7686;
  --border: #262d3a;
  --accent: #4f83ff;
  --accent-hover: #6a96ff;
  --accent-weak: rgba(79, 131, 255, 0.16);
  --mine: #3f6ff0;
  --mine-text: #ffffff;
  --danger: #f87171;
  --ok: #4ade80;
  --warn: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 14px 40px -16px rgba(0, 0, 0, 0.85);
}

*,
*::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;
}

#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;
}

button:disabled {
  cursor: not-allowed;
}

svg {
  display: block;
}

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

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

.join {
  display: grid;
  place-items: center;
  padding: 32px 18px calc(32px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1100px 540px at 50% -12%, var(--bg-glow), transparent 68%),
    var(--bg);
}

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

.mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(150deg, var(--accent), #7c3aed);
  border-radius: 15px;
  box-shadow: 0 8px 22px -10px var(--accent);
}

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

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

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

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

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

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

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

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

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

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

.primary-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

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

.join-error {
  margin: 14px 0 0;
  padding: 9px 12px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

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

.join-note code {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
}

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

.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: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(150deg, var(--accent), #7c3aed);
  border-radius: 9px;
}

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

.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 10px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  white-space: nowrap;
}

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

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

.chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: 0 0 auto;
}

.chip.conn[data-state="open"] .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent);
}

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

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

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  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: 4px;
  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);
  border-radius: 999px;
}

.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(4px); }
  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: var(--surface-2);
  border-radius: 50%;
  user-select: none;
}

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

.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 3px;
  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: 9px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 5px;
  box-shadow: var(--shadow-sm);
}

.msg.mine .bubble {
  color: var(--mine-text);
  background: var(--mine);
  border-color: transparent;
  border-radius: 14px 14px 5px 14px;
}

.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: 11px;
  min-width: min(268px, 62vw);
}

.file-icon {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-weak);
  border-radius: 10px;
}

.msg.mine .file-icon {
  color: var(--mine-text);
  background: rgba(255, 255, 255, 0.18);
}

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

.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.78);
}

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

.bubble.file.is-failed .file-status {
  color: var(--danger);
}

.msg.mine .bubble.file.is-failed .file-status {
  color: #ffd7d7;
}

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

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

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

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

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

.msg.mine .bar > i {
  background: #fff;
}

.file-action {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--accent);
  text-decoration: none;
  background: var(--accent-weak);
  border-radius: 8px;
  transition: background 0.14s;
}

.file-action:hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.msg.mine .file-action {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
}

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

/* 空状态 */

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

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

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

.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(10px + 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;
  margin-bottom: 0;
  background: var(--surface-2);
  border-radius: 12px;
}

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

#input {
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 168px;
  padding: 10px 14px;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  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(--accent);
  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 15px 0 17px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  transition: background 0.15s, opacity 0.15s;
}

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

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.hint {
  width: 100%;
  max-width: 860px;
  margin: 0 auto 8px;
  padding: 7px 11px;
  font-size: 12.5px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-radius: var(--radius-sm);
}

.kbd-hint {
  width: 100%;
  max-width: 860px;
  margin: 8px auto 0;
  font-size: 11.5px;
  color: var(--faint);
  text-align: center;
}

.kbd-hint kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
}

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

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

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 14px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(3px);
}

.drop-box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  border: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 24px;
  font-size: 17px;
  font-weight: 600;
}

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

.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: 9px 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.18s ease-out;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast.is-error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

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

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

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

  .kbd-hint {
    display: none;
  }

  .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;
  }
}
