/* studygroup — a calm, rounded messenger. Dark by default, light on request.
   Everything is a token so the two themes stay in step; the layout is a sidebar
   plus a chat pane on desktop and one-at-a-time on a phone or Chromebook. */

:root {
  --bg: #15171c;
  --bg-raise: #1b1e25;
  --bg-sink: #101216;
  --panel: #1e222b;
  --line: #2a2f3a;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --faint: #6b7483;
  --brand: #7c9cff;
  --brand-soft: #2a3354;
  --mine: #3a4a7a;
  --mine-text: #eef1ff;
  --bubble: #262b35;
  --danger: #ff6b6b;
  --ok: #58c69a;
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 42px;
  --shadow: 0 6px 24px -12px rgba(0,0,0,.6);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-raise: #ffffff;
  --bg-sink: #e9edf5;
  --panel: #ffffff;
  --line: #e2e7f0;
  --text: #1b2330;
  --muted: #5d6675;
  --faint: #99a2b2;
  --brand: #4463e0;
  --brand-soft: #dfe6ff;
  --mine: #4463e0;
  --mine-text: #ffffff;
  --bubble: #eef1f7;
  --danger: #d6455b;
  --ok: #1f9d6b;
  --shadow: 0 8px 28px -16px rgba(30,50,110,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.brand { font-weight: 700; font-size: 17px; letter-spacing: -.02em; display: inline-flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.linkish { background: none; border: 0; color: var(--brand); font: inherit; padding: 0; text-decoration: underline; }
.hint { color: var(--faint); font-weight: 400; font-size: 12px; }

/* ── gate ─────────────────────────────────────────────────────────────────── */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; position: relative; }
.gate-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow);
}
.gate-sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 22px; }
.auth-form h1 { font-size: 21px; margin: 0 0 18px; letter-spacing: -.02em; }
.auth-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.auth-form input {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px; min-height: var(--tap);
  background: var(--bg-sink); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text); font-size: 16px; outline: none; transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--brand); }
.btn-primary {
  width: 100%; min-height: var(--tap); border: 0; border-radius: var(--radius-sm);
  background: var(--brand); color: #fff; font-size: 15px; font-weight: 600; margin-top: 4px;
  transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: translateY(1px); }
.auth-err { color: var(--danger); font-size: 13px; min-height: 1em; margin: 12px 0 0; }
.auth-ok { color: var(--ok); font-size: 13px; margin: 12px 0 0; }
.auth-switch { color: var(--muted); font-size: 13px; margin: 18px 0 0; text-align: center; }

.theme-toggle {
  position: absolute; top: 18px; right: 18px; width: var(--tap); height: var(--tap);
  border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-size: 18px; line-height: 1; display: grid; place-items: center;
}
.theme-toggle:hover { border-color: var(--brand); }

/* ── app shell ────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.sidebar { background: var(--bg-sink); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.side-head .theme-toggle { position: static; width: 34px; height: 34px; font-size: 15px; }
.side-actions { display: flex; gap: 8px; padding: 0 16px 10px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; min-height: 34px; transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--brand); }
.conv-list { flex: 1; overflow-y: auto; padding: 6px 10px; min-height: 0; }
.conv {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; color: var(--text); border-radius: var(--radius-sm);
  padding: 10px 10px; min-height: var(--tap); font-size: 14.5px; transition: background .12s;
}
.conv:hover { background: var(--bg-raise); }
.conv.active { background: var(--brand-soft); }
.conv-ic { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.conv.main .conv-ic { background: var(--brand); color: #fff; border-color: transparent; }
.conv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-kind { color: var(--faint); font-size: 11px; }
.side-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.me { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── chat pane ────────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--bg-raise); }
.chat-head h2 { font-size: 15.5px; margin: 0; letter-spacing: -.01em; }
.chat-sub { color: var(--faint); font-size: 12px; margin-left: auto; }
.back-btn { display: none; border: 0; background: none; color: var(--text); font-size: 26px; line-height: 1; width: 32px; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.day-note { align-self: center; color: var(--faint); font-size: 11px; background: var(--bg-raise); padding: 3px 10px; border-radius: 999px; }
.msg { max-width: min(76%, 560px); display: flex; flex-direction: column; gap: 3px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-who { font-size: 11.5px; color: var(--muted); padding: 0 4px; }
.msg.mine .msg-who { display: none; }
.bubble {
  background: var(--bubble); padding: 9px 13px; border-radius: 15px; font-size: 14.5px;
  line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; position: relative;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 5px; }
.msg:not(.mine) .bubble { border-bottom-left-radius: 5px; }
.msg-meta { font-size: 10.5px; color: var(--faint); padding: 0 4px; display: flex; gap: 8px; align-items: center; }
.msg-del { border: 0; background: none; color: var(--faint); font-size: 10.5px; padding: 0; text-decoration: underline; }
.msg-del:hover { color: var(--danger); }
.empty { margin: auto; color: var(--faint); font-size: 13.5px; text-align: center; }

.composer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--bg-raise); }
.composer input {
  flex: 1; padding: 11px 14px; min-height: var(--tap); background: var(--bg-sink);
  border: 1px solid var(--line); border-radius: 999px; color: var(--text); font-size: 16px; outline: none;
}
.composer input:focus { border-color: var(--brand); }
.btn-send { border: 0; border-radius: 999px; background: var(--brand); color: #fff; font-weight: 600; padding: 0 20px; min-height: var(--tap); font-size: 14px; }
.btn-send:hover { filter: brightness(1.07); }

/* ── modals ───────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); max-height: 86vh; overflow-y: auto; }
.modal-card.wide { max-width: 520px; }
.modal-card h3 { margin: 0 0 12px; font-size: 16px; }
.modal-card input { width: 100%; padding: 10px 12px; min-height: var(--tap); background: var(--bg-sink); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); font-size: 16px; outline: none; margin-bottom: 12px; }
.modal-card input:focus { border-color: var(--brand); }
.people { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; margin-bottom: 8px; }
.person { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); border: 1px solid transparent; background: var(--bg-sink); }
.person .av { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.person .pn { flex: 1; min-width: 0; }
.person .pn b { display: block; font-size: 14px; }
.person .pn small { color: var(--faint); font-size: 12px; }
.person.sel { border-color: var(--brand); background: var(--brand-soft); }
.person button { margin-left: auto; }
.pill-ok { color: var(--ok); border-color: var(--ok); }
.pill-bad { color: var(--danger); border-color: var(--danger); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ── toast ────────────────────────────────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); color: var(--text); padding: 11px 16px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow); z-index: 60; }

/* ── friends, presence ────────────────────────────────────────────────────── */
.friends-tab {
  display: flex; align-items: center; gap: 10px; width: calc(100% - 32px); margin: 0 16px 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 10px; min-height: var(--tap); font-size: 14.5px;
  transition: border-color .15s, background .15s;
}
.friends-tab:hover { border-color: var(--brand); }
.badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; box-shadow: 0 0 0 2px var(--bg-sink); }
.dot.on { background: var(--ok); }
.person .dot { margin-left: 6px; }

