/* Light by default, dark follows the system setting. Same palette as the first chat site. */
:root {
  color-scheme: light dark;
  --bg: #f4f5f7; --panel: #ffffff; --side: #f8f9fb; --text: #1c1e21; --muted: #6b7280;
  --line: #e3e5e8; --accent: #4f46e5; --accent-text: #ffffff; --mine: #e4e7ff;
  --bubble: #f1f2f4; --chip: #f3f4f6; --chip-on: #e0e7ff; --danger: #dc2626;
  --shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13; --panel: #1b1e25; --side: #15181e; --text: #e6e8ec; --muted: #8b93a1;
    --line: #2a2e38; --accent: #7c75ff; --accent-text: #0e0f14; --mine: #2d3158;
    --bubble: #252932; --chip: #2a2e38; --chip-on: #34385c; --danger: #f87171;
    --shadow: 0 6px 24px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 6px 0 0; }

/* ---------- buttons & inputs ---------- */
button { cursor: pointer; border: 1px solid var(--line); background: var(--chip); border-radius: 8px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: none; }
button.ghost.danger { color: var(--danger); }
button.small { padding: 4px 10px; font-size: 13px; }
button.link { border: 0; background: none; padding: 4px 0; color: var(--accent); }
button.icon { border: 0; background: none; font-size: 24px; line-height: 1; padding: 4px 10px; }
button:disabled { opacity: .5; cursor: default; }
input, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); resize: none;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row.end { justify-content: flex-end; }

/* ---------- layout ---------- */
.shell {
  display: flex; height: 100%; height: 100dvh; max-width: 1040px; margin: 0 auto;
  background: var(--panel); border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}
#sidebar { width: 280px; flex: none; display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; }
.side-head h2, .side-sub { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-sub { padding: 12px 16px 6px; border-top: 1px solid var(--line); }
.side-actions { padding: 0 12px 8px; }
.list { overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
#friendList { flex: 1 1 0; min-height: 60px; }
#reqList { max-height: 30vh; }
.room { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 8px; background: none; }
.room:hover { background: var(--chip); }
.room.active { background: var(--chip-on); }
.rname { flex: 1; min-width: 0; }
.fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.dm-empty { padding: 6px 10px; font-size: 14px; color: var(--muted); }
.dm-row { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; }
.side-foot { padding: 10px 16px; border-top: 1px solid var(--line); }
.status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.dot.on { background: #22c55e; }
.dot.err { background: #ef4444; }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
header { display: flex; align-items: center; gap: 6px; padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--line); }
header h1 { font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codebox { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.codebox span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.codebox input { width: 170px; padding: 5px 9px; font-size: 14px; }
.empty { margin: auto; text-align: center; padding: 24px; max-width: 320px; }
.empty p { margin: 6px 0; }

/* ---------- messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.msg { max-width: min(78%, 560px); padding: 7px 11px 5px; border-radius: 14px; background: var(--bubble); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .text.bad { color: var(--muted); font-style: italic; }
.msg .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 1px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; max-height: 140px; }

/* ---------- dialogs & toast ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(460px, calc(100% - 24px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg { padding: 20px; }
.dlg h3 { font-size: 18px; margin-bottom: 4px; }
.code { font: 14px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; overflow-wrap: anywhere; user-select: all; }
.code.small { font-size: 12px; }
.code.big { font-size: 20px; text-align: center; letter-spacing: .08em; padding: 14px; margin-top: 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); z-index: 10; max-width: calc(100% - 32px); }
