:root {
  --bg: #111b21;
  --panel: #202c33;
  --panel-2: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #25d366;
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen[hidden] { display: none; }

.login-body {
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--panel);
  padding: 32px 24px;
  border-radius: 16px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card input, .login-card button {
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
}
.login-card input { background: var(--panel-2); color: var(--text); }
.login-card button { background: var(--accent); color: #062015; font-weight: 600; }
.error { color: #ff6b6b; text-align: center; margin: 0; font-size: 14px; }

.setup-card {
  margin: auto;
  text-align: center;
  padding: 24px;
  max-width: 320px;
}
.setup-card img { width: 220px; height: 220px; margin: 16px auto; border-radius: 8px; background: white; padding: 8px; }
.setup-card button {
  background: var(--accent); color: #062015; border: none;
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 15px;
}

.top-bar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.top-bar h1 { font-size: 19px; margin: 0; flex: 1; }
.icon-btn {
  background: transparent; border: none; color: var(--text);
  font-size: 22px; padding: 4px 8px; cursor: pointer;
}

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.chat-item .avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
  flex-shrink: 0; overflow: hidden;
}
.chat-item .avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .name { font-weight: 500; }
.chat-item .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.bubble {
  max-width: 78%; padding: 8px 12px; border-radius: 12px; font-size: 15px; line-height: 1.35;
  word-wrap: break-word; white-space: pre-wrap;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }

.bubble-media-img, .bubble-media-video { max-width: 100%; border-radius: 8px; display: block; }
.bubble-media-file {
  display: block; color: var(--text); text-decoration: underline;
  padding: 4px 0;
}
.bubble-caption { margin-top: 6px; }

.send-bar {
  display: flex; gap: 8px; padding: 10px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: var(--panel);
}
.send-bar input {
  flex: 1; border: none; border-radius: 20px; padding: 10px 16px;
  background: var(--panel-2); color: var(--text); font-size: 16px;
}
.send-bar button {
  background: var(--accent); color: #062015; border: none;
  border-radius: 20px; padding: 0 18px; font-weight: 600;
}
