:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --bubble-in: #eceef1;
  --warn-bg: #fff4e5;
  --warn-border: #f0b45b;
  --error: #c62828;
  --ok: #2e9d57;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d22;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #2c3036;
    --accent: #4d86f7;
    --bubble-in: #262a31;
    --warn-bg: #3a2a12;
    --warn-border: #a8742a;
    --error: #ef6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 0.55em 1em;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.link { background: none; color: var(--accent); padding: 0.3em; }
input {
  font: inherit;
  padding: 0.55em 0.75em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.error { color: var(--error); min-height: 1.2em; }

.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: min(380px, 100%);
  display: grid;
  gap: 10px;
}
.card h1 { margin: 0; font-size: 1.4em; }
.stack { display: grid; gap: 10px; }
.stack[hidden] { display: none; }
#relay-form { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 6px; }
button.secondary { background: none; color: var(--accent); border: 1px solid var(--border); }

.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.me { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.peers { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.peers button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  color: var(--text);
  text-align: left;
}
.peers button:hover, .peers button.active { background: var(--bubble-in); }
.peers .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; font-size: 0.75em; padding: 0 7px; }
.tag { font-size: 0.75em; color: var(--muted); }
.tag.warn { color: var(--error); }
.sidebar > .link { margin: 10px; font-size: 0.8em; color: var(--muted); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.empty { margin: auto; padding: 16px; text-align: center; }
#conversation { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.chat-header strong { flex: 1; }
.back { display: none; }
.verify, .warning { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.verify code { display: block; font-size: 1.1em; letter-spacing: 0.04em; margin: 6px 0; word-spacing: 0.4em; }
.warning { background: var(--warn-bg); border-bottom-color: var(--warn-border); }
.warning p { margin: 0 0 8px; }

.messages { list-style: none; margin: 0; padding: 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.messages li { max-width: min(75%, 520px); padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.messages li.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.messages li.out { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.messages li.bad { align-self: flex-start; border: 1px dashed var(--error); color: var(--error); font-size: 0.85em; }
.messages time { display: block; font-size: 0.7em; opacity: 0.7; margin-top: 2px; }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--panel); }

@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: inline-block; }
}
