/* ============================================================
   BALO LIVE CLASSROOM — CLEAN MODERN REVISION (KEEP SAME LAYOUT)
   Scoped to #balo-live only — SAFE, NON-CONFLICTING
   ============================================================ */

#balo-live {
  --bg: #0b1224;
  --bg2: #0f172a;

  --panel: rgba(255,255,255,0.07);
  --panel2: rgba(255,255,255,0.04);

  --text: #e8eefc;
  --muted: #9fb3d9;

  --accent: #5ea1ff;
  --accent2: #48d2e2;

  --danger: #ef4444;
  --success: #22c55e;

  color: var(--text);
  background:
    radial-gradient(80% 60% at 20% 10%, rgba(94,161,255,0.08), transparent),
    radial-gradient(80% 60% at 80% 90%, rgba(72,210,226,0.08), transparent),
    linear-gradient(180deg, var(--bg), var(--bg2));

  border-radius: 16px;
  box-shadow: 0 10px 50px rgba(0,0,0,0.35);
  overflow: hidden;
}

/* Fullscreen fix */
#balo-live:fullscreen,
#balo-live:fullscreen .live-main,
#balo-live:fullscreen .live-stage {
  border-radius: 0;
}

/* ============================================================
   TOP BAR
   ============================================================ */
.live-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;

  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.live-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.live-brand {
  font-weight: 700;
  color: #fff;
}

.live-divider {
  opacity: 0.4;
}

.live-right .btn.only {
  padding: 8px;
}

/* ============================================================
   MAIN GRID LAYOUT
   ============================================================ */
.live-main {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 500px;
}

/* Sidebar */
.live-sidebar {
  background: rgba(255,255,255,0.04);
  border-right: 1px solid rgba(255,255,255,0.06);
  padding: 14px;
}

.live-sidebar[hidden] {
  display: none;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}

.tab:hover {
  background: rgba(255,255,255,0.09);
}

.tab.active {
  background: var(--panel);
  border-color: rgba(255,255,255,0.15);
}

/* Panels & Lists */
.panel {
  display: none;
}

.panel.show {
  display: block;
}

.list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.list li {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel2);
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.list .role {
  font-size: 12px;
  opacity: 0.8;
}

/* Host tools */
.host-tools {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn.sm {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 10px;
}

/* Chat */
.chat-log {
  background: var(--panel2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 10px;

  min-height: 240px;
  max-height: 340px;
  overflow-y: auto;
  font-size: 14px;
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chat-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.08);
  color: #fff;
}

/* Selects */
select {
  padding: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: #fff;
}

/* ============================================================
   VIDEO STAGE
   ============================================================ */
.live-stage {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  padding: 12px;
}

.tile {
  background: #0a1222;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  overflow: hidden;
  min-height: 160px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  position: relative;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0b162a;
}

.tile.self video {
  transform: scaleX(-1);
}

#balo-live .no-mirror #video-self {
  transform: none !important;
}

/* Nameplates */
.nameplate {
  position: absolute;
  bottom: 8px;
  left: 10px;

  font-size: 12px;
  padding: 4px 8px;
  border-radius: 10px;

  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(6px);

  color: #e7eefc;
}

/* Badges */
.badge-row {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
}

.badge {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 10px;

  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
}

.badge.role { background: rgba(94,161,255,0.18); border-color: rgba(94,161,255,0.35); }
.badge.hand { background: rgba(255,199,95,0.18); border-color: rgba(255,199,95,0.4); }
.badge.mic  { background: rgba(239,68,68,0.18); border-color: rgba(239,68,68,0.4); }
.badge.cam  { background: rgba(156,163,175,0.18); border-color: rgba(156,163,175,0.4); }

/* ============================================================
   TOOLBAR
   ============================================================ */
