:root {
  --bg: #ffffff;
  --panel: #f6f7f9;
  --panel2: #eef0f3;
  --line: #d7dce3;
  --txt: #111827;
  --dim: #3d444e;
  --faint: #6b7280;
  --accent: #1d4ed8;
  --ok: #047857;
  --warn: #b91c1c;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--faint);
  display: inline-block;
  margin-right: 6px;
}
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--warn); }

.main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  max-width: 480px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
}

.card h1 {
  font-size: 19px;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.card p {
  color: var(--dim);
  margin: 6px 0;
  font-size: 13.5px;
}

.card ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--dim);
  font-size: 13px;
}

.pill {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--faint);
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 700;
}
.pill.ok { background: var(--ok); }
.pill.err { background: var(--warn); }

.card form {
  margin-top: 14px;
}

.card input[type="text"],
.card input[type="tel"] {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--txt);
}

.card input[type="text"]:focus,
.card input[type="tel"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.card button[type="submit"],
.card button[type="button"]:not(.btn-secondary):not(.room-list-item) {
  width: 100%;
  margin-top: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 11px 14px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}

.card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: default;
}

.card a {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}
.card a:hover { text-decoration: underline; }

.field-error {
  color: var(--warn);
  font-size: 12.5px;
  margin: 8px 0 0;
}

/* --- room view (step 3) ---------------------------------------------------
   Deliberately NOT `.card`: that class is sized (max-width: 480px) and
   styled (buttons/inputs at width:100%) for the single-column auth/
   onboarding screens. A chat view needs to use available width on a laptop
   instead of sitting in a narrow portrait-shaped column, and its buttons
   need to sit inline (Copy invite link / Back) rather than stack full-width,
   which is what reusing `.card` was accidentally doing. */
.room-view {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 96px);
}

/* Landscape / desktop: use much more of the available width instead of the
   same narrow column the phone-sized layout uses. */
@media (min-width: 720px) {
  .room-view {
    max-width: min(1100px, 92vw);
  }
}

.room-view .room-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-shrink: 0;
}

/* Persistent split, no toggle: participants get two-thirds of the room
   view, chat (messages + composer) gets the remaining third. Stacked
   top/bottom on narrow screens, side by side once there's enough width to
   put a real member panel next to the conversation (matches how Discord/
   Slack lay this out on desktop). */
.room-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}
@media (min-width: 720px) {
  .room-body {
    flex-direction: row;
  }
}

.room-view h1 {
  font-size: 19px;
  margin: 0 0 2px;
  letter-spacing: -0.01em;
}

.room-presence {
  font-size: 12.5px;
  color: var(--faint);
  margin: 0;
}

.room-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-secondary {
  background: var(--panel2);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--line); }

.room-chat-section {
  flex: 1; /* one-third when paired with .room-grid-section's flex: 2 */
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.message-list {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-row {
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.composer-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.composer-form input[type="text"] {
  flex: 1 1 auto;
  min-width: 0; /* let a flex item actually shrink/grow instead of sitting at its intrinsic size */
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--txt);
}
.composer-form input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.composer-form button[type="submit"] {
  flex: 0 0 auto;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 10px 20px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}

.leave-room-btn {
  margin-top: 10px;
  flex-shrink: 0;
  background: transparent;
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 12.5px;
  cursor: pointer;
  align-self: flex-start;
}

.room-list-item {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  background: var(--panel2);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}
.room-list-item:hover { background: var(--line); }

/* --- participant grid (step 4, brief §3) -----------------------------------
   Static CSS grid. No physics, no SVG connector layer, no zoom, no drag —
   containment (which tile a circle sits in) and border style (solid=owned,
   dotted=shared) carry all the meaning. See public/js/participantGrid.js for
   the data rules, including the Facilitator special case. */
.room-grid-section {
  flex: 2; /* two-thirds when paired with .room-chat-section's flex: 1 */
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel2);
  padding: 22px 14px 14px;
  overflow-y: auto;
}

.participant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 22px 12px;
}
@media (max-width: 480px) {
  .participant-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

.tile {
  position: relative;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px;
  min-height: 78px;
  padding: 10px 8px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.tile.speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

/* The room-scoped agents' tile (Facilitator today) — dashed border marks it
   as belonging to the room itself, distinct from the solid-bordered human
   tiles next to it, so it doesn't read as "one more person". */
.tile.room-tile {
  border-style: dashed;
  background: var(--panel);
}

.tile-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
  flex-shrink: 0;
}
.tile-avatar.room {
  border-radius: 8px;
  background: var(--faint);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.tile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-name {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-agents {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -13px;
  display: flex;
  justify-content: center;
  gap: 5px;
}

.agent-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--panel2);
  border: 2px solid var(--txt);
  display: grid;
  place-items: center;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--txt);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
}
.agent-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.agent-circle.shared {
  border-style: dotted;
}
.agent-circle.overflow {
  background: var(--line);
  cursor: default;
}

.agent-popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.agent-popover-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  max-width: 320px;
  width: 100%;
}
.agent-popover-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}
.agent-popover-card p {
  margin: 4px 0;
  font-size: 13px;
  color: var(--dim);
}

.install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: #111827;
  color: #fff;
  font-size: 13px;
}
.install-banner.visible { display: flex; }
.install-banner button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}
