/* GemFlare — dark-first (it's a video app); light theme via media query or
   data-theme override set by the pre-paint script in index.html. */

:root {
  --bg: #0e1116;
  --panel: #1a1f27;
  --panel-2: #232a35;
  --text: #e8ecf1;
  --muted: #8b95a3;
  --accent: #26a5ff;
  --accent-2: #1b7fd4;
  --green: #2ecc71;
  --red: #e74c3c;
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9; --panel: #ffffff; --panel-2: #eef1f5;
    --text: #16202b; --muted: #5c6773;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --panel: #1a1f27; --panel-2: #232a35;
  --text: #e8ecf1; --muted: #8b95a3;
}
:root[data-theme="gray"] {
  --bg: #23262b; --panel: #2e3238; --panel-2: #3a3f46;
  --text: #e6e9ed; --muted: #a5adb8;
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #eef1f5;
  --text: #16202b; --muted: #5c6773;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app { max-width: 560px; margin: 0 auto; padding: 16px; }

h1 { margin: 24px 0 4px; }
h2 { font-size: 1rem; color: var(--muted); margin: 24px 0 8px; text-transform: uppercase; letter-spacing: .06em; }
a { color: var(--accent); }
button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  transition: filter .2s ease, transform .15s ease, background-color .2s ease;
}
button:hover { filter: brightness(1.1); }
button:active { transform: scale(.95); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Inline SVG icons inherit text color and size to their container. */
button svg, .dir svg { width: 20px; height: 20px; display: block; }
.with-icon { display: inline-flex; align-items: center; gap: 8px; }
.icon-btn { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.rot { display: inline-flex; transform: rotate(135deg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
button.primary, .button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; color: var(--muted); }
/* Destructive actions read as destructive before they are pressed, and the
   whole zone is fenced off from the settings above it. */
button.danger { background: var(--red); color: #fff; }
button.ghost.danger { background: transparent; color: var(--red); }
.danger-zone { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line, rgba(128,128,128,.25)); }
.danger-zone p { margin: 4px 0 12px; }
.delete-confirm { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.delete-confirm.hidden, [data-delete].hidden { display: none; }
.card {
  background: var(--panel); border-radius: var(--radius);
  padding: 20px; margin: 12px 0;
}
.muted { color: var(--muted); }
.error { color: var(--red); }
.hint { color: var(--muted); min-height: 1.5em; margin: 4px 2px; }

/* --- Verify -------------------------------------------------------------- */
.verify { text-align: center; padding-top: 8vh; }
.verify .accent { color: var(--accent); }
.tagline { color: var(--muted); margin-top: 0; }
.phone-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.phone-form label { font-weight: 600; }
.phone-form input {
  font: inherit; font-size: 1.1rem; color: var(--text);
  background: var(--panel-2); border: 0; border-radius: 10px; padding: 12px 14px;
}
.small { font-size: .9rem; margin: 0; }
.welcome { font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; }
.code {
  font: 700 2rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .12em; margin: 16px 0; user-select: all;
}
.button { display: inline-block; padding: 12px 24px; border-radius: 10px; text-decoration: none; }
.qr-wrap { margin-top: 20px; }
.qr { width: 160px; margin: 8px auto; background: #fff; padding: 8px; border-radius: 8px; }
.qr svg { display: block; width: 100%; height: auto; }
.waiting { margin-top: 20px; }
.spinner {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px;
  border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Home ---------------------------------------------------------------- */
.home header { display: flex; align-items: center; gap: 12px; padding: 4px 0 12px; }
.identity { flex: 1; display: flex; flex-direction: column; }
.me { display: flex; gap: 8px; align-items: baseline; }
.own-name { font-weight: 600; outline: none; border-bottom: 1px dashed transparent; }
.own-name:hover, .own-name:focus { border-bottom-color: var(--muted); }
.own-phone { color: var(--muted); font-size: .9rem; }
.quality-pref {
  font: inherit; font-size: .85rem; color: var(--text);
  background: var(--panel-2); border: 0; border-radius: 8px; padding: 6px 8px;
}
.theme-btn { font-size: .85rem; padding: 6px 10px; border: 1px solid var(--panel-2); border-radius: 8px; }
.conn { color: var(--red); font-size: .8rem; }
.conn.online { color: var(--green); }

.banner { color: #ffb84d; }
.usage-strip { font-size: .85rem; margin: 2px 4px 8px; min-height: 1.2em; }
.plan-card { display: flex; flex-direction: column; gap: 8px; }
.plan-row { display: flex; justify-content: space-between; align-items: center; }
.plan-card progress { width: 100%; height: 8px; accent-color: var(--accent); }

.dial { display: flex; gap: 8px; padding: 12px; }
.dial input {
  flex: 1; min-width: 0; font: inherit; color: var(--text);
  background: var(--panel-2); border: 0; border-radius: 10px; padding: 10px 14px;
}
.recents { list-style: none; margin: 0; padding: 0; }
.recent {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px;
}
.recent .dir svg { width: 13px; height: 13px; display: inline-block; vertical-align: -2px; margin-right: 4px; }
.recent.missed .dir, .recent.missed .name { color: var(--red); }
.recent .who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.recent .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .sub { color: var(--muted); font-size: .85rem; }
.recent .actions { display: flex; gap: 8px; }
.recent .actions .icon-btn:last-child { color: var(--accent); }
.avatar.small {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent-2); color: #fff;
  font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none;
}

/* --- Call overlay -------------------------------------------------------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 40; background: #000;
  display: flex; align-items: center; justify-content: center;
  animation: fade-in .25s ease;
}
.call-overlay video.remote {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  background: #000;
}
/* Set from JS when the stream's orientation differs from the screen's:
   showing the whole frame beats cropping most of it away. */
.call-overlay video.remote.contain { object-fit: contain; }
.remote-idle {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #26303c, #0b0e12);
}
.avatar {
  width: 96px; height: 96px; border-radius: 50%; background: var(--accent-2);
  color: #fff; font-size: 2.4rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.avatar.big { width: 120px; height: 120px; font-size: 3rem; }
.call-overlay video.local {
  position: absolute; right: 16px; top: calc(16px + env(safe-area-inset-top));
  width: 28vw; max-width: 160px; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 12px; z-index: 42; background: #111;
  /* Draggable (see drag.ts): grab affordance, and no touch-scroll fighting the drag. */
  cursor: grab; touch-action: none;
}
.call-overlay video.local.dragging { cursor: grabbing; }
/* Landscape screens have landscape cameras — a portrait thumbnail would crop
   most of the self-view away. */
@media (orientation: landscape) {
  .call-overlay video.local { aspect-ratio: 4 / 3; max-width: 200px; }
}
/* Mirror the self-view only for the front camera (set from JS). */
.call-overlay video.local.mirror { transform: scaleX(-1); }
.call-overlay video.local.disabled { opacity: .35; }
.hidden { display: none !important; }

.call-top {
  position: absolute; left: 16px; right: 16px; top: calc(16px + env(safe-area-inset-top));
  display: flex; justify-content: space-between; align-items: flex-start; z-index: 41;
  color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.peer-name { font-size: 1.2rem; font-weight: 600; }
.call-status { color: #cfd8e3; font-variant-numeric: tabular-nums; }
.reconnecting .call-status { color: #ffb84d; }

.quality { display: flex; gap: 3px; align-items: flex-end; height: 18px; padding-top: 4px; }
.quality .bar { width: 5px; background: #ffffff55; border-radius: 2px; }
.quality .b1 { height: 6px; } .quality .b2 { height: 11px; } .quality .b3 { height: 16px; }
.quality[data-bars="1"] .b1 { background: #ffb84d; }
.quality[data-bars="2"] .b1, .quality[data-bars="2"] .b2 { background: #ffe14d; }
.quality[data-bars="3"] .b1, .quality[data-bars="3"] .b2, .quality[data-bars="3"] .b3 { background: var(--green); }

.stats-panel {
  position: absolute; left: 16px; top: calc(72px + env(safe-area-inset-top));
  z-index: 43; max-width: 70vw;
  background: rgba(0,0,0,.7); color: #d9e2ec; border-radius: 8px;
  padding: 8px 12px; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}

.call-controls {
  position: absolute; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; justify-content: center; gap: 14px; z-index: 42;
}
.call-controls button {
  width: 56px; height: 56px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: #ffffff22; color: #fff; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
/* The display:flex above silently defeats the `hidden` attribute (any author
 * display beats the UA's [hidden] rule), which put FIVE buttons on an audio
 * call — including two identical camera icons, one of them a no-op. This was
 * "upgrading to video doesn't work" in the wild: people tapped the wrong one. */
.call-controls button[hidden] { display: none; }
.call-controls button svg { width: 24px; height: 24px; }
.call-controls button.off { background: #fff; color: #16202b; }
.call-controls button.hangup { background: var(--red); }

/* --- Incoming call (full-screen, Duo-style) ------------------------------ */
.incoming-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(circle at 50% 30%, #223140, #0b0e12 70%);
  display: flex; flex-direction: column; align-items: center;
  justify-content: space-between;
  padding: calc(12vh + env(safe-area-inset-top)) 24px calc(8vh + env(safe-area-inset-bottom));
  animation: fade-in .25s ease;
  color: #fff;
}
.incoming-caller { text-align: center; }
.incoming-caller .peer-name { font-size: 1.7rem; font-weight: 700; margin-top: 24px; }
.incoming-kind { color: #9fb0c0; margin-top: 6px; }
.avatar-ring { position: relative; width: 120px; height: 120px; margin: 0 auto; }
.avatar-ring::before, .avatar-ring::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  animation: pulse-ring 2s ease-out infinite;
}
.avatar-ring::after { animation-delay: 1s; }
.incoming-actions { display: flex; gap: 40px; align-items: flex-end; }
.incoming-action { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #cfd8e3; font-size: .9rem; }
button.round {
  width: 68px; height: 68px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
button.round svg { width: 28px; height: 28px; }
button.round.accept { background: var(--green); color: #fff; }
button.round.decline { background: var(--red); color: #fff; }
button.round.accept-audio { background: #ffffff26; color: #fff; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); width: 56px; height: 56px; }
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: .8; }
  100% { transform: scale(1.6); opacity: 0; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* --- Admin panel ---------------------------------------------------------- */
.admin-shell { max-width: 860px; margin: 0 auto; padding: 16px; }
.admin h1 { font-size: 1.4rem; }
.admin-knobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 8px 0 14px; }
.admin-knobs label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.admin-knobs input {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 0; border-radius: 8px; padding: 8px 10px;
}
.admin-billing progress { width: 100%; height: 10px; accent-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; margin: 8px 0 12px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat strong { font-size: 1.3rem; }
.stat span { color: var(--muted); font-size: .78rem; line-height: 1.25; }
.admin-users { width: 100%; border-collapse: collapse; font-size: .92rem; }
.admin-users th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 10px; }
.admin-users td { padding: 8px 10px; border-top: 1px solid var(--panel-2); vertical-align: top; }
.admin-users select { font: inherit; background: var(--panel-2); color: var(--text); border: 0; border-radius: 6px; padding: 4px 6px; }
tr.user-disabled td { opacity: .45; }

/* --- Profile modal -------------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.modal-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 8px; }
.handle-row { display: flex; gap: 8px; }
.small-btn { font-size: .85rem; padding: 6px 10px; align-self: flex-start; }
.speed-figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0; }
.speed-verdict { margin: 4px 0; }
.speed-verdict.ok { color: var(--green); }
.speed-verdict.bad { color: var(--red); }
.modal-card select { font: inherit; background: var(--panel-2); color: var(--text); border: 0; border-radius: 8px; padding: 8px 10px; }
.oauth-row, .oauth-link-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.oauth-btn { background: var(--panel-2); color: var(--text); padding: 8px 14px; font-size: .92rem; }
.handle-row input {
  flex: 1; min-width: 0; font: inherit; color: var(--text);
  background: var(--panel-2); border: 0; border-radius: 10px; padding: 10px 14px;
}
.identity { cursor: pointer; border-radius: 10px; }
.identity:hover .own-phone { color: var(--accent); }
.nudge { border: 1px dashed var(--accent); }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: var(--panel); color: var(--text); border-radius: 10px;
  padding: 12px 20px; z-index: 60; box-shadow: 0 4px 24px rgba(0,0,0,.4);
}

/* --- Avatars (synced profile pictures over the initial circles) ----------- */
.avatar { position: relative; overflow: hidden; }
.avatar-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
}

/* --- Profile page ------------------------------------------------------- */
.profile-page { max-width: 560px; margin: 0 auto; padding: 0 16px 40px; }
.profile-top { display: flex; align-items: center; gap: 12px; padding: 16px 0; }
.profile-top h1 { font-size: 1.3rem; margin: 0; outline: none; }
.profile-card { display: flex; flex-direction: column; gap: 8px; }
.profile-sections { display: flex; flex-direction: column; gap: 8px; }
.profile-card > label { margin-top: 12px; }
.profile-avatar-row { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.profile-avatar-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.avatar.big {
  width: 88px; height: 88px; font-size: 2rem; position: relative; overflow: hidden; flex: none;
}
/* The file input is hidden, so its <label> is the button people actually press. */
.profile-avatar-actions .button { cursor: pointer; }
.profile-card input[readonly] { opacity: .75; }

/* --- Contacts page + presence -------------------------------------------- */
.contacts-btn { flex: none; text-decoration: none; color: var(--muted); }
.contacts-btn:hover { color: var(--text); }
.home header .identity { min-width: 0; } /* let the contacts icon fit beside it */
/* One dot vocabulary: red-ish muted = offline, green = online (same as .conn) */
.presence { color: var(--muted); font-size: .7rem; margin-right: 2px; }
.presence.online { color: var(--green); }
.contact.blocked .name { text-decoration: line-through; opacity: .7; }
.contact-menu {
  background: var(--panel-2); border-radius: var(--radius);
  padding: 10px 12px; margin: -4px 0 8px; display: flex; flex-direction: column; gap: 8px;
}
[data-availability].dnd { color: var(--red); }
