/* Encrypted Chat PWA — neutral WhatsApp-style, mobile-first (spec §8) */
:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel2: #202c33;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
  --danger: #ea5455;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
img, canvas { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------- auth ---------- */
#screen-auth { align-items: center; justify-content: center; }
.auth-box { width: min(92vw, 380px); display: flex; flex-direction: column; gap: 14px; }
.logo { text-align: center; font-weight: 300; letter-spacing: 4px; color: var(--accent); margin-bottom: 8px; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
input, textarea {
  background: var(--panel2);
  border: 1px solid #2a3942;
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  width: 100%;
  resize: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.btn {
  background: var(--panel2);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #06100d; font-weight: 600; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn:active { filter: brightness(1.15); }
#auth-choice { display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--muted); font-size: 13.5px; }
.form-err { color: var(--danger); font-size: 13px; min-height: 1em; }
.passphrase-display {
  background: var(--panel2);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 17px;
  text-align: center;
  letter-spacing: 1px;
  user-select: text;
  -webkit-user-select: text;
}
.busy { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 18px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--panel2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  min-height: 56px;
}
.topbar h2 { font-size: 17px; font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 20px; padding: 8px 10px; cursor: pointer; border-radius: 50%;
}
.icon-btn:active { background: rgba(255,255,255,0.08); }
.icon-btn.send { color: var(--accent); font-size: 22px; }

/* ---------- chip ---------- */
.chip {
  margin: 8px 14px 0;
  padding: 7px 12px;
  background: var(--panel2);
  color: var(--muted);
  font-size: 13px;
  border-radius: 999px;
  width: fit-content;
}

/* ---------- chat list ---------- */
#chat-list { flex: 1; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
.chat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(134,150,160,0.08);
}
.chat-row:active { background: var(--panel); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--muted); flex-shrink: 0;
}
.chat-row .meta { flex: 1; min-width: 0; }
.chat-row .name { font-weight: 500; }
.chat-row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--accent); color: #06100d;
  font-size: 12px; font-weight: 700;
  border-radius: 999px; min-width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
}
.cat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px solid rgba(134,150,160,0.08);
  font-size: 14px;
}
.cat-header .chev { transition: transform 0.15s; }
.cat-header.open .chev { transform: rotate(90deg); }
.cat-unlock { padding: 10px 14px; background: var(--panel); display: flex; gap: 8px; }
.cat-unlock input { flex: 1; }
.cat-empty { padding: 10px 14px 16px; color: var(--muted); font-size: 13px; background: var(--panel); }

/* ---------- conversation ---------- */
#messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.bubble {
  max-width: 78%;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 14.5px;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble .time { display: inline-block; margin-left: 8px; font-size: 11px; color: rgba(233,237,239,0.55); vertical-align: bottom; }
.bubble .ticks { font-size: 11px; margin-left: 3px; color: rgba(233,237,239,0.55); }
.bubble .ticks.read { color: #53bdeb; }
.bubble.deleted { font-style: italic; color: var(--muted); }
.bubble canvas { max-width: 100%; border-radius: 6px; display: block; }
.day-sep { align-self: center; background: var(--panel2); color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 8px 0; }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel2);
}
.composer textarea { flex: 1; max-height: 110px; }

/* ---------- modal ---------- */
#modal-root {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 20px;
  width: min(92vw, 420px);
  max-height: 86vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.modal h3 { font-size: 17px; font-weight: 500; }
.modal .row { display: flex; gap: 8px; align-items: center; }
.modal .row > * { flex: 1; }
.modal .list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid rgba(134,150,160,0.12);
  gap: 8px;
}
.modal .list-item .btn { padding: 6px 12px; font-size: 13px; }
.fingerprint { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-spacing: 2px; line-height: 1.8; background: var(--panel2); padding: 12px; border-radius: 8px; text-align: center; }
.qr-holder { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 8px; }
.qr-holder img { image-rendering: pixelated; width: 240px; height: 240px; }
#qr-video { width: 100%; border-radius: 8px; background: #000; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--muted); padding: 1px 6px; border-radius: 4px; }
.link-box { background: var(--panel2); padding: 10px; border-radius: 8px; font-size: 13px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.muted { color: var(--muted); font-size: 13px; }
