/* ==============================
   Microsoft Teams Inspired Theme
   JCT Live Classroom
   ============================== */

/* ----- Design System ----- */
:root {
  /* Teams Primary Colors */
  --ms-primary: #6264A7;
  --ms-primary-hover: #4F4F82;
  --ms-primary-light: #E8E8F4;
  --ms-primary-dark: #464775;
  
  /* Backgrounds */
  --ms-bg: #F5F5F5;
  --ms-bg-dark: #292929;
  --ms-sidebar-bg: #2B2B40;
  --ms-sidebar-hover: #3D3D56;
  --ms-stage-bg: #1A1A2E;
  --ms-card-bg: #FFFFFF;
  --ms-panel-bg: #FFFFFF;
  
  /* Text */
  --ms-text: #242424;
  --ms-text-light: #616161;
  --ms-text-muted: #8A8886;
  --ms-text-inverse: #FFFFFF;
  
  /* Status */
  --ms-success: #92C353;
  --ms-warning: #F8D22A;
  --ms-danger: #C4314B;
  --ms-info: #4A90E2;
  
  /* Borders */
  --ms-border: #E1DFDD;
  --ms-border-light: #F0F0F0;
  
  /* Shadows */
  --ms-shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --ms-shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --ms-shadow-lg: 0 8px 24px rgba(0,0,0,0.16);
  
  /* Sizing */
  --sidebar-width: 64px;
  --sidebar-expanded: 240px;
  --topbar-height: 48px;
  --controlbar-height: 64px;
  --panel-width: 320px;
  
  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s ease;
  
  /* Font */
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  color: var(--ms-text);
  background: var(--ms-bg);
}

/* ----- Reset & Base ----- */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  background: var(--ms-bg);
  color: var(--ms-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #C8C6C4;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #A8A6A4;
}

/* ========================
   LAYOUT: Teams Shell
   ======================== */

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  max-width: none;
  margin: 0;
  padding: 0;
}

/* ----- Top Navigation Bar ----- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  background: var(--ms-sidebar-bg);
  color: var(--ms-text-inverse);
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--ms-primary);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.top-bar-title {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.2px;
}

.top-bar-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.12);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ms-danger);
  animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition-fast);
  margin: 0;
}

.top-bar-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
}

/* ----- Main Body (Sidebar + Content + Panel) ----- */
.main-body {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ----- Left Sidebar ----- */
.sidebar {
  width: var(--sidebar-expanded);
  background: var(--ms-sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-section {
  padding: 12px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 8px;
  padding: 0 8px;
}

.classes-sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.class-sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: rgba(255,255,255,0.75);
  font-size: 13px;
  transition: var(--transition-fast);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.class-sidebar-item:hover {
  background: var(--ms-sidebar-hover);
  color: #fff;
}

.class-sidebar-item.active {
  background: var(--ms-primary);
  color: #fff;
}

.class-sidebar-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.6);
  margin-left: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition-fast);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.sidebar-nav-item:hover {
  background: var(--ms-sidebar-hover);
  color: #fff;
}

.sidebar-nav-item.active {
  background: rgba(98, 100, 167, 0.3);
  color: #fff;
}

.sidebar-nav-icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-bottom {
  margin-top: auto;
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ----- Content Area ----- */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ms-bg-dark);
  color: rgba(255,255,255,0.9);
}

.content-area h2 {
  color: rgba(255,255,255,0.9);
}

.content-area .card {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
}

.content-area .card h2,
.content-area .card h3 {
  color: #fff;
}

.content-area .muted {
  color: rgba(255,255,255,0.5);
}

/* Theme switch: the existing dark interface is the default night mode. */
.theme-switch { display:inline-flex; align-items:center; gap:6px; color:rgba(255,255,255,.9); font-size:11px; user-select:none; cursor:pointer; }
.theme-switch input { position:absolute; opacity:0; pointer-events:none; }
.theme-slider { position:relative; width:32px; height:18px; border-radius:999px; background:rgba(255,255,255,.22); border:1px solid rgba(255,255,255,.3); transition:background .2s ease; }
.theme-slider::after { content:''; position:absolute; width:12px; height:12px; top:2px; left:2px; border-radius:50%; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,.25); transition:transform .2s ease; }
.theme-switch input:checked + .theme-slider { background:var(--ms-primary); }
.theme-switch input:checked + .theme-slider::after { transform:translateX(14px); }
.theme-label { min-width:31px; }

