:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --text: #1c2624;
  --muted: #5b6966;
  --line: #d5dcda;
  --accent: #17695c;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --call-bg: #121615;
  --call-surface: #1e2523;
  --call-line: #34403d;
  --call-text: #eef2f1;
  --call-muted: #a3b0ad;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1e2523;
    --text: #eef2f1;
    --muted: #a3b0ad;
    --line: #34403d;
    --accent: #4fb3a2;
    --accent-text: #0c1a17;
    --danger: #f2877f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 0.75rem; text-wrap: balance; }
h2 { font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; margin: 0 0 0.5rem; color: var(--call-muted); }
p { margin: 0 0 1rem; }
.fine { font-size: 0.875rem; color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }

button, input { font: inherit; }
button {
  min-height: 44px;
  padding: 0 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  cursor: pointer;
}
button:hover { border-color: currentColor; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }

label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
input[type="text"], input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 0 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
form { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
form button { margin-top: 0.5rem; }

/* ---------------------------------------------- forms and message pages */
.page-client:not(.in-call) { display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%;
  max-width: 440px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card > :last-child { margin-bottom: 0; }

.preview { margin-bottom: 1rem; }
.preview video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #000;
  border-radius: 8px;
  transform: scaleX(-1);
  margin-bottom: 0.5rem;
}

/* ------------------------------------------------------------ call view */
.in-call { background: var(--call-bg); color: var(--call-text); }
.call {
  height: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.tiles {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  grid-auto-rows: minmax(0, 1fr);
}
.tile {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--call-surface);
}
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-self video { transform: scaleX(-1); }
.tile .avatar {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: none;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 600;
  background: var(--call-line);
}
.tile.no-video video { visibility: hidden; }
.tile.no-video .avatar { display: grid; }
.tile-label, .tile-status {
  position: absolute;
  bottom: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.875rem;
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-label { left: 8px; }
.tile-status { right: 8px; bottom: auto; top: 8px; }
.tile-status:empty { display: none; }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #000;
}
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage-label {
  position: relative;
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.875rem;
  align-self: start;
  margin-top: 8px;
}
.stage video[hidden] + .stage-label { align-self: center; font-size: 1rem; }

/* While a screen is shared the people shrink to a strip underneath it. */
.has-stage .tiles {
  flex: 0 0 132px;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 200px;
  justify-content: center;
  overflow-x: auto;
}
.has-stage .tile .avatar { width: 56px; height: 56px; font-size: 1.5rem; }

.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.controls button { border-color: var(--call-line); background: var(--call-surface); color: var(--call-text); }
.controls button.off { background: var(--call-text); color: var(--call-bg); }
.controls button.on, .controls button.attention { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.controls button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

/* -------------------------------------------------------- provider page */
.page-provider { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100%; }
.side {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 16px;
  overflow-y: auto;
  background: var(--call-surface);
  border-right: 1px solid var(--call-line);
}
.side .fine { color: var(--call-muted); }
.side button { border-color: var(--call-line); }
.side-foot { margin-top: auto; }
.count {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 6px;
  border-radius: 999px;
  background: #4fb3a2;
  color: #0c1a17;
  text-align: center;
  letter-spacing: 0;
}
.people { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.people li { padding: 12px; border: 1px solid var(--call-line); border-radius: var(--radius); background: var(--call-bg); }
.person { display: flex; flex-direction: column; margin-bottom: 8px; overflow-wrap: anywhere; }
.person span { font-size: 0.875rem; color: var(--call-muted); }
.person-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.person-actions button { min-height: 40px; }
.person-actions .primary { background: #4fb3a2; border-color: #4fb3a2; color: #0c1a17; }
.link-row { display: flex; gap: 8px; margin-bottom: 12px; }
.link-row input { background: var(--call-bg); color: var(--call-text); border-color: var(--call-line); min-width: 0; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.8);
  color: var(--text);
}

@media (max-width: 760px) {
  .page-provider { grid-template-columns: 1fr; grid-template-rows: auto minmax(360px, 1fr); height: auto; min-height: 100%; }
  .side { border-right: 0; border-bottom: 1px solid var(--call-line); }
}

/* ------------------------------------- enlarge a person, quality menu */
.tile { cursor: pointer; }
.tile:focus-visible { outline: 3px solid #4fb3a2; outline-offset: 2px; }
.tile.pinned { box-shadow: 0 0 0 3px #4fb3a2; }
.stage-person { cursor: pointer; }
.stage video.mirror { transform: scaleX(-1); }
.controls select {
  min-height: 44px;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--call-line);
  background: var(--call-surface);
  color: var(--call-text);
  font: inherit;
  cursor: pointer;
}
.controls select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------- two-factor sign-in */
.qr { display: block; width: 200px; height: 200px; margin: 0 auto 1rem; background: #fff; border-radius: 8px; }
code { font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.overlay form.card { max-height: 100%; overflow-y: auto; }
.side-foot h2 { margin-top: 16px; }
.side-foot h2:first-child { margin-top: 0; }
