:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --mine: #3b82f6;
  --theirs: #334155;
  --accent: #38bdf8;
}
* { 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; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.screen { height: 100dvh; display: flex; flex-direction: column; }

/* Login */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 88px; height: 88px; border-radius: 22px; }
.login-card h1 { margin: 12px 0 24px; font-weight: 700; }
.login-card input, .login-card button {
  width: 100%; padding: 14px; margin-bottom: 12px; border-radius: 12px; border: 1px solid #334155;
  background: var(--panel); color: var(--text); font-size: 17px; }
.login-card button { background: var(--mine); border: none; font-weight: 600; }
.error { color: #f87171; min-height: 1.2em; }

/* Header */
header { display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid #0b1222; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #38bdf8, #6366f1);
  display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.who { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 17px; }
.status { font-size: 12px; color: var(--muted); }
.icon-btn { background: none; border: none; color: var(--text); font-size: 26px; padding: 4px 8px; }

.banner { background: #1d4ed8; color: white; padding: 10px 14px; font-size: 14px; }
.banner button { margin-left: 8px; background: white; color: #1d4ed8; border: none; border-radius: 8px; padding: 4px 10px; font-weight: 600; }

/* Messages */
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 4px;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.day { align-self: center; color: var(--muted); font-size: 12px; margin: 12px 0 6px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 18px; line-height: 1.35; font-size: 16px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; position: relative; }
.msg.mine { align-self: flex-end; background: var(--mine); color: white; border-bottom-right-radius: 6px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 6px; }
.msg.pending { opacity: .6; }
.msg.failed { background: #b91c1c; }
.msg .time { display: block; font-size: 11px; opacity: .7; margin-top: 2px; text-align: right; }
.msg a { color: inherit; }
.load-older { align-self: center; background: var(--panel); color: var(--muted); border: none; border-radius: 12px; padding: 6px 12px; margin-bottom: 8px; }
.typing { color: var(--muted); font-size: 13px; padding: 0 16px 4px; }

/* Composer */
#composer { display: flex; gap: 8px; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); align-items: flex-end; }
#input { flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px; border: 1px solid #334155;
  background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit; }
#sendBtn { width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--mine); color: white; font-size: 18px; flex-shrink: 0; }

/* Menu */
.menu { position: fixed; inset: auto 0 0 0; background: var(--panel); padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.menu button { padding: 14px; border-radius: 12px; border: none; background: var(--bg); color: var(--text); font-size: 16px; text-align: left; }
.menu #closeMenu { text-align: center; color: var(--muted); }

/* ---- Multi-user screens ---- */
.title { flex: 1; margin: 0; font-size: 20px; font-weight: 700; }
.back { font-size: 34px; line-height: 1; padding: 0 8px 4px 0; }
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.padded { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.contact { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #1e293b; cursor: pointer; }
.contact:active { background: #1e293b; }
.contact .avatar { width: 48px; height: 48px; font-size: 20px; flex-shrink: 0; }
.contact .info { flex: 1; min-width: 0; }
.contact .top { display: flex; justify-content: space-between; gap: 8px; }
.contact .cname { font-weight: 600; }
.contact .when { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.contact .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact.unread .preview { color: var(--text); font-weight: 600; }
.pill { background: var(--mine); color: white; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 2px 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.row-btn { padding: 14px; border-radius: 12px; border: none; background: var(--panel); color: var(--text); font-size: 16px; text-align: left; }
.row-btn.danger { color: #f87171; }
.card { background: var(--panel); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.card h3 { margin: 0 0 4px; }
.card input:not([type=checkbox]), .modal-card input {
  padding: 12px; border-radius: 10px; border: 1px solid #334155; background: var(--bg); color: var(--text); font-size: 16px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
button.primary { padding: 12px; border-radius: 10px; border: none; background: var(--mine); color: white; font-weight: 600; font-size: 16px; }
.user-row { background: var(--panel); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-row .head { display: flex; align-items: center; gap: 10px; }
.user-row .avatar { width: 36px; height: 36px; font-size: 15px; }
.user-row .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-row .actions button { background: var(--bg); color: var(--text); border: none; border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.user-row .actions button.danger { color: #f87171; }
.tag { font-size: 11px; background: #334155; border-radius: 6px; padding: 2px 6px; color: var(--muted); margin-left: 6px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--panel); border-radius: 16px; padding: 18px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.modal-card h3 { margin: 0; }
#modalFields { display: flex; flex-direction: column; gap: 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button { padding: 10px 16px; border-radius: 10px; border: none; font-size: 15px; background: var(--bg); color: var(--text); }
.modal-actions button.primary { background: var(--mine); color: white; }
#userList { display: flex; flex-direction: column; gap: 10px; }