body.light-mode { --ms-bg:#f5f7fb; --ms-bg-dark:#eef1f6; --ms-sidebar-bg:#fff; --ms-sidebar-hover:#edf0f8; --ms-stage-bg:#e8ecf4; --ms-card-bg:#fff; --ms-panel-bg:#fff; --ms-text:#242424; --ms-text-light:#616161; --ms-text-muted:#6f7480; --ms-text-inverse:#242424; --ms-border:#d9dee8; --ms-border-light:#edf0f5; }
body.light-mode .top-bar { color:var(--ms-text); box-shadow:0 2px 8px rgba(31,41,55,.12); }
body.light-mode .top-bar-title, body.light-mode .top-bar-btn, body.light-mode .theme-switch { color:var(--ms-text); }
body.light-mode .top-bar-btn:hover { background:#edf0f8; }
body.light-mode .sidebar { color:var(--ms-text); border-right:1px solid var(--ms-border); }
body.light-mode .sidebar-nav-item { color:#4b5563; }
body.light-mode .sidebar-nav-item:hover { background:var(--ms-sidebar-hover); color:var(--ms-text); }
body.light-mode .sidebar-nav-item.active { background:var(--ms-primary-light); color:var(--ms-primary-dark); }
body.light-mode .sidebar-bottom { border-top-color:var(--ms-border-light); }
body.light-mode .content-area { color:var(--ms-text); }
body.light-mode .content-area h2, body.light-mode .content-area .card h2, body.light-mode .content-area .card h3 { color:var(--ms-text); }
body.light-mode .content-area .card { background:var(--ms-card-bg); border-color:var(--ms-border); color:var(--ms-text); }
body.light-mode .content-area .muted { color:var(--ms-text-muted); }
body.light-mode .stage-main { background:var(--ms-bg); }
body.light-mode .theme-switch-icon { color:#4b5563; }

/* ----- Stage (Video Area) ----- */
.stage-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.stage-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 8px;
}

/* Media Container (Teacher + Students) */
.media {
  flex: 1;
  min-height: 0;
  background: var(--ms-stage-bg);
  border-radius: var(--radius-lg);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  overflow: hidden;
  align-content: center;
  justify-content: center;
}

.media video {
  border-radius: var(--radius-md);
  background: #000;
  object-fit: cover;
}

/* Teacher video - larger, prominent */
.media video:first-child {
  width: calc(66.66% - 4px);
  min-height: 200px;
  max-height: calc(100% - 4px);
  border: 2px solid var(--ms-primary);
}

/* Student videos - gallery grid */
.media video:not(:first-child) {
  width: calc(33.33% - 4px);
  min-height: 100px;
  max-height: 180px;
}

/* Shared screens use the main canvas; camera video remains a small preview. */
.media:has(video.screen-share-video) {
  position: relative;
  align-content: stretch;
}

.media video.screen-share-video {
  order: -1;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  object-fit: contain;
  border: 0;
}

/* Full-page classroom mode keeps the bottom controls available to students. */
:fullscreen .shell {
  height: 100vh;
  width: 100vw;
}

:fullscreen .media video.screen-share-video {
  object-fit: contain;
}

.media:has(video.screen-share-video) video:not(.screen-share-video) {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 220px;
  height: 124px;
  min-height: 0;
  max-height: none;
  z-index: 2;
  border: 2px solid var(--ms-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.media audio {
  display: none;
}

.participant-tile {
  position: relative;
  flex: 1 1 calc(33.333% - 8px);
  min-width: 220px;
  min-height: 150px;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: #202033;
  border: 1px solid rgba(255,255,255,0.12);
}

.participant-tile video {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: none !important;
  object-fit: cover;
}

.participant-name {
  position: absolute;
  left: 10px;
  bottom: 8px;
  z-index: 4;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 5px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.participant-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: #fff;
}

.participant-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(145deg, #6264a7, #464775);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}

.participant-avatar[data-gender="male"] { background: linear-gradient(145deg, #2563eb, #1e3a8a); }
.participant-avatar[data-gender="female"] { background: linear-gradient(145deg, #db2777, #831843); }
.participant-avatar img { width: 100%; height: 100%; object-fit: cover; }

.media:has(video.screen-share-video) .participant-placeholder {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 3;
  width: 180px;
  min-width: 180px;
  height: 110px;
  min-height: 110px;
  flex: none;
}

.media:has(video.screen-share-video) .participant-placeholder .participant-avatar {
  width: 42px;
  height: 42px;
  font-size: 15px;
}

.media:has(video.screen-share-video) .participant-tile:has(video.screen-share-video) {
  position: absolute;
  inset: 4px;
  width: auto;
  height: auto;
  z-index: 1;
  border: 0;
}

.media:has(video.screen-share-video) .participant-tile:has(video.screen-share-video) video {
  object-fit: contain;
}

.media:has(video.screen-share-video) .participant-tile:not(.participant-placeholder):not(:has(video.screen-share-video)) {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 220px;
  height: 124px;
  min-width: 0;
  min-height: 0;
  z-index: 3;
  border: 2px solid var(--ms-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.media:has(video.screen-share-video) .participant-tile.local-preview {
  right: 16px;
  bottom: 16px;
  width: 240px;
  height: 135px;
  min-width: 160px;
  min-height: 90px;
  resize: both;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.media:has(video.screen-share-video) .participant-tile.local-preview::after {
  content: 'Drag to move · Resize corner';
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 5;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.media:has(video.screen-share-video) .participant-tile.local-preview:hover::after {
  opacity: 1;
}

/* Media Status Bar */
.media-status {
  padding: 8px 16px;
  background: rgba(98, 100, 167, 0.1);
  color: var(--ms-primary);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  margin: 0 8px 8px;
  text-align: center;
}

/* ----- Right Panel (Chat / People / Polls) ----- */
.right-panel {
  width: var(--panel-width);
  background: var(--ms-panel-bg);
  border-left: 1px solid var(--ms-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition-normal), opacity var(--transition-normal);
}

.right-panel.hidden {
  width: 0;
  opacity: 0;
  overflow: hidden;
  border: none;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--ms-border);
  background: #FAF9F8;
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  padding: 10px 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--ms-text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  transition: var(--transition-fast);
  margin: 0;
}

.panel-tab:hover {
  color: var(--ms-text);
  background: var(--ms-border-light);
}

.panel-tab.active {
  color: var(--ms-primary);
  border-bottom-color: var(--ms-primary);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.panel-content.hidden {
  display: none;
}

/* Panel Toggle Button */
.panel-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--ms-card-bg);
  border: 1px solid var(--ms-border);
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  padding: 8px 4px;
  cursor: pointer;
  z-index: 10;
  color: var(--ms-text-muted);
  font-size: 16px;
  transition: var(--transition-fast);
  margin: 0;
}
.panel-toggle {
  width: 28px;
  min-width: 28px;
  text-align: center;
  line-height: 1;
}
.panel-toggle:hover {
  color: var(--ms-primary);
}
.panel-toggle.close {
  right: var(--panel-width);
}

/* ----- Bottom Controls Bar ----- */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--controlbar-height);
  background: var(--ms-card-bg);
  border-top: 1px solid var(--ms-border);
  flex-shrink: 0;
  padding: 0 16px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

/* Chrome displays its own screen-sharing bar at the bottom of the window.
   Lift the classroom controls above it while sharing is active. */
body.screen-share-active .control-bar {
  transform: translateY(calc(-1 * var(--controlbar-height)));
  position: relative;
  z-index: 110;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.12);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.control-divider {
  width: 1px;
  height: 32px;
  background: var(--ms-border);
  margin: 0 8px;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ms-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  margin: 0;
  white-space: nowrap;
}

.control-btn:hover {
  background: var(--ms-border-light);
}

.control-btn.active {
  background: var(--ms-primary-light);
  color: var(--ms-primary);
}

.control-btn.recording {
  background: #c4314b;
  color: #fff;
  animation: recording-pulse 1.2s ease-in-out infinite;
}

.control-btn.recording .control-btn-icon {
  color: #fff;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196,49,75,0.35); }
  50% { box-shadow: 0 0 0 6px rgba(196,49,75,0.08); }
}

.control-btn.primary-btn {
  background: var(--ms-primary);
  color: #fff;
}
.control-btn.primary-btn:hover {
  background: var(--ms-primary-hover);
}

.control-btn.danger-btn {
  background: var(--ms-danger);
  color: #fff;
}
.control-btn.danger-btn:hover {
  background: #A82A3F;
}

.control-btn.danger-btn.class-running {
  background: var(--ms-danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(196, 49, 75, 0.28);
}

.control-btn.danger-btn.class-running:hover {
  background: #A82A3F;
}

.control-btn.danger-btn.class-left,
.control-btn.danger-btn.class-left:disabled {
  background: #e1dfdd;
  color: #797775;
  opacity: 0.82;
  cursor: not-allowed;
  box-shadow: none;
}

.control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.control-btn-icon {
  font-size: 18px;
  line-height: 1;
}

/* ----- Grid Layout for Content Pages ----- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* ----- Cards ----- */
.card {
  background: var(--ms-card-bg);
  border: 1px solid var(--ms-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--ms-shadow-sm);
}

/* ----- Header, Toolbar ----- */
header {
  display: none; /* Replaced by top-bar */
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ----- Headings ----- */
h1 {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 600;
  color: var(--ms-text);
}

h2 {
  margin-top: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--ms-text);
}

h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--ms-text);
  margin: 0 0 8px;
}

/* ----- Forms ----- */
input, select, textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  margin: 6px 0;
  border: 1px solid var(--ms-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--ms-text);
  background: #fff;
  transition: var(--transition-fast);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ms-primary);
  box-shadow: 0 0 0 2px rgba(98, 100, 167, 0.15);
}

input::placeholder {
  color: var(--ms-text-muted);
}

button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  background: var(--ms-primary);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition-fast);
  margin: 4px 4px 4px 0;
  font-family: inherit;
  line-height: 1.4;
}

button:hover {
  background: var(--ms-primary-hover);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.secondary {
  background: #E1DFDD;
  color: var(--ms-text);
}
button.secondary:hover {
  background: #C8C6C4;
}

button.danger {
  background: var(--ms-danger);
  color: #fff;
}
button.danger:hover {
  background: #A82A3F;
}

/* ----- Error / Muted / Status ----- */
.error {
  color: var(--ms-danger);
}

.muted {
  color: var(--ms-text-muted);
  font-size: 13px;
}

.form-message {
  color: var(--ms-primary);
  margin-left: 8px;
  font-size: 13px;
}

/* ========================
   CHAT STYLES
   ======================== */

.activity {
  min-height: 100px;
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
}

.chat-empty {
  text-align: center;
  color: var(--ms-text-muted);
  padding: 40px 20px;
  font-size: 13px;
}

.chat-message {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: #F8F8F8;
  transition: var(--transition-fast);
}

.chat-message:hover {
  background: #F0F0F0;
}

.chat-message-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-message-heading strong {
  font-size: 13px;
  font-weight: 600;
}

.chat-message-heading small {
  margin-left: auto;
  color: var(--ms-text-muted);
  font-size: 11px;
}

.chat-message p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ms-text-light);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.chat-role {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: #E1DFDD;
  color: var(--ms-text-light);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.chat-role.teacher {
  background: var(--ms-primary-light);
  color: var(--ms-primary);
  font-weight: 600;
}

.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--ms-border);
  background: #FAF9F8;
}

.chat-input-area input {
  margin: 0;
  flex: 1;
  border-radius: var(--radius-full);
  padding: 8px 14px;
  border: 1px solid var(--ms-border);
  background: #fff;
}

.chat-input-area button {
  margin: 0;
  flex-shrink: 0;
}

/* ========================
   PARTICIPANTS LIST
   ======================== */

.participants {
  border: none;
  padding: 0;
  margin: 0;
}

.participants > strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ms-text);
  margin-bottom: 8px;
  padding: 0 4px;
}

.participant-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--ms-border-light);
}

.participant-row:last-child {
  border-bottom: none;
}

.participant-row span:first-child {
  font-size: 13px;
  font-weight: 500;
  color: var(--ms-text);
}

.participant-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: #E1DFDD;
  color: var(--ms-text-light);
}

