:root {
  font-family: "Helvetica Neue", Arial, "PingFang SC", sans-serif;
  color: #171719;
  background: #f7f7f8;
  --blue: #002fa7;
  --line: #dfe1e5;
  --muted: #6c7077;
  --soft: #f7f7f8;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--soft); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.operator-shell { width: 100%; height: 100%; display: grid; grid-template-rows: 68px minmax(0, 1fr); }
.topbar { display: grid; grid-template-columns: 180px minmax(0, 1fr) auto; align-items: center; gap: 24px; padding: 0 24px; border-bottom: 1px solid var(--line); background: #fff; }
.brand { color: var(--blue); font-size: 14px; font-weight: 700; }
.lesson-heading { min-width: 0; display: flex; align-items: baseline; gap: 12px; }
.lesson-heading span { color: var(--muted); font-size: 12px; }
.lesson-heading strong { min-width: 0; overflow: hidden; font-size: 18px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.topbar-status { display: flex; align-items: center; gap: 22px; color: var(--muted); font-size: 12px; }
#connection-status { position: relative; padding-left: 12px; white-space: nowrap; }
#connection-status::before { content: ""; position: absolute; top: 5px; left: 0; width: 6px; height: 6px; border-radius: 50%; background: #92959b; }
#connection-status[data-state="connected"]::before { background: var(--blue); }
#connection-status[data-state="error"]::before, #connection-status[data-state="revoked"]::before { background: #e4002b; }
.presence { display: flex; align-items: baseline; gap: 7px; padding-left: 22px; border-left: 1px solid var(--line); }
.presence strong { color: var(--blue); font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }

.console-grid { min-height: 0; display: grid; grid-template-columns: minmax(260px, 0.82fr) minmax(420px, 1.75fr) minmax(260px, 0.9fr); gap: 1px; background: var(--line); }
.panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.panel-head { flex: 0 0 70px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 18px; border-bottom: 1px solid var(--line); background: #fff; }
.panel-kicker { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.panel-head strong { display: block; min-width: 0; overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.messages-head { align-items: flex-end; padding-bottom: 13px; }
.channel-picker { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.channel-picker select { width: 100px; height: 30px; padding: 0 7px; border: 1px solid #b8bbc1; border-radius: 0; outline: 0; background: #fff; color: #171719; font-size: 12px; }
.channel-picker select:focus { border-color: var(--blue); }

.messages { min-height: 0; flex: 1 1 auto; padding: 8px 16px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; background: var(--soft); }
.message { position: relative; display: block; width: 100%; padding: 12px 8px 13px; border-bottom: 1px solid var(--line); cursor: pointer; }
.message:hover, .message[data-selected="true"] { background: #fff; }
.message strong { display: block; margin-bottom: 4px; color: var(--blue); font-size: 12px; font-weight: 600; }
.message p { margin: 0; color: #202124; font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message time { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; }
.error-note { margin: 18px 8px; color: #b32645; font-size: 13px; }
.composer { flex: 0 0 auto; display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #fff; }
.composer input { min-width: 0; flex: 1 1 auto; height: 40px; padding: 0 11px; border: 1px solid #b8bbc1; border-radius: 0; outline: 0; background: #fff; font-size: 14px; }
.composer input:focus { border-color: var(--blue); }
.composer input:disabled { background: var(--soft); }
.composer button { flex: 0 0 52px; height: 40px; border: 0; border-radius: 0; background: var(--blue); color: #fff; font-size: 13px; font-weight: 600; }
.composer button:disabled { opacity: .5; cursor: default; }

.video-panel { background: #111; }
.video-panel .panel-head { background: #fff; }
.video-status { color: var(--muted); font-size: 11px; }
.video-stage { min-height: 0; flex: 1 1 auto; display: grid; place-items: center; background: #111; }
.video-stage video { display: block; width: 100%; max-height: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #111; }
.video-footer { display: flex; align-items: center; justify-content: space-between; flex: 0 0 42px; padding: 0 18px; border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 11px; }
.video-footer strong { color: #171719; font-weight: 600; }

.users-head { align-items: flex-end; padding-bottom: 13px; }
.user-note { color: var(--muted); font-size: 11px; white-space: nowrap; }
.user-list { min-height: 0; flex: 1 1 auto; overflow-y: auto; background: var(--soft); }
.user-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.user-row:hover, .user-row[data-selected="true"] { background: #fff; }
.user-avatar { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--blue); border-radius: 50%; color: var(--blue); font-size: 13px; font-weight: 600; }
.user-name { min-width: 0; overflow: hidden; color: #171719; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.user-id { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.user-count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.user-detail { flex: 0 0 auto; min-height: 152px; padding: 18px 16px; border-top: 1px solid var(--line); background: #fff; }
.detail-title { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.detail-title .user-avatar { flex: 0 0 34px; width: 34px; height: 34px; }
.detail-title strong { display: block; font-size: 15px; font-weight: 600; }
.detail-title span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.detail-grid { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 12px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-detail { color: var(--muted); font-size: 12px; }
.empty-users { padding: 20px 16px; color: var(--muted); font-size: 12px; }

@media (max-width: 1040px) {
  body { overflow: auto; }
  .operator-shell { height: auto; min-height: 100%; }
  .console-grid { grid-template-columns: minmax(240px, .8fr) minmax(360px, 1.2fr); grid-template-rows: minmax(520px, 1fr) 390px; }
  .video-panel { grid-column: 2; grid-row: 1; }
  .messages-panel { grid-column: 1; grid-row: 1; }
  .users-panel { grid-column: 1 / -1; grid-row: 2; }
  .user-list { display: flex; overflow-x: auto; overflow-y: hidden; }
  .user-row { min-width: 190px; border-right: 1px solid var(--line); border-bottom: 0; }
  .user-detail { min-height: 0; }
}

@media (max-width: 680px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 0 14px; }
  .brand { display: none; }
  .lesson-heading { gap: 8px; }
  .lesson-heading strong { font-size: 15px; }
  .topbar-status { gap: 10px; }
  .presence { padding-left: 10px; }
  .presence strong { font-size: 18px; }
  .console-grid { display: flex; flex-direction: column; gap: 1px; }
  .video-panel { order: 1; min-height: 300px; }
  .messages-panel { order: 2; height: 480px; }
  .users-panel { order: 3; height: 300px; }
  .video-stage { flex: 0 0 auto; aspect-ratio: 16 / 9; }
  .video-stage video { max-height: none; }
}
