:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --green: #15803d;
  --green-dark: #166534;
  --red: #dc2626;
  --red-dark: #b91c1c;
  --amber: #b45309;
  --call-bg: #0b0f14;
  --tile-bg: #1b2230;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .6; cursor: default; }

/* ---------- Botões gerais ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  font-size: 17px;
  text-decoration: none;
  color: #fff;
  background: var(--primary);
  transition: background .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:hover:not(:disabled) { background: var(--primary-dark); }
.btn.green { background: var(--green); }
.btn.green:hover:not(:disabled) { background: var(--green-dark); }
.btn.red { background: var(--red); }
.btn.red:hover:not(:disabled) { background: var(--red-dark); }
.btn.light { background: #eef2f7; color: var(--text); }
.btn.light:hover:not(:disabled) { background: #e2e8f0; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.huge {
  width: 100%;
  min-height: 76px;
  font-size: 26px;
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(21, 128, 61, .35);
}

/* ---------- Telas centralizadas (entrada, mensagens, login) ---------- */
.center-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border-radius: 22px;
  padding: 32px 24px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, .08);
  text-align: center;
}
.card .big-icon { font-size: 60px; line-height: 1; margin-bottom: 12px; }
.card h1 { font-size: 28px; line-height: 1.2; margin: 0 0 10px; }
.card .lead { font-size: 21px; color: var(--muted); margin: 0 0 26px; }
.card .hint { font-size: 17px; color: var(--muted); margin: 20px 0 0; }
.card .help { text-align: left; font-size: 18px; margin: 0 0 20px; padding-left: 22px; }
.card .help li { margin-bottom: 8px; }
.card .actions { display: grid; gap: 10px; }
.warn-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #7c2d12;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  margin-top: 18px;
  text-align: left;
}

/* ---------- Login ---------- */
.form { display: grid; gap: 14px; text-align: left; }
.form label { font-size: 15px; font-weight: 600; color: var(--muted); display: grid; gap: 6px; }
.input {
  width: 100%;
  min-height: 50px;
  padding: 10px 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 17px;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
.error-text { color: var(--red); font-size: 15px; min-height: 1em; margin: 0; }

/* ---------- Painel do host ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.topnav .brand { font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.topnav .who { font-size: 15px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.container { max-width: 880px; margin: 0 auto; padding: 18px 16px 48px; }
.host-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.host-tabs a { padding: 10px 15px; color: var(--muted); text-decoration: none; border-radius: 10px; font-size: 16px; font-weight: 600; }
.host-tabs a[aria-current="page"] { color: var(--primary); background: #dbeafe; }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 20px 0; }
.usage-card { border: 1px solid var(--line); border-radius: 14px; padding: 16px; font-size: 15px; }
.usage-card h3 { margin: 0 0 12px; font-size: 18px; }
.usage-card p { margin: 8px 0; }
.panel {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
}
.panel h2 { font-size: 20px; margin: 0 0 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .input { flex: 1 1 220px; }
.muted { color: var(--muted); }
.small-text { font-size: 14px; }
.list { display: grid; gap: 12px; }
.item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.item-title { font-weight: 700; font-size: 17px; word-break: break-word; }
.item-sub { font-size: 14px; color: var(--muted); }
.transcript-body { margin-top: 16px; border-top: 1px solid #e2e8f0; padding-top: 14px; }
.transcript-body h3 { font-size: 16px; margin: 0 0 10px; }
.transcript-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow-y: auto; background: #f8fafc; border-radius: 8px; padding: 14px; font: inherit; font-size: 14px; line-height: 1.6; }
.item .link-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
}
.item .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  background: #eef2f7;
  color: #334155;
}
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.empty { color: var(--muted); font-size: 16px; padding: 8px 0; }
.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 15px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #7c2d12;
}

/* ---------- Chamada ---------- */
body.in-call { background: var(--call-bg); overflow: hidden; }
#screen-call {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--call-bg);
  color: #fff;
}
#grid {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 6px;
  padding: 6px;
  padding-top: max(6px, env(safe-area-inset-top));
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--tile-bg);
  border-radius: 14px;
  overflow: hidden;
}
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.tile.local.mirror video { transform: scaleX(-1); }
.tile .avatar {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--tile-bg);
}
.tile .avatar span {
  width: clamp(56px, 22%, 120px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #3b4557;
  font-size: clamp(24px, 6vw, 48px);
  font-weight: 700;
  text-transform: uppercase;
}
.tile.cam-off .avatar { display: grid; }
.tile.cam-off video { visibility: hidden; }
.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .label .mic-off { display: none; color: #fca5a5; flex: none; }
.tile.mic-off .label .mic-off { display: inline-flex; }
.tile .conn {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 15, 20, .6);
  font-size: 17px;
  text-align: center;
  padding: 12px;
}

/* Layouts conforme a quantidade de pessoas */
#grid[data-count="2"] .tile.remote video { object-fit: contain; }
#grid[data-count="2"] .tile.local {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 30vw;
  max-width: 190px;
  aspect-ratio: 3 / 4;
  z-index: 5;
  border: 2px solid rgba(255, 255, 255, .85);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
#grid[data-count="2"] .tile.local .label { font-size: 12px; padding: 2px 6px; left: 4px; bottom: 4px; }
#grid[data-count="3"], #grid[data-count="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
#grid[data-count="3"] .tile.local + .tile { grid-column: span 2; order: -1; }

@media (orientation: landscape) {
  #grid[data-count="2"] .tile.local { aspect-ratio: 4 / 3; width: 24vw; max-width: 260px; }
  #grid[data-count="3"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr; }
  #grid[data-count="3"] .tile.local + .tile { grid-column: auto; order: 0; }
}

.waiting-msg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  width: min(86%, 420px);
  padding: 18px 20px;
  border-radius: 16px;
  background: rgba(0, 0, 0, .65);
  text-align: center;
  font-size: 20px;
  line-height: 1.35;
}

