/*
 * TALK LINE STYLES
 * Colours, sizes and corners are variables ("design tokens") at the top, so the
 * dark theme only has to swap a few values.
 */
:root {
  --bg: #eef1f6;            /* page behind everything */
  --panel: #ffffff;         /* sidebar, header, composer */
  --chat-bg: #f6f7fb;       /* behind the messages */
  --ink: #111827;           /* main text */
  --muted: #6b7280;         /* secondary text */
  --line: #e5e7eb;          /* hairlines */
  --hover: #f3f4f6;
  --accent: #ef6234;        /* brand coral (matches the app icon) */
  --accent-soft: #fde8df;
  --mine: #ef6234;          /* my bubbles */
  --mine-ink: #ffffff;
  --theirs: #ffffff;        /* their bubbles */
  --go: #16a34a;
  --stop: #dc2626;
  --online: #22c55e;
  --shadow: 0 1px 2px rgb(17 24 39 / .06), 0 1px 1px rgb(17 24 39 / .04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070a12; --panel: #0f1420; --chat-bg: #0b0f19; --ink: #e8ebf2; --muted: #8b93a7;
    --line: #1e2533; --hover: #161c2a; --accent: #ff7a4d; --accent-soft: #3a1f17;
    --mine: #e95a2c; --theirs: #182032; --go: #22c55e; --stop: #ef4444; --online: #22c55e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }

/* ---------- buttons and inputs ---------- */
button { font: inherit; border: 0; cursor: pointer; color: inherit; background: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible, label:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: #fff; font-weight: 600; border-radius: 10px; padding: 11px 18px; transition: filter .15s; }
.primary:hover { filter: brightness(1.06); }
.primary.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--muted); flex: none; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
input, textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; min-width: 0; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.error { color: var(--stop); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- round profile pictures ---------- */
.avatar {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%; background: var(--line);
  color: #fff; font-weight: 700; font-size: 14px; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.md { width: 44px; height: 44px; font-size: 17px; }
/* The green "online" dot on someone's picture */
.avatar.online::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px;
  border-radius: 50%; background: var(--online); border: 2px solid var(--panel);
}

/* ---------- login / sign up ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%); background: var(--panel); border-radius: 20px; padding: 32px 28px;
  box-shadow: 0 10px 40px rgb(17 24 39 / .08); display: flex; flex-direction: column; gap: 14px;
}
.logo { width: 56px; height: 56px; border-radius: 16px; }
.login h1 { font-size: 26px; letter-spacing: -.02em; }
.sub { color: var(--muted); margin-top: -8px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--hover); border-radius: 10px; padding: 4px; }
.tab { padding: 8px; border-radius: 7px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.stack .primary { margin-top: 10px; }
.photo-pick { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.photo-pick .hint { flex: 1; }
.avatar.pick { width: 64px; height: 64px; font-size: 26px; cursor: pointer; background: var(--hover); color: var(--muted); border: 2px dashed var(--line); }
.avatar.pick:has(img) { border: 0; }

/* ---------- the app: sidebar + chat ---------- */
.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100%; height: 100dvh; max-width: 1400px; margin: 0 auto; background: var(--panel); }
/* min-width: 0 lets a column be narrower than its longest line, so long previews get "…"
   instead of pushing the page wider than the screen. */
.people { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-height: 0; min-width: 0; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px 16px; padding-top: max(14px, env(safe-area-inset-top)); }
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; border-radius: 12px; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: var(--go); }
.conn.bad { color: var(--stop); }
.section { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 16px 6px; }
#people-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; overflow-x: hidden; flex: 1; }
#people-list li { min-width: 0; }
.person { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; text-align: left; transition: background .12s; }
.person:hover { background: var(--hover); }
.person.active { background: var(--accent-soft); }
.person-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.person-top, .person-bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.person .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.preview { flex: 1; min-width: 0; color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview.is-typing { color: var(--accent); font-style: italic; }
.ai { font-size: 10px; font-weight: 800; letter-spacing: .06em; color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 1px 5px; flex: none; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center; flex: none; }
.empty-list { padding: 8px 16px; }

/* "Turn on notifications" card */
.push-box { margin: 4px 12px 8px; padding: 12px; border-radius: 12px; background: var(--accent-soft); display: flex; align-items: center; gap: 10px; font-size: 13px; }
.push-box p { flex: 1; min-width: 0; }
.push-icon { color: var(--accent); flex: none; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); position: relative; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px; }
.empty-chat img { width: 72px; height: 72px; border-radius: 20px; opacity: .9; margin-bottom: 6px; }
.empty-chat h2 { color: var(--ink); font-size: 20px; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); padding-top: max(10px, env(safe-area-inset-top));
}
.chat-who { flex: 1; min-width: 0; }
.chat-who h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-status { font-size: 12.5px; color: var(--muted); }
#chat-status.live { color: var(--go); }
.icon-btn.call { color: var(--go); }
.back { display: none; margin-left: -6px; }

.messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 16px 5%; display: flex; flex-direction: column; gap: 3px; }
.messages li { flex-shrink: 0; }
.messages .day {
  align-self: center; margin: 14px 0 8px; padding: 3px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  color: var(--muted); background: var(--panel); box-shadow: var(--shadow);
}
.messages .mine, .messages .theirs {
  max-width: min(72%, 560px); padding: 8px 12px 6px; border-radius: 18px; overflow-wrap: anywhere;
  box-shadow: var(--shadow); margin-top: 4px; display: flex; flex-direction: column;
}
.messages .theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 6px; }
.messages .mine { align-self: flex-end; background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 6px; }
.messages .system { align-self: center; font-size: 12.5px; color: var(--muted); padding: 6px 0; display: flex; gap: 6px; }
.messages .system .meta { margin: 0; }
/* Keep line breaks. Long messages start collapsed with a fade and a "See more" button. */
.messages .body { white-space: pre-wrap; }
.messages .body.clamped { max-height: 12em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.messages .more { align-self: flex-start; padding: 2px 0; font-size: 13px; font-weight: 600; text-decoration: underline; color: inherit; }
.meta { align-self: flex-end; font-size: 11px; opacity: .7; margin-top: 2px; display: flex; gap: 4px; align-items: center; }
.tick { font-weight: 700; letter-spacing: -2px; }
.tick.failed { color: #fff; background: var(--stop); border-radius: 50%; width: 14px; height: 14px; display: inline-grid; place-items: center; letter-spacing: 0; font-size: 10px; }

/* Photos and files in a message */
.photo { display: block; margin: -4px -8px 4px; border-radius: 14px; overflow: hidden; background: var(--hover); }
.photo img { display: block; width: 100%; max-width: 320px; max-height: 360px; object-fit: cover; }
.photo-only { padding: 4px !important; }
.photo-only .photo { margin: 0; }
.photo-only .meta { margin: -24px 8px 6px auto; padding: 1px 7px; border-radius: 999px; background: rgb(0 0 0 / .45); color: #fff; opacity: 1; position: relative; }
.file-card { display: flex; align-items: center; gap: 10px; padding: 8px; margin: -2px -4px 4px; border-radius: 12px; color: inherit; text-decoration: none; background: rgb(127 127 127 / .12); min-width: 200px; }
.file-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 10px; font-weight: 800; background: var(--accent); color: #fff; flex: none; }
.mine .file-icon { background: rgb(255 255 255 / .25); }
.file-info { display: flex; flex-direction: column; min-width: 0; }
.file-info b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info small { opacity: .75; }

/* "…" typing bubble */
.typing-bubble { align-self: flex-start; margin: 0 5% 8px; padding: 12px 14px; background: var(--theirs); border-radius: 18px; border-bottom-left-radius: 6px; display: flex; gap: 4px; box-shadow: var(--shadow); }
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* "Listening…" / "Recording 0:04…" / errors, just above the composer */
.voice-note { margin: 0; padding: 6px 16px; font-size: 13px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }
.voice-note.bad { color: var(--stop); }

/* The composer: [attach] [ text ] [mic] [send] */
.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; background: var(--panel);
  border-top: 1px solid var(--line); padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.composer textarea { resize: none; overflow-y: hidden; border-radius: 22px; padding: 10px 16px; max-height: 150px; line-height: 1.4; background: var(--chat-bg); }
.send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; transition: transform .1s, filter .15s; }
.send-btn:hover { filter: brightness(1.06); }
.send-btn:active { transform: scale(.94); }
.mic.listening { color: #fff; background: var(--stop); animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(220 38 38 / .5); } 70% { box-shadow: 0 0 0 10px rgb(220 38 38 / 0); } 100% { box-shadow: 0 0 0 0 rgb(220 38 38 / 0); } }

/* ---------- phones: show either the chat list OR the chat ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app.chatting .people { display: none; }
  .app:not(.chatting) .chat { display: none; }
  .back { display: inline-grid; }
  .messages { padding: 12px 10px; }
  .messages .mine, .messages .theirs { max-width: 82%; }
  .typing-bubble { margin-left: 10px; }
}

/* ---------- call popup ---------- */
.call-box { position: fixed; inset: 0; background: rgb(3 6 14 / .6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: grid; place-items: center; padding: 16px; z-index: 10; }
.call-card { background: var(--panel); border-radius: 24px; padding: 32px 28px; width: min(360px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.call-face { width: 96px; height: 96px; font-size: 38px; margin-bottom: 10px; }
.call-status { color: var(--muted); font-size: 14px; }
.call-peer { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.call-say { text-align: left; max-height: 40vh; overflow-y: auto; white-space: pre-wrap; color: var(--muted); margin-top: 8px; }
.call-timer { font-variant-numeric: tabular-nums; font-size: 18px; color: var(--muted); }
.call-actions { display: flex; gap: 14px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.round { min-width: 96px; padding: 12px 20px; border-radius: 999px; font-weight: 600; color: #fff; }
.round.go { background: var(--go); }
.round.stop { background: var(--stop); }
.round.ghost { background: var(--hover); color: var(--ink); }
/* Ringing: the picture pulses */
.call-box:has(#accept-btn:not([hidden])) .call-face { animation: ring 1.6s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgb(34 197 94 / .45); } 70% { box-shadow: 0 0 0 22px rgb(34 197 94 / 0); } 100% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
