* { box-sizing: border-box; }
:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  color: #111;
  background: #fff;
}
body { margin: 0; background: #fff; min-height: 100vh; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: #777; font-size: 14px; }

.screen { min-height: 100vh; }
#authView {
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(#fff, #f7f7f7);
}
.brand { font-size: 34px; font-weight: 800; letter-spacing: -1.5px; margin-bottom: 22px; }
.brand.small { font-size: 24px; margin: 0; }

.card {
  width: min(430px, 100%);
  border: 1px solid #e4e4e4;
  border-radius: 24px;
  padding: 28px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0,0,0,.06);
}
.auth-card h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.8px; }
.auth-card p { margin: 0 0 24px; }

.field { margin: 14px 0; }
.field label { display:block; margin-bottom: 7px; font-size: 13px; font-weight: 650; }
.field input, .search-row input {
  width: 100%;
  border: 1px solid #d9d9d9;
  border-radius: 14px;
  padding: 14px 15px;
  outline: none;
  background: #fff;
}
.field input:focus, .search-row input:focus, textarea:focus { border-color: #111; }

.primary, .send {
  border: 0;
  background: #111;
  color: #fff;
}
.primary {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  margin-top: 8px;
  font-weight: 700;
}
.link-button, .ghost {
  border: 0;
  background: transparent;
}
.link-button { width:100%; padding: 16px 0 2px; color:#111; text-decoration: underline; }
.message { min-height: 20px; margin-top: 12px; font-size: 14px; }
.config-note {
  width: min(430px, 100%);
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 14px;
  background: #f2f2f2;
  font-size: 13px;
}
.config-note span { display:block; margin-top: 5px; color:#666; }

.topbar {
  height: 76px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 0 22px;
  border-bottom: 1px solid #e8e8e8;
}
.ghost { padding: 10px 14px; border-radius: 12px; }
.ghost:hover { background:#f2f2f2; }

.messenger {
  height: calc(100vh - 76px);
  display:grid;
  grid-template-columns: 330px 1fr;
}
.sidebar { border-right:1px solid #e8e8e8; padding:16px; overflow:auto; }
.search-row { margin-bottom: 12px; }
.section-title { font-size: 12px; color:#888; text-transform:uppercase; letter-spacing: .08em; margin: 18px 4px 8px; }
.results, .chat-list { display:flex; flex-direction:column; gap:6px; }
.user-result, .chat-item {
  padding: 12px;
  border-radius: 14px;
  border: 0;
  background: #fff;
  text-align:left;
}
.user-result:hover, .chat-item:hover, .chat-item.active { background:#f1f1f1; }
.user-result strong, .chat-item strong { display:block; }
.user-result span, .chat-item span { color:#777; font-size:12px; }

.conversation { min-width:0; display:flex; }
.empty {
  margin:auto;
  text-align:center;
  max-width:360px;
  padding:24px;
}
.empty-icon { font-size:48px; }
.empty h2 { margin:14px 0 8px; }
.active-conversation { width:100%; display:flex; flex-direction:column; min-height:0; }
.conversation-header { padding:16px 22px; border-bottom:1px solid #eee; }
.messages {
  flex:1;
  overflow:auto;
  padding:22px;
  display:flex;
  flex-direction:column;
  gap:9px;
  background:#fafafa;
}
.bubble {
  max-width:min(70%, 600px);
  padding:10px 13px;
  border-radius:17px;
  line-height:1.35;
  white-space:pre-wrap;
  word-break:break-word;
}
.bubble.mine { align-self:flex-end; background:#111; color:#fff; border-bottom-right-radius:5px; }
.bubble.theirs { align-self:flex-start; background:#fff; border:1px solid #e4e4e4; border-bottom-left-radius:5px; }
.time { display:block; font-size:10px; opacity:.6; margin-top:4px; }
.composer {
  display:flex;
  gap:9px;
  padding:12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top:1px solid #eee;
  background:#fff;
}
.composer textarea {
  flex:1;
  resize:none;
  max-height:120px;
  border:1px solid #ddd;
  border-radius:18px;
  padding:12px 14px;
  outline:none;
}
.send { width:46px; height:46px; border-radius:50%; font-size:20px; }

.toast {
  position:fixed; left:50%; bottom:24px; transform:translateX(-50%);
  background:#111; color:#fff; padding:11px 15px; border-radius:12px;
  opacity:0; pointer-events:none; transition:.2s; max-width:90%;
}
.toast.show { opacity:1; }

@media (max-width: 720px) {
  #authView { padding: 18px; }
  .card { padding: 22px; border-radius:20px; }
  .messenger { grid-template-columns: 1fr; height: calc(100vh - 76px); }
  .sidebar { height: 42vh; border-right:0; border-bottom:1px solid #e8e8e8; }
  .conversation { height:58vh; }
  .topbar { padding:0 15px; }
  .bubble { max-width:84%; }
}
