:root {
  --bg: #0b0f14;
  --surface: #121a22;
  --surface-2: #18232d;
  --line: #22303c;
  --text: #e6edf3;
  --muted: #8b9aa8;
  --accent: #14b8a6;
  --accent-2: #2dd4bf;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  --ctl-h: 76px;
  --side-w: 340px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.ico {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #33485a; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #04211e; font-weight: 600; }
.btn--primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn--primary:disabled { opacity: .6; cursor: progress; }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; }
.btn--sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn--sm .ico { width: 16px; height: 16px; }
.btn--icon { padding: 0 12px; position: relative; }
.pill {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--accent-2);
  font-size: 12px; line-height: 18px; text-align: center;
}

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login__card {
  width: min(100%, 400px); display: grid; gap: 16px; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.brand__mark {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px;
  background: rgba(20,184,166,.14); color: var(--accent-2);
}
.brand__mark--sm { width: 36px; height: 36px; border-radius: 10px; }
.brand__title { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.brand__sub { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input[type=text], .field input[type=password] {
  min-height: 46px; padding: 0 14px; border-radius: 10px; background: var(--bg);
  border: 1px solid var(--line); outline: none; font-size: 16px;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20,184,166,.2); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(239,68,68,.12); color: #fca5a5; font-size: 14px; }

/* app shell */
.app {
  height: 100dvh; display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  grid-template-rows: auto minmax(0, 1fr) var(--ctl-h);
  grid-template-areas: "top top" "stage side" "ctl ctl";
}
.topbar {
  grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.topbar__left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar__title { display: grid; line-height: 1.2; min-width: 0; }
.topbar__title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__title .muted { font-size: 12px; }
.panel-toggle { display: none; }
.rec-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; margin-left: auto;
  border-radius: 99px; background: rgba(239,68,68,.14); border: 1px solid rgba(239,68,68,.5);
  color: #fecaca; font-size: 13px; font-weight: 600; letter-spacing: .06em;
}
.rec-badge time { font-variant-numeric: tabular-nums; letter-spacing: 0; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* stage / grid */
.stage { grid-area: stage; overflow: auto; padding: 14px; min-width: 0; }
.grid {
  display: grid; gap: 12px; align-content: start; min-height: 100%;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}
.grid[data-n="1"] { grid-template-columns: minmax(0, 1fr); align-content: center; }
.grid[data-n="1"] .tile { max-height: calc(100dvh - 190px); margin-inline: auto; width: 100%; }
.tile {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--radius);
  background: var(--surface); border: 2px solid transparent; outline: 1px solid var(--line); outline-offset: -1px;
  transition: border-color .15s, box-shadow .15s;
}
.tile.is-speaking { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(45,212,191,.22); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.is-screen video { object-fit: contain; }
.tile.is-local:not(.is-screen) video { transform: scaleX(-1); }
.tile__ph { position: absolute; inset: 0; display: grid; place-items: center; }
.tile__ava {
  display: grid; place-items: center; width: clamp(56px, 22%, 96px); aspect-ratio: 1; border-radius: 50%;
  background: linear-gradient(145deg, #134e4a, #0f766e); color: #ccfbf1; font-size: clamp(22px, 4vw, 36px); font-weight: 600;
}
.tile.has-video .tile__ph { display: none; }
.tile__label {
  position: absolute; left: 8px; bottom: 8px; right: 8px; display: flex; align-items: center; gap: 6px;
  width: fit-content; max-width: calc(100% - 16px); padding: 4px 10px 4px 8px; border-radius: 8px;
  background: rgba(11,15,20,.72); font-size: 13px;
}
.tile__label .ico { width: 16px; height: 16px; }
.tile__label .is-off { color: #fca5a5; }
.tile__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.is-speaking .tile__label .mic { color: var(--accent-2); }

/* screen share large */
.grid.has-screen { grid-template-columns: minmax(0, 1fr) clamp(150px, 18vw, 230px); }
.grid.has-screen .tile { grid-column: 2; }
.grid.has-screen .tile.is-screen { grid-column: 1; grid-row: 1 / span 40; max-height: none; align-self: start; }

/* side */
.side { grid-area: side; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }
.side__head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 12px; border-bottom: 1px solid var(--line); }
.side__close { display: none; }
.tabs { display: flex; gap: 4px; }
.tab {
  min-height: 44px; padding: 0 12px; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.pane { flex: 1; min-height: 0; overflow: auto; padding: 8px; }
.pane__bar { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
.pane__status { padding: 4px; margin: 0; font-size: 13px; }
.people, .recs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.person {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2);
}
.person__ava { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: #0f766e; color: #ccfbf1; font-weight: 600; flex: none; }
.person.is-speaking .person__ava { box-shadow: 0 0 0 2px var(--accent-2); }
.person__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person__name small { color: var(--muted); }
.person__st { display: flex; gap: 8px; color: var(--accent-2); }
.person__st .ico { width: 18px; height: 18px; }
.person__st .is-off { color: #6b7b89; }
.rec-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: var(--surface-2); }
.rec-item__main { flex: 1; min-width: 0; display: grid; }
.rec-item__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-item__meta { font-size: 12px; color: var(--muted); }
.rec-item a {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; color: var(--accent-2);
  border: 1px solid var(--line); text-decoration: none;
}
.rec-item a:hover { background: rgba(20,184,166,.12); }

/* controls */
.controls {
  grid-area: ctl; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg);
  overflow-x: auto;
}
.ctl {
  display: grid; justify-items: center; align-content: center; gap: 4px; flex: none;
  min-width: 68px; min-height: 58px; padding: 6px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 12px; color: var(--text);
  transition: background .15s, border-color .15s;
}
.ctl:hover { border-color: #33485a; }
.ctl:disabled { opacity: .45; cursor: not-allowed; }
.ctl.is-off { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.5); color: #fecaca; }
.ctl.is-on { background: rgba(20,184,166,.16); border-color: var(--accent); color: var(--accent-2); }
.ctl--rec.is-on { background: rgba(239,68,68,.16); border-color: var(--danger); color: #fecaca; }
.ctl--rec.is-on .ico { color: var(--danger); }
.ctl--leave { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl--leave:hover { background: #dc2626; border-color: #dc2626; }

/* toasts */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 440px); pointer-events: none; }
.toast { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.45); font-size: 14px; }
.toast--error { border-color: rgba(239,68,68,.6); }
.toast--ok { border-color: var(--accent); }
.audio-gate { position: fixed; left: 50%; bottom: calc(var(--ctl-h) + 16px); transform: translateX(-50%); z-index: 40; }
.scrim { display: none; }

/* tablet / mobile */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage" "ctl"; }
  .panel-toggle { display: inline-flex; gap: 6px; margin-left: 8px; }
  .rec-badge { margin-left: auto; }
  .side {
    position: fixed; inset: auto 0 0 0; height: min(78dvh, 640px); z-index: 30;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
    transform: translateY(105%); transition: transform .22s ease; visibility: hidden;
  }
  .side.is-open { transform: none; visibility: visible; }
  .side__close { display: inline-flex; }
  .scrim.is-open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
  .grid.has-screen { grid-template-columns: minmax(0, 1fr); }
  .grid.has-screen .tile { grid-column: 1; }
  .grid.has-screen .tile.is-screen { grid-row: auto; order: -1; }
  .stage { padding: 10px; }
  .grid { gap: 8px; }
}
@media (max-width: 640px) {
  :root { --ctl-h: 66px; }
  .ctl { min-width: 50px; min-height: 50px; padding: 4px 8px; }
  .ctl span { display: none; }
  .controls { gap: 6px; justify-content: space-around; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
  .login__card { padding: 22px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .topbar { padding: 4px 12px; }
  .grid[data-n="1"] .tile { max-height: calc(100dvh - 130px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
