:root {
  --bg: #0f121c;
  --surface: #181c2a;
  --surface-2: #20253a;
  --text: #e8eaf2;
  --muted: #8b91a8;
  --accent: #5e78c8;
  --bubble-me: #3a5bd0;
  --bubble-them: #20253a;
  --online: #4caf72;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

.view { display: flex; flex-direction: column; height: 100dvh; }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid #000;
  position: sticky; top: 0; z-index: 2;
}
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: 2px; flex: 1; }
.ghost {
  background: none; border: none; color: var(--text);
  font-size: 22px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.ghost:active { background: var(--surface-2); }

/* contacts */
#contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.contact {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; cursor: pointer; border-bottom: 1px solid #00000055;
}
.contact:active { background: var(--surface); }
.avatar {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  font-size: 26px; border-radius: 50%;
  background: var(--surface-2);
}
.contact-main { flex: 1; min-width: 0; }
.contact-main strong { display: block; }
.contact-main small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--online); }

.thread-title { display: flex; flex-direction: column; line-height: 1.2; }
.thread-title small { color: var(--muted); font-size: 12px; }

/* messages */
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--bubble-me); border-bottom-right-radius: 5px; }
.msg.agent { align-self: flex-start; background: var(--bubble-them); border-bottom-left-radius: 5px; }
.msg.status { align-self: center; background: none; color: var(--muted); font-size: 13px; font-style: italic; }

#composer {
  display: flex; gap: 8px; padding: 10px 12px calc(var(--safe-bottom) + 10px);
  background: var(--surface); border-top: 1px solid #000;
}
#input {
  flex: 1; background: var(--surface-2); border: none; color: var(--text);
  padding: 11px 15px; border-radius: 20px; font-size: 16px; outline: none;
}
#composer button {
  background: var(--accent); border: none; color: #fff; font-size: 18px;
  width: 44px; border-radius: 50%; cursor: pointer;
}

/* login overlay */
#login-view {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card { text-align: center; padding: 32px; max-width: 320px; }
.login-logo { font-size: 56px; margin-bottom: 8px; }
.login-card h1 { letter-spacing: 3px; margin: 4px 0; }
.login-card p { color: var(--muted); margin: 4px 0 24px; }
#gsi-button { display: flex; justify-content: center; }
#login-error { color: #e07a7a; display: block; margin-top: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px); transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 6px 24px #0008; z-index: 5; max-width: 90%;
}