.friends-pane { background: var(--bg); }
.friends-body { flex: 1; overflow-y: auto; padding: 18px; }
.friends-h { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin: 18px 0 8px; }
.friends-h:first-child { margin-top: 0; }

.head-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 15px; display: grid; place-items: center;
  transition: border-color .15s, opacity .15s;
}
.icon-btn:hover:not(:disabled) { border-color: var(--brand); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.chat-head .chat-sub { margin-left: 10px; }

.call-note {
  background: var(--brand-soft); color: var(--text); font-size: 12.5px;
  padding: 9px 18px; border-bottom: 1px solid var(--line);
}
.switch-row { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 4px; min-height: var(--tap); }
.switch-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }

/* ── ringing ──────────────────────────────────────────────────────────────── */
.ring-card { text-align: center; max-width: 320px; }
.ring-av {
  width: 74px; height: 74px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 30px; font-weight: 700; margin: 4px auto 14px;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--brand-soft); } 50% { box-shadow: 0 0 0 14px transparent; } }
@media (prefers-reduced-motion: reduce) { .ring-av { animation: none; } }
.ring-sub { color: var(--muted); font-size: 13px; margin: 2px 0 20px; }
.ring-actions { display: flex; justify-content: center; gap: 26px; }
.btn-round {
  width: 54px; height: 54px; border-radius: 50%; border: 0; font-size: 20px; color: #fff;
  background: var(--bubble); display: grid; place-items: center; transition: filter .15s, transform .05s;
}
.btn-round:hover { filter: brightness(1.12); }
.btn-round:active { transform: translateY(1px); }
.btn-round.accept { background: var(--ok); }
.btn-round.decline, .btn-round.hang { background: var(--danger); }
.btn-round.off { background: var(--danger); }

/* ── in a call ────────────────────────────────────────────────────────────── */
.call-overlay {
  position: fixed; inset: 0; z-index: 70; background: var(--bg-sink);
  display: flex; flex-direction: column;
}
.call-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; color: var(--muted); font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.call-timer { font-variant-numeric: tabular-nums; color: var(--text); }
.tiles { flex: 1; display: grid; gap: 10px; padding: 14px; min-height: 0; grid-template-columns: 1fr; }
.tiles.n2, .tiles.n3, .tiles.n4 { grid-template-columns: repeat(2, 1fr); }
.tiles.n5 { grid-template-columns: repeat(3, 1fr); }
.tile {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; min-height: 0; display: grid; place-items: center;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.audio-only video { display: none; }
.tile.audio-only::before {
  content: attr(data-initial);
  width: 76px; height: 76px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 30px; font-weight: 700;
}
.tile.waiting { opacity: .6; }
.tile-name {
  position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.55); color: #fff;
  font-size: 12px; padding: 3px 9px; border-radius: 999px; max-width: calc(100% - 20px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.call-bar { display: flex; justify-content: center; gap: 18px; padding: 16px; border-top: 1px solid var(--line); }

/* ── phone / Chromebook narrow ──────────────────────────────────────────────── */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: flex; }
  .main { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .main:not([hidden]) { display: flex; }
  .back-btn { display: block; }
  .chat-sub { display: none; }
  .msg { max-width: 86%; }
  .tiles.n2, .tiles.n3, .tiles.n4, .tiles.n5 { grid-template-columns: repeat(2, 1fr); }
  .friends-tab { width: calc(100% - 32px); }
}
