/* Hush — minimal messenger UI */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --text-dim: #70768a;
  --border: #e3e6ec;
  --accent: #4c6fff;
  --accent-text: #ffffff;
  --bubble-them: #eaecf2;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(20, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #16181d;
    --surface-2: #1e2128;
    --text: #e8eaf0;
    --text-dim: #8a90a3;
    --border: #262a33;
    --accent: #5b7bff;
    --bubble-them: #23262e;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, background .15s;
}
input:focus, textarea:focus { border-color: var(--accent); background: var(--surface); }

/* ---------------- auth ---------------- */
#auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
}
.wordmark {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -.03em;
  text-align: center;
}
.wordmark .dot { color: var(--accent); }
.tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 4px 0 26px;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tabs button {
  padding: 8px 0;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.auth-tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

#auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.field input { width: 100%; }
.at-input { position: relative; }
.at-input i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--text-dim); }
.at-input input { padding-left: 28px; }

.note { font-size: 12.5px; color: var(--text-dim); }
.error { font-size: 13px; color: var(--danger); min-height: 1em; }
.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 10px;
  padding: 11px;
  font-weight: 600;
  transition: filter .15s;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .6; cursor: default; }

/* ---------------- layout ---------------- */
#app-view { display: flex; height: 100dvh; }

#sidebar {
  width: 320px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
}
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me-name {
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.me-name:hover { background: var(--surface-2); }
#me-name-input { width: 150px; padding: 5px 8px; }

.avatar {
  width: 38px; height: 38px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #8b5bff);
  text-transform: uppercase;
  user-select: none;
}

.icon-btn {
  width: 36px; height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.add-bar { display: flex; gap: 8px; padding: 4px 14px 8px; }
.add-bar input { flex: 1; min-width: 0; }
.side-error { padding: 0 16px 4px; }
.side-note { padding: 24px 16px; text-align: center; line-height: 1.6; }

#convo-list { list-style: none; overflow-y: auto; flex: 1; padding: 4px 8px 12px; }
#convo-list li {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .12s;
}
#convo-list li:hover { background: var(--surface-2); }
#convo-list li.active { background: var(--surface-2); }
.convo-main { flex: 1; min-width: 0; }
.convo-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.convo-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-time { font-size: 11.5px; color: var(--text-dim); flex: none; }
.convo-preview {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.unread-dot {
  width: 9px; height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------------- chat ---------------- */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chat-empty {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--text-dim);
  gap: 12px;
}
.big-lock { font-size: 52px; }

#chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-head .avatar { width: 34px; height: 34px; font-size: 14px; }
.chat-title { flex: 1; min-width: 0; }
#chat-name { font-weight: 600; }
.chat-sub { font-size: 11.5px; color: var(--text-dim); }
.back { display: none; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.day-sep {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 12px;
  margin: 12px 0 8px;
}
.msg {
  max-width: min(72%, 560px);
  padding: 8px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  position: relative;
  animation: pop .14s ease-out;
}
@keyframes pop { from { transform: translateY(4px); opacity: 0; } }
.msg.mine {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 5px;
}
.msg.theirs {
  align-self: flex-start;
  background: var(--bubble-them);
  border-bottom-left-radius: 5px;
}
.msg .t {
  display: inline-block;
  font-size: 10.5px;
  opacity: .65;
  margin-left: 8px;
  vertical-align: bottom;
  user-select: none;
}
.msg.undecryptable { font-style: italic; opacity: .6; }

/* composer */
#composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#emoji-btn { font-size: 19px; }
#msg-input {
  flex: 1;
  resize: none;
  max-height: 130px;
  border-radius: 18px;
  padding: 9px 14px;
}
.send { color: var(--accent); }
.send:hover { background: var(--surface-2); color: var(--accent); }

/* emoji picker */
#emoji-pop {
  position: absolute;
  bottom: 68px;
  left: 12px;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 2px;
  width: min(340px, calc(100vw - 24px));
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 20;
}
#emoji-pop button {
  font-size: 21px;
  padding: 4px;
  border-radius: 8px;
  line-height: 1.3;
}
#emoji-pop button:hover { background: var(--surface-2); }
#chat-pane { position: relative; }

/* ---------------- modal ---------------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 18, .55);
  z-index: 50;
  padding: 20px;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-card h3 { font-size: 17px; }
#verify-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14px;
  text-align: center;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 14px;
  letter-spacing: .04em;
}

/* ---------------- mobile ---------------- */
@media (max-width: 720px) {
  #sidebar { width: 100%; border-right: 0; }
  #app-view.chat-open #sidebar { display: none; }
  #app-view:not(.chat-open) #chat { display: none; }
  .back { display: grid; }
  .msg { max-width: 84%; }
}

/* scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }
