:root {
  color-scheme: dark;
  --bg: #120a0d;
  --surface: #1c1216;
  --surface-2: #251720;
  --text: #f1e7ea;
  --text-dim: #9c8890;
  --accent: #7a2c40;
  --accent-dim: #5c2130;
  --danger: #ff5c5c;
  --logged: #ffb020;
  font-family: Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

.app {
  /* --app-height is kept in sync with window.visualViewport in app.js —
     more reliable than 100dvh alone for keeping the compose bar above the
     on-screen keyboard (and Chrome's autofill accessory bar) on Android. */
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
}

.screen { height: 100%; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }

/* Login */
.login-form {
  margin: auto;
  width: min(320px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-form h1 {
  text-align: center;
  font-weight: 600;
  margin-bottom: 8px;
}
.login-form input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
.login-form button {
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
}
.error { color: var(--danger); font-size: 14px; text-align: center; }

/* Chat */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 10px 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
}
.chat-header-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}
#chat-title {
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ghost-btn, .attach-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ghost-btn:active, .attach-btn:active { background: var(--surface-2); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
}
.msg-wrap.mine { align-items: flex-end; }

.msg {
  max-width: min(78vw, 480px);
  padding: 7px 10px;
  border-radius: 16px;
  background: var(--surface);
  font-size: 15px;
  line-height: 1.35;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: pan-y;
}
.msg-wrap.mine .msg {
  background: var(--accent);
  border-bottom-right-radius: 4px;
  margin-left: 20px; /* room for the inner-side badge */
}
.msg-wrap:not(.mine) .msg {
  border-bottom-left-radius: 4px;
  margin-right: 20px;
}

.msg-body { white-space: pre-wrap; word-break: break-word; }

.msg .meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}
.msg-wrap.mine .msg .meta { color: rgba(255,255,255,0.75); }

.reply-quote {
  border-left: 3px solid rgba(255,255,255,0.35);
  padding: 2px 8px;
  margin-bottom: 4px;
  font-size: 13px;
  opacity: 0.8;
  border-radius: 4px;
  background: rgba(0,0,0,0.15);
}
.reply-quote-sender {
  display: block;
  font-weight: 600;
  font-size: 11px;
}

.msg-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 4px;
  object-fit: cover;
}

/* Logged/not-logged indicator: transparent, no background plate, vertically
   centered on the side of the bubble that faces the center of the
   conversation column (not the screen edge). */
.lock-badge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  opacity: 0.55;
}
.msg-wrap.mine .lock-badge { left: -20px; }
.msg-wrap:not(.mine) .lock-badge { right: -20px; }
.lock-badge.locked {
  color: var(--logged);
  opacity: 0.9;
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.reaction-chip {
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  font-size: 12px;
  padding: 1px 6px;
  cursor: pointer;
}
.reaction-chip.mine {
  border-color: var(--accent);
  background: rgba(122, 44, 64, 0.3);
}

/* Reply / edit context bar above the compose bar */
.notify-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--accent-dim);
  font-size: 13px;
}
.notify-banner[hidden] { display: none; }
.notify-banner-actions { display: flex; gap: 6px; flex-shrink: 0; }
.notify-banner-actions button {
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
#notify-dismiss { background: none; color: var(--text-dim); }
#notify-enable { background: var(--accent); color: white; font-weight: 600; }

.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  font-size: 13px;
}
.reply-preview[hidden] { display: none; }
.reply-preview-body { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview-label {
  color: var(--accent);
  font-weight: 600;
  margin-right: 6px;
}
#reply-preview-cancel {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.compose-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
}
.log-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text-dim);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.log-toggle .icon-locked { display: none; }
.log-toggle[aria-pressed="true"] {
  background: var(--logged);
  color: #1a1200;
  border-color: var(--logged);
}
.log-toggle[aria-pressed="true"] .icon-unlocked { display: none; }
.log-toggle[aria-pressed="true"] .icon-locked { display: block; }
#compose-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  min-width: 0;
}
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.send-btn svg { margin-left: 2px; }

/* Message action sheet + profile modal */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* The sheet renders right under the finger that long-pressed the message —
     without this, the browser's native long-press-to-select-text grabs
     whatever text (e.g. the emoji glyphs) ends up under the touch point. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.sheet-reactions {
  display: flex;
  justify-content: space-between;
  padding: 6px 4px 14px;
}
.sheet-emoji {
  background: none;
  border: none;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.sheet-action {
  width: 100%;
  text-align: left;
  padding: 12px 10px;
  border-radius: 10px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.sheet-action:active { background: var(--surface-2); }
.sheet-cancel { color: var(--text-dim); text-align: center; margin-top: 4px; }
.sheet-primary { color: var(--accent); font-weight: 600; }

.profile-sheet h2 {
  margin: 0 0 10px;
  font-size: 17px;
}
.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.avatar-choice {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--surface-2);
  font-size: 20px;
  cursor: pointer;
}
.avatar-choice.selected { border-color: var(--accent); }
#display-name-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 12px;
}
.profile-actions {
  display: flex;
  gap: 8px;
}
.profile-actions .sheet-action { text-align: center; }

/* Call consent */
.call-consent-sheet h2 { margin: 0 0 8px; font-size: 17px; }
.call-consent-text {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.4;
  margin: 0 0 10px;
}
.call-consent-status {
  color: var(--logged);
  font-size: 13px;
  min-height: 18px;
  margin: 0 0 6px;
}

/* In-call screen */
.call-screen {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.call-screen[hidden] { display: none; }
.call-video-grid {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#call-remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--surface);
}
#call-local-video {
  position: absolute;
  bottom: max(96px, calc(96px + env(safe-area-inset-bottom)));
  right: 16px;
  width: 96px;
  height: 128px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.2);
}
.call-status-bar {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  text-align: center;
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.call-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.4);
}
.call-control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
/* aria-pressed = muted/off, not "active" — style it as a warning state */
.call-control-btn[aria-pressed="true"] {
  background: var(--danger);
  color: white;
}
.call-leave-btn {
  background: #d13a3a;
  color: white;
}