.participant-badge.teacher {
  background: var(--ms-primary-light);
  color: var(--ms-primary);
  font-weight: 600;
}

/* ========================
   POLLS
   ======================== */

.poll {
  border: 1px solid var(--ms-border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 8px 0;
  background: #FAF9F8;
}

.poll strong {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ms-text);
}

.poll button {
  margin: 4px 4px 4px 0;
}

/* ========================
   NOTIFICATIONS
   ======================== */

.notifications {
  margin-bottom: 14px;
}

.notification {
  border: 1px solid var(--ms-border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 8px 0;
  background: #F0F4FF;
  transition: var(--transition-fast);
}

.notification.read {
  background: #fff;
  color: var(--ms-text-muted);
}

.notification p {
  margin: 5px 0;
  font-size: 13px;
}

.notification strong {
  font-size: 14px;
  font-weight: 600;
}

.notification small {
  display: block;
  color: var(--ms-text-muted);
  font-size: 12px;
  margin-bottom: 7px;
}

/* ========================
   DASHBOARD / ADMIN
   ======================== */

.dashboard {
  margin-bottom: 14px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.metric {
  border: 1px solid var(--ms-border);
  border-radius: var(--radius-md);
  padding: 14px;
  background: #FAF9F8;
  text-align: center;
}

.metric strong {
  display: block;
  font-size: 26px;
  font-weight: 700;
  color: var(--ms-primary);
}

.metric span {
  display: block;
  font-size: 12px;
  color: var(--ms-text-muted);
  margin-top: 4px;
}

.admin-badge {
  background: var(--ms-primary);
  color: white;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 18px;
}

.form-grid label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ms-text-light);
}