.live-toolbar {
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Buttons */
.btn {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;

  background: var(--panel);
  color: #fff;

  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;

  cursor: pointer;
  transition: 0.2s ease;
}

.btn:hover {
  box-shadow: 0 8px 22px rgba(30,64,175,0.25);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.btn.round {
  border-radius: 999px;
}

.btn.alert {
  background: rgba(239,68,68,0.22);
  border-color: rgba(239,68,68,0.4);
}

.btn.only svg {
  margin: 0;
}

.btn[aria-pressed="true"] {
  outline: 2px solid rgba(94,161,255,0.45);
}

.btn svg {
  width: 20px;
  height: 20px;
}

/* Speaker mode */
#balo-live.speaker .live-stage {
  grid-template-columns: 2fr 1fr;
}

#balo-live.speaker .tile:first-child {
  grid-column: 1 / -1;
  min-height: 320px;
}

/* Responsive */
@media (max-width: 980px) {
  .live-main {
    grid-template-columns: 1fr;
  }
  .live-sidebar {
    order: 2;
  }
}

/* ✅ IMPROVED: Mobile & iOS optimizations */
@media (max-width: 600px) {
  /* Better viewport for small phones */
  #balo-live {
    min-height: 100dvh; /* Dynamic viewport height for iOS */
    max-height: 100dvh;
    border-radius: 0; /* No rounded corners on mobile fullscreen */
  }

  /* Hide button text labels on mobile - icons only */
  .btn span {
    display: none;
  }

  /* Larger tap targets for toolbar buttons */
  .btn {
    min-width: 44px;
    min-height: 44px;
    padding: 12px;
    justify-content: center;
  }

  /* Make round buttons circular on mobile */
  .btn.round {
    width: 48px;
    height: 48px;
    padding: 0;
  }

  .btn svg {
    width: 22px;
    height: 22px;
  }

  /* Ensure video tiles are visible on small screens */
  .live-stage {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 8px;
    gap: 8px;
  }

  .tile {
    min-height: 200px; /* Bigger on phones */
  }

  /* Compact topbar on mobile */
  .live-topbar {
    padding: 8px 12px;
  }

  .live-left {
    font-size: 12px;
    gap: 6px;
  }

  .live-room {
    display: none; /* Hide room name on mobile to save space */
  }

  /* Optimize toolbar for mobile */
  .live-toolbar {
    flex-wrap: nowrap;
    justify-content: space-between;
    padding: 8px;
    gap: 4px;
  }

  .toolbar-left,
  .toolbar-right {
    gap: 4px;
  }

  .toolbar-center {
    gap: 6px;
  }

  /* Hide less essential buttons on very small screens */
  #btn-layout,
  #btn-captions,
  #btn-more {
    display: none;
  }

  /* Sidebar takes full width on mobile */
  .live-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px; /* Leave space for toolbar */
    z-index: 100;
    border-radius: 0;
    border-right: none;
  }

  /* Tabs scroll horizontally if needed */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari */
  #balo-live {
    /* Prevent rubber-band scrolling */
    overscroll-behavior: none;
  }

  video {
    /* Prevent full-page zoom on double-tap */
    touch-action: manipulation;
  }

  /* iOS fullscreen media controls fix */
  video::-webkit-media-controls-enclosure {
    display: none !important;
  }

  /* Fix for iOS safe area (notch) */
  .live-topbar {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .live-toolbar {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}

/* Tablet breakpoint (601px - 980px) */
@media (min-width: 601px) and (max-width: 980px) {
  /* Hide some button labels on tablets too */
  .toolbar-left .btn span,
  .toolbar-right .btn span {
    display: none;
  }

  .btn {
    padding: 10px;
  }

  .live-stage {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

/* Landscape orientation optimization for phones */
@media (max-width: 900px) and (orientation: landscape) {
  .live-sidebar {
    display: none !important; /* Force hide sidebar in landscape on small devices */
  }

  .live-main {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .live-stage {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    max-height: calc(100dvh - 100px);
    overflow-y: auto;
  }

  .tile {
    min-height: 120px;
  }

  /* Compact toolbar in landscape */
  .live-toolbar {
    padding: 4px 8px;
  }

  .btn.round {
    width: 40px;
    height: 40px;
  }

  /* Slim topbar */
  .live-topbar {
    padding: 4px 10px;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .btn,
  #balo-live {
    transition: none !important;
  }
}