/* Barra superior (gravando / status) */
.topbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 8;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .7);
  font-size: 16px;
  font-weight: 600;
}
.pill.rec { background: rgba(185, 28, 28, .92); }
.pill.rec .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.2s infinite;
}
.pill.warn { background: rgba(180, 83, 9, .95); }
@keyframes pulse { 50% { opacity: .25; } }

/* Controles */
.controls {
  flex: none;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(6px, 2.5vw, 22px);
  padding: 10px 8px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: #111823;
}
.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  width: clamp(54px, 17vw, 84px);
  padding: 0;
  border: 0;
  background: none;
  color: #e5e7eb;
  font-size: clamp(11px, 3.1vw, 14px);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}
.ctl .ic {
  width: clamp(48px, 13.5vw, 60px);
  height: clamp(48px, 13.5vw, 60px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2b3444;
  transition: background .15s, transform .05s;
}
.ctl svg { width: 46%; height: 46%; }
.ctl:hover .ic { background: #3a4558; }
.ctl:active .ic { transform: scale(.94); }
.ctl.off .ic { background: var(--red); }
.ctl.danger .ic { background: var(--red); }
.ctl.recording .ic { background: var(--red); animation: pulse 1.4s infinite; }
.ctl.waiting .ic { background: var(--amber); }
.ctl .ic-off { display: none; }
.ctl.off .ic-on { display: none; }
.ctl.off .ic-off { display: block; }

/* ---------- Modais ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .65);
}
.modal-box {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: #fff;
  color: var(--text);
  border-radius: 20px;
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.modal-box .big-icon { font-size: 50px; line-height: 1; margin-bottom: 10px; }
.modal-box h2 { font-size: 24px; margin: 0 0 10px; line-height: 1.25; }
.modal-box p { font-size: 19px; color: var(--muted); margin: 0 0 20px; }
.modal-box .actions { display: grid; gap: 10px; }
.modal-box .btn { min-height: 58px; font-size: 20px; }
.modal-box .link-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 16px;
  word-break: break-all;
  user-select: all;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: max(16px, env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 60;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  text-align: center;
}

.unmute {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  z-index: 40;
}