.admin-table-wrap {
  margin-top: 20px;
}

.admin-row {
  display: grid;
  grid-template-columns: 2fr 1.1fr 1.2fr 2.4fr;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--ms-border-light);
  padding: 12px 0;
}

.admin-row small {
  display: block;
  color: var(--ms-text-muted);
  font-size: 12px;
}

.admin-user-row {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1fr;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--ms-border-light);
  padding: 12px 0;
}

.admin-user-row small {
  display: block;
  color: var(--ms-text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-user-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-user-search input {
  flex: 1;
  margin: 0;
}

.admin-reports {
  margin-top: 16px;
}

.report-card {
  border: 1px solid var(--ms-border);
  border-radius: var(--radius-md);
  padding: 10px;
  margin-top: 8px;
  font-size: 13px;
}

/* ========================
   CLASS ITEMS (on dark background)
   ======================== */

.class {
  border: 1px solid rgba(255,255,255,0.12);
  padding: 14px;
  border-radius: var(--radius-md);
  margin: 8px 0;
  background: rgba(255,255,255,0.05);
  transition: var(--transition-fast);
}

.class:hover {
  border-color: var(--ms-primary);
  background: rgba(255,255,255,0.08);
}

.class strong {
  font-size: 14px;
  font-weight: 600;
  display: block;
  color: #fff;
}

.class small {
  display: block;
  color: rgba(255,255,255,0.55);
  font-size: 12px;
  margin: 4px 0 8px;
}

/* ========================
   TEACHER CONTROLS (Sidebar)
   ======================== */

.teacher-workspace {
  margin-bottom: 12px;
}

.teacher-actions {
  margin-top: 10px;
}

.teacher-actions > strong {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: #fff;
}

.teacher-class-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.teacher-class-action button {
  flex: 0 0 auto;
  padding: 6px 8px;
  font-size: 11px;
}

.shell.sidebar-collapsed .teacher-actions {
  display: none;
}

.teacher-class-action strong {
  color: #fff;
}

.teacher-class-action .muted {
  color: rgba(255,255,255,0.5);
}

/* ========================
   KEY MANAGEMENT
   ======================== */

.key-management {
  border-top: 4px solid var(--ms-primary);
}

.generated-key {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--ms-warning);
  background: #FFFBE6;
  border-radius: var(--radius-md);
}

.generated-key strong {
  display: block;
  color: #8A6D00;
}

.generated-key input {
  font-family: monospace;
  background: #fff;
}

.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--ms-border-light);
  padding: 12px 0;
}

