/* FamilyChat — Telegram-inspired dark theme, mobile-first */

:root {
  --bg: #0e1621;
  --bg-2: #17212b;
  --bg-3: #1f2c38;
  --bubble-mine: #2b5278;
  --bubble-theirs: #182533;
  --accent: #64b5ef;
  --text: #ffffff;
  --muted: #7d8e9e;
  --green: #4dd865;
  --danger: #e05555;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
}
#app { height: 100dvh; }
button { font: inherit; color: inherit; background: var(--bg-3); border: none; border-radius: 10px; padding: 10px 16px; cursor: pointer; }
button:disabled { opacity: .5; }
button.primary { background: var(--accent); color: #08151f; font-weight: 600; }
button.wide { display: block; width: 100%; margin: 10px 0; }
button.danger { background: var(--danger); }
button.link { background: none; color: var(--muted); text-decoration: underline; padding: 10px; }
input, textarea {
  font: inherit; color: var(--text);
  background: var(--bg-3); border: 1px solid transparent; border-radius: 10px;
  padding: 12px 14px; width: 100%; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { display: block; margin: 12px 0; color: var(--muted); font-size: 13px; }
label input { margin-top: 6px; color: var(--text); }
h1 { font-size: 24px; margin: 8px 0; }
h2 { font-size: 16px; margin: 22px 0 8px; color: var(--accent); }
code { background: var(--bg-3); padding: 2px 8px; border-radius: 6px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.green { color: var(--green); }
.hidden { display: none !important; }
.grow { flex: 1; }
.center { text-align: center; }
.center-screen { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.fatal { text-align: center; color: var(--muted); }

/* ---- auth ---- */
.auth-wrap { max-width: 380px; margin: 0 auto; padding: 48px 24px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; height: 100dvh; }
.auth-logo { font-size: 48px; text-align: center; }
.auth-wrap h1 { text-align: center; }
.auth-wrap h2 { text-align: center; margin-top: 28px; }

/* ---- generic screen ---- */
.screen { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; width: 100%; }
.bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2); padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  min-height: 56px; flex-shrink: 0;
}
.bar-title { font-weight: 600; font-size: 17px; }
.bar-main { flex: 1; min-width: 0; }
.bar-sub { font-size: 12px; color: var(--muted); }
.icon-btn { background: none; font-size: 20px; padding: 8px; line-height: 1; border-radius: 50%; }
.icon-btn.send { color: var(--accent); font-size: 22px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---- chat list ---- */
.chat-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; }
.chat-row:active { background: var(--bg-2); }
.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 18px; color: #fff; position: relative;
}
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.chat-row-main { flex: 1; min-width: 0; border-bottom: 1px solid rgba(255,255,255,.05); padding-bottom: 10px; }
.chat-row:last-child .chat-row-main { border-bottom: none; }
.chat-row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.chat-preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.chat-preview.unread { color: var(--text); font-weight: 500; }
.unread-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; flex-shrink: 0; }
.online-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--green); margin-left: 6px; vertical-align: middle;
}
.empty-state { text-align: center; padding: 60px 24px; color: var(--muted); }

/* ---- user list ---- */
.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid rgba(255,255,255,.05); }
.user-row input { width: 20px; height: 20px; }
.user-row-main { flex: 1; min-width: 0; }
.invite-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.05); }

/* ---- chat view ---- */
.chat-screen { background: var(--bg); }
.messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; }
.day-label { align-self: center; background: rgba(0,0,0,.25); color: var(--muted); font-size: 12px; padding: 3px 12px; border-radius: 12px; margin: 10px 0; }
.msg-row { display: flex; margin: 2px 0; max-width: 82%; }
.msg-row.mine { align-self: flex-end; }
.msg-row.theirs { align-self: flex-start; }
.bubble {
  background: var(--bubble-theirs); border-radius: var(--radius);
  padding: 8px 10px 6px; min-width: 80px; word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.2);
}
.msg-row.mine .bubble { background: var(--bubble-mine); }
.bubble.pending { opacity: .6; }
.msg-text { white-space: pre-wrap; font-size: 15px; }
.msg-meta { display: flex; justify-content: flex-end; gap: 4px; color: rgba(255,255,255,.5); font-size: 11px; margin-top: 3px; align-items: center; }

/* media bubbles */
.media-bubble { padding: 2px; }
.media-load {
  display: flex; gap: 10px; align-items: center; text-align: left;
  background: rgba(0,0,0,.25); border-radius: 10px; padding: 10px 14px; width: 100%;
}
.media-bubble.image img, .media-bubble.video video {
  max-width: 320px; max-height: 360px; border-radius: 10px; display: block;
}
.media-bubble.file a { color: var(--accent); text-decoration: none; display: block; padding: 6px; }
.file-ico { font-size: 26px; }
.voice-msg { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.voice-play {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent);
  color: #08151f; font-size: 16px; flex-shrink: 0; padding: 0;
}

/* ---- composer ---- */
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-2); padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px; border-radius: 18px;
  padding: 10px 14px; background: var(--bg-3);
}
.typing-bar {
  padding: 4px 16px; font-size: 12px; color: var(--accent);
  background: var(--bg-2); flex-shrink: 0;
}
.rec-bar {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-2); padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---- call overlay ---- */
#fc-call {
  position: fixed; inset: 0; background: #0a0f16; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
#fc-remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0a0f16; }
#fc-call.audio-only #fc-remote-video, #fc-call:not(.connected) #fc-remote-video { visibility: hidden; }
#fc-local-video {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px;
  width: 100px; height: 140px; object-fit: cover; border-radius: 12px;
  background: #000; z-index: 2;
}
#fc-call.audio-only #fc-local-video { display: none; }
.fc-call-info { z-index: 3; text-align: center; margin-bottom: auto; padding-top: 18vh; }
.fc-call-avatar {
  width: 110px; height: 110px; border-radius: 50%; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center; font-size: 38px; font-weight: 600;
}
.fc-call-name { font-size: 24px; font-weight: 600; }
.fc-call-status { color: var(--muted); margin-top: 6px; min-height: 20px; }
.fc-call-actions { z-index: 3; display: flex; gap: 22px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.fc-call-btn {
  width: 64px; height: 64px; border-radius: 50%; font-size: 24px;
  background: rgba(255,255,255,.15); display: flex; align-items: center; justify-content: center;
}
.fc-call-btn.accept { background: var(--green); color: #06210d; }
.fc-call-btn.danger { background: var(--danger); }
.fc-call-btn.off { background: rgba(224,85,85,.4); }

/* scrollbars (desktop) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
