/* Ugo — styles.css
   Design intent: near-black console, one accent (signal violet), zero
   webfont downloads (every KB matters on 2G), zero backdrop-filter/blur
   (expensive to composite on a Mali/PowerVR GPU like the M02's), and a
   single signature detail — the presence dot — that carries the app's
   whole promise: "is the other person here right now."
   System fonts only. No box-shadow blur radii above 8px. No transitions
   longer than 160ms. All of this is deliberate for the Galaxy M02. */

:root {
  --bg: #0b0c10;
  --bg-raised: #14161c;
  --bg-input: #1b1e26;
  --border: #262a35;
  --text: #e8e9ed;
  --text-dim: #8b8f9c;
  --text-faint: #565a66;
  --accent: #7c6fee;
  --accent-dim: #4b4394;
  --online: #35d999;
  --danger: #ef5b5b;
  --bubble-me: #2a2560;
  --bubble-them: #1b1e26;

  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  /* Prevent accidental text selection / long-press callouts everywhere;
     re-enabled explicitly on message text with .selectable */
  -webkit-touch-callout: none;
}

button, input {
  font-family: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------------- Auth screen ---------------- */

#auth-screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 28px;
}

.wordmark {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.wordmark span { color: var(--accent); }

.auth-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 15px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  outline: none;
}
.auth-card input:focus { border-color: var(--accent); }

.auth-card button {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
.auth-card button:active { background: var(--accent-dim); }
.auth-card button:disabled { opacity: 0.5; }

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

.auth-hint {
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  max-width: 300px;
}

/* ---------------- Chat screen ---------------- */

#chat-screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.presence-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.presence-dot.online {
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(53, 217, 153, 0.18);
}

.header-info { flex: 1; min-width: 0; }
.header-name { font-weight: 600; font-size: 15px; }
.header-status { font-size: 12px; color: var(--text-dim); }

.header-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.icon-btn:active { background: var(--bg-input); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------------- Message list ---------------- */

#message-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* momentum scroll on iOS-style webviews / Android webview */
  -webkit-overflow-scrolling: touch;
  contain: content; /* cheap layout containment for long lists */
}

.day-divider {
  align-self: center;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-raised);
  padding: 3px 10px;
  border-radius: 20px;
  margin: 8px 0;
}

.bubble-row { display: flex; }
.bubble-row.me { justify-content: flex-end; }
.bubble-row.them { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14.5px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble-row.me .bubble {
  background: var(--bubble-me);
  border-bottom-right-radius: 4px;
}
.bubble-row.them .bubble {
  background: var(--bubble-them);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.selectable { user-select: text; -webkit-touch-callout: default; }

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--text-faint);
}
.bubble-row.me .bubble-meta { justify-content: flex-end; }

.tick { font-size: 12px; }
.tick.sent { color: var(--text-faint); }
.tick.delivered, .tick.read { color: var(--accent); }

/* media bubbles */
.bubble-media {
  max-width: 220px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: block;
}
.bubble-media img, .bubble-media video {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}

.view-once-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-width: 140px;
}
.view-once-card .vo-icon { color: var(--accent); flex-shrink: 0; }
.view-once-card.opened { opacity: 0.5; }

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-width: 180px;
}
.file-card .file-icon {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.file-meta { min-width: 0; }
.file-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11px; color: var(--text-dim); }
.progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 120ms linear;
}

/* ---------------- Composer ---------------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 110px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14.5px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }

.composer .icon-btn { flex-shrink: 0; }
.composer .send-btn {
  background: var(--accent);
  color: #fff;
}
.composer .send-btn:active { background: var(--accent-dim); }

.view-once-toggle.active { color: var(--accent); }

/* ---------------- Modals: incoming call / media viewer ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.call-modal {
  width: 100%;
  max-width: 320px;
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.call-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 10px;
}
.call-title { font-size: 17px; font-weight: 600; }
.call-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 20px; }
.call-actions { display: flex; gap: 20px; }
.call-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  display: flex; align-items: center; justify-content: center;
}
.call-btn.accept { background: var(--online); }
.call-btn.decline { background: var(--danger); }

.in-call-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.in-call-video-wrap {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}
#remote-video { width: 100%; height: 100%; object-fit: cover; }
#local-video {
  position: absolute;
  bottom: 14px; right: 14px;
  width: 90px; height: 120px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
}
.in-call-audio-only {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.in-call-status { font-size: 13px; color: var(--text-dim); }
.in-call-controls {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 22px;
  background: var(--bg-raised);
}

/* View-once fullscreen viewer */
.viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-touch-callout: none;
}
.viewer img, .viewer video { max-width: 100%; max-height: 100%; }
.viewer-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.viewer-warning {
  position: absolute;
  bottom: 24px;
  left: 16px; right: 16px;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}

/* Toast for connection state */
#toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--text-dim);
  z-index: 40;
  transition: opacity 160ms ease;
}

/* Reduced motion: kill everything non-essential */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Small-screen safety (M02 is ~5.7", low density) */
@media (max-width: 360px) {
  .bubble { max-width: 84%; }
  .wordmark { font-size: 28px; }
}