.key-row small {
  display: block;
  color: var(--ms-text-muted);
  margin-top: 4px;
}

/* ========================
   EVENT ITEM
   ======================== */

.event {
  padding: 7px;
  border-bottom: 1px solid var(--ms-border-light);
}

/* ========================
   TEACHER CONTROLS (In-Class)
   ======================== */

#teacherControls {
  padding: 12px;
  background: #FAF9F8;
  border-radius: var(--radius-md);
  border: 1px solid var(--ms-border);
  margin-top: 12px;
}

#teacherControls h3 {
  margin-bottom: 12px;
}

#teacherControls hr {
  border: none;
  border-top: 1px solid var(--ms-border);
  margin: 12px 0;
}

#teacherControls input {
  margin-bottom: 8px;
}

#teacherControls:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-top: 8px;
}

#teacherControls:not([hidden]) h3 {
  margin: 0 auto 0 0;
  white-space: nowrap;
  font-size: 14px;
}

#teacherControls:not([hidden]) input {
  width: 220px;
  margin: 0;
}

#teacherControls:not([hidden]) > div {
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
}

.teacher-controls-toggle {
  margin: 0;
  white-space: nowrap;
}

#teacherControls.controls-collapsed h3,
#teacherControls.controls-collapsed input,
#teacherControls.controls-collapsed > div {
  display: none !important;
}

