:root {
  --bg: #efeae2; --panel: #ffffff; --topbar: #f0f2f5; --text: #111b21; --muted: #667781;
  --in-bubble: #ffffff; --out-bubble: #d9fdd3; --accent: #00a884; --border: #e9edef;
  --shadow: 0 1px 1px rgba(11,20,26,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a; --panel: #111b21; --topbar: #202c33; --text: #e9edef; --muted: #8696a0;
    --in-bubble: #202c33; --out-bubble: #005c4b; --accent: #00a884; --border: #2a3942;
    --shadow: 0 1px 1px rgba(0,0,0,.2);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.screen { height: 100dvh; display: flex; flex-direction: column; }

/* — Login — */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px 24px; width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 34px; }
.brand h1 { font-size: 22px; margin: 0; }
.sub { color: var(--muted); font-size: 14px; margin: 8px 0 20px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
input {
  font-size: 16px; padding: 13px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
button { cursor: pointer; border: none; font-size: 16px; }
#login-btn {
  background: var(--accent); color: #fff; padding: 13px; border-radius: 10px; font-weight: 600;
}
#login-btn:disabled { opacity: .6; cursor: default; }
.error { color: #e5484d; font-size: 14px; margin: 12px 0 0; }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

/* — Chat — */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--topbar); padding: 10px 14px; border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}
.peer { display: flex; align-items: center; gap: 10px; }
.avatar { font-size: 26px; background: var(--panel); border-radius: 50%; padding: 4px 6px; }
.peer-meta { display: flex; flex-direction: column; line-height: 1.2; }
.peer-meta small { color: var(--muted); font-size: 12px; }
.icon-btn { background: transparent; color: var(--muted); font-size: 20px; padding: 6px 10px; border-radius: 8px; }
.topbar-actions { display: flex; gap: 2px; }
.icon-btn.on { color: var(--accent); }

.bubble img { max-width: 100%; border-radius: 8px; margin-bottom: 4px; display: block; }
.bubble strong { font-weight: 700; }
.bubble ul { margin: 4px 0; padding-left: 18px; }
.bubble li { margin: 2px 0; }
.bubble table { border-collapse: collapse; margin: 6px 0; font-size: 13px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; white-space: nowrap; }
.bubble th { background: rgba(127,127,127,.15); font-weight: 700; }
.bubble > span:first-child > div:empty { display: none; }
.photo-preview { position: relative; padding: 8px 12px; background: var(--topbar); border-top: 1px solid var(--border); }
.photo-preview img { max-height: 80px; border-radius: 8px; }
.photo-remove { position: absolute; top: 4px; left: 76px; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; }
.composer .attach { font-size: 20px; }

.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.bubble {
  max-width: 78%; padding: 8px 11px; border-radius: 10px; font-size: 15px; line-height: 1.4;
  box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word;
}
.bubble.in  { background: var(--in-bubble); align-self: flex-start; border-top-left-radius: 3px; }
.bubble.out { background: var(--out-bubble); align-self: flex-end; border-top-right-radius: 3px; }
.bubble .time { display: block; font-size: 10px; color: var(--muted); text-align: right; margin-top: 3px; }
.typing { color: var(--muted); font-size: 13px; align-self: flex-start; padding: 6px 4px; }

.composer {
  display: flex; gap: 8px; padding: 10px 12px; background: var(--topbar);
  border-top: 1px solid var(--border);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.composer input { flex: 1; border-radius: 22px; }
.send-btn {
  background: var(--accent); color: #fff; width: 46px; border-radius: 50%; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