/* ========================
   LOGIN / REDIRECT SCREEN
   ======================== */

.redirecting {
  text-align: center;
  padding: 54px 32px;
  max-width: 560px;
  margin: auto;
  border: 0;
  box-shadow: 0 22px 60px rgba(15,23,42,0.12);
}

.redirect-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--ms-primary-dark), var(--ms-primary));
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 12px 28px rgba(98, 100, 167, 0.28);
}

.redirecting h2 {
  margin: 0 0 10px;
  color: var(--ms-text);
  font-size: 28px;
}

.redirect-message {
  color: var(--ms-text-muted);
  font-size: 16px;
  line-height: 1.6;
}

.loading-spinner {
  width: 34px;
  height: 34px;
  margin: 24px auto 4px;
  border: 4px solid #E1DFDD;
  border-top-color: var(--ms-primary);
  border-radius: 50%;
  animation: jct-spin 0.9s linear infinite;
}

@keyframes jct-spin {
  to { transform: rotate(360deg); }
}

.redirecting .secondary {
  margin-top: 14px;
}

body.is-connecting {
  min-height: 100vh;
  background: radial-gradient(circle at top, #F0F4FF 0%, #F8F8F8 42%, #EEF2F7 100%);
}

body.is-connecting .shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.is-connecting header {
  display: none;
}

/* ========================
   RESPONSIVE
   ======================== */

@media (max-width: 1100px) {
  .right-panel {
    width: 280px;
  }
  .panel-toggle.close {
    right: 280px;
  }
}

@media (max-width: 900px) {
  .sidebar {
    width: 56px;
    overflow: hidden;
  }
  .sidebar-nav-item span:not(.sidebar-nav-icon) {
    display: none;
  }
  .sidebar-section-title {
    font-size: 0;
  }
  .class-sidebar-item span:not(.class-sidebar-status) {
    display: none;
  }
  
  .media video:first-child {
    width: 100%;
  }
  .media video:not(:first-child) {
    width: calc(50% - 4px);
  }
}

@media (max-width: 768px) {
  .right-panel {
    display: none;
  }
  .panel-toggle {
    display: none;
  }
  
  .control-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px;
    gap: 4px;
  }
  
  .media video:first-child {
    width: 100%;
  }
  .media video:not(:first-child) {
    width: 100%;
  }
  
  .grid {
    grid-template-columns: 1fr;
  }
  
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .admin-row,
  .admin-user-row {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    display: none;
  }
}

/* Left menu toggle */
.sidebar-toggle {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
  background: rgba(255,255,255,0.22);
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 2px;
}

.shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-width);
}

.shell.sidebar-collapsed .sidebar-nav-item {
  justify-content: center;
  gap: 0;
  padding-left: 8px;
  padding-right: 8px;
}

.shell.sidebar-collapsed .sidebar-nav-item > span:not(.sidebar-nav-icon),
.shell.sidebar-collapsed .sidebar-section-title,
.shell.sidebar-collapsed .class-sidebar-item > span:not(.class-sidebar-status),
.shell.sidebar-collapsed .class-sidebar-status {
  display: none;
}

.shell.sidebar-collapsed .sidebar-section,
.shell.sidebar-collapsed .sidebar-nav {
  padding-left: 8px;
  padding-right: 8px;
}

@media (max-width: 768px) {
  .control-bar {
    flex-wrap: nowrap !important;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    white-space: nowrap;
  }

  .control-bar .control-group,
  .control-bar .control-divider {
    flex: 0 0 auto;
  }

  .control-bar .control-divider {
    margin-left: 4px;
    margin-right: 4px;
  }

  .main-body {
    position: relative;
  }

  .content-area {
    width: 100%;
    min-width: 100%;
  }

  .shell.sidebar-collapsed .sidebar {
    display: none;
  }

  .shell:not(.sidebar-collapsed) .sidebar {
    display: flex;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    margin: 0;
    width: min(280px, 84vw);
    z-index: 150;
    box-shadow: 8px 0 24px rgba(0,0,0,0.35);
  }

  .shell:not(.sidebar-collapsed) .sidebar-nav-item span:not(.sidebar-nav-icon),
  .shell:not(.sidebar-collapsed) .class-sidebar-item span:not(.class-sidebar-status) {
    display: inline;
  }

  .shell:not(.sidebar-collapsed) .sidebar-section-title {
    font-size: 11px;
  }

  .sidebar-toggle { display: inline-flex; }
}

/* Responsive participant gallery. A large class remains scrollable instead of
   shrinking every preview until names and faces become unreadable. Screen
   sharing keeps its dedicated presentation layout above. */
.media:not(:has(video.screen-share-video)) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  grid-auto-rows: minmax(140px, auto);
  align-content: start;
  justify-content: stretch;
  overflow: auto;
  padding: clamp(8px, 1.2vw, 18px);
  gap: clamp(8px, 1vw, 14px);
}

.media:not(:has(video.screen-share-video)) .participant-tile {
  position: relative !important;
  inset: auto !important;
  right: auto !important;
  bottom: auto !important;
  width: auto !important;
  height: auto !important;
  min-width: 0;
  min-height: 140px;
  aspect-ratio: 16 / 9;
  flex: none;
}

.media:not(:has(video.screen-share-video)) .participant-tile video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

.media:not(:has(video.screen-share-video)) .participant-placeholder {
  display: flex;
}

@media (max-width: 700px) {
  .media:not(:has(video.screen-share-video)) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .media:not(:has(video.screen-share-video)) .participant-tile {
    min-height: 104px;
  }
}

/* Keep the compact bottom controls icon-only for camera, microphone, and hand. */
#controlBar #camera span:last-child,
#controlBar #microphone span:last-child,
#controlBar #handBtn span:last-child {
  display: none;
}

#controlBar #camera,
#controlBar #microphone,
#controlBar #handBtn {
  min-width: 44px;
  width: 44px;
  padding-left: 8px;
  padding-right: 8px;
}

@media (max-width: 420px) {
  .media:not(:has(video.screen-share-video)) {
    grid-template-columns: 1fr;
  }
}

.chat-attachment-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 0;
}

.chat-attachment-area button {
  flex: 0 0 auto;
}

/* Use the paperclip button as the only visible file-picker control. */
#chatFile {
  display: none !important;
}

.chat-attachment-area #chatFileButton {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
}

.chat-attachment-area .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.chat-file-card {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--ms-border);
  border-radius: 8px;
  background: rgba(98, 100, 167, 0.06);
}

.chat-file-card span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.chat-file-card button {
  padding: 6px 8px;
  font-size: 12px;
  flex: 0 0 auto;
}

.icon-only-button,
.chat-file-card button {
  width: 34px;
  height: 32px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0 !important;
}

.icon-only-button {
  font-size: 18px !important;
}

.chat-file-card button::before {
  font-size: 17px;
  line-height: 1;
}

.chat-file-card button:first-of-type::before {
  content: '⇩';
}

.chat-file-card button:last-of-type::before {
  content: '🗑';
}

/* Phone and tablet classroom layout */
@media (max-width: 768px) {
  .shell {
    height: 100dvh;
    min-height: 100dvh;
  }

  .top-bar {
    height: 52px;
    padding: 0 8px;
    gap: 6px;
  }

  .top-bar-left,
  .top-bar-right {
    gap: 6px;
    min-width: 0;
  }

  .top-bar-title {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-bar-btn {
    width: 32px;
    height: 32px;
    padding: 0;
  }

  .status {
    display: none;
  }

  .main-body,
  .content-area,
  .stage-area,
  .stage-main {
    min-width: 0;
    min-height: 0;
  }

  .stage-main {
    padding: 4px;
  }

  .media {
    border-radius: 10px;
    padding: 6px;
    gap: 6px;
  }

  .control-bar {
    min-height: 60px;
    padding: 6px 4px;
    gap: 3px;
    overflow-x: auto;
    justify-content: flex-start;
  }

  .control-group {
    flex: 0 0 auto;
  }

  .control-btn {
    min-width: 58px;
    padding: 7px 8px;
    font-size: 11px;
  }

  .control-btn-icon {
    font-size: 16px;
  }

  .control-divider {
    height: 28px;
    margin: 0 2px;
  }

  .panel-toggle {
    display: flex;
    right: 0;
    top: 50%;
    z-index: 161;
  }

  .right-panel {
    display: none !important;
  }

  .shell.mobile-panel-open .right-panel {
    display: flex !important;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(360px, 92vw);
    z-index: 160;
    box-shadow: -8px 0 24px rgba(0,0,0,0.35);
  }

  .shell.mobile-panel-open .panel-toggle {
    right: min(360px, 92vw);
  }

  .chat-input-area {
    padding: 8px;
  }

  .chat-attachment-area {
    padding: 8px;
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .top-bar-brand .brand-icon {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .top-bar-title {
    display: none;
  }

  .live-indicator {
    font-size: 11px;
    padding: 4px 7px;
  }

  .media:not(:has(video.screen-share-video)) .participant-tile {
    min-height: 112px;
  }

  .control-btn {
    min-width: 52px;
    padding-left: 5px;
    padding-right: 5px;
  }

  .control-btn span:last-child {
    max-width: 52px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Keep chat history scrollable while the composer stays at the bottom. */
#panel-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

#panel-chat.hidden {
  display: none;
}

#panel-chat .activity {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 12px;
}

#panel-chat .chat-input-area,
#panel-chat .chat-attachment-area,
#panel-chat #hand {
  flex: 0 0 auto;
}

#panel-chat .chat-attachment-area {
  padding: 6px 12px;
  border-top: 1px solid var(--ms-border);
  background: #FAF9F8;
}

#panel-chat #hand {
  margin: 0 12px 12px !important;
}

/* Keep the side-panel handle out of the middle of the lesson area. */
.panel-toggle,
.panel-toggle.close {
  top: 8px;
  bottom: auto;
  transform: none;
}

/* Professional side-panel handle */
.panel-toggle,
.panel-toggle.close {
  right: 10px;
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  background: #3b3a63;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.panel-toggle:hover,
.panel-toggle:focus-visible {
  background: var(--ms-primary);
  color: #fff;
  border-color: rgba(255,255,255,0.45);
  outline: none;
  transform: translateY(-1px);
}

.panel-toggle.close {
  right: calc(var(--panel-width) + 10px);
}

@media (max-width: 768px) {
  .panel-toggle,
  .panel-toggle.close {
    right: 10px;
    top: 10px;
  }

  .shell.mobile-panel-open .panel-toggle {
    right: calc(min(360px, 92vw) + 10px);
  }
}

/* Fit the complete classroom control set on one mobile screen. */
@media (max-width: 768px) {
  .control-bar {
    height: 56px;
    min-height: 56px;
    width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
    gap: 0;
    padding: 4px 6px;
    overflow: hidden;
  }

  .control-bar .control-group {
    display: contents;
  }

  .control-bar .control-divider {
    display: none;
  }

  .control-bar .control-btn {
    flex: 1 1 0;
    min-width: 0 !important;
    width: auto !important;
    height: 46px;
    padding: 5px 2px;
    gap: 0;
    border-radius: 8px;
  }

  .control-bar .control-btn span:last-child {
    display: none;
  }

  .control-bar .control-btn-icon {
    font-size: 17px;
  }
}
