:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #2b384e;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #4f46e5;
  --primary-hover: #6366f1;
  --emerald: #10b981;
  --rose: #ef4444;
  --amber: #f59e0b;
  --sky: #0ea5e9;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.topbar {
  background: #0f172a;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.brand-logo {
  height: 38px;
  width: auto;
  border-radius: 6px;
  background: #ffffff;
  padding: 2px 5px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-titles {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: #e2e8f0;
  white-space: nowrap;
}

.pill-live {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fecaca;
}

.pill-waiting {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fde68a;
}

.pill-mode-b {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.5);
  color: #a7f3d0;
}

.pill-mode-c {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

.dot-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-emerald {
  background: #059669;
  color: #ffffff;
}
.btn-emerald:hover:not(:disabled) {
  background: #10b981;
}

.btn-danger {
  background: #dc2626;
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background: #ef4444;
}

.btn-amber {
  background: #d97706;
  color: #ffffff;
}
.btn-amber:hover:not(:disabled) {
  background: #f59e0b;
}

.btn-outline {
  background: var(--surface-2);
  color: #f1f5f9;
  border-color: #3b4b68;
}
.btn-outline:hover:not(:disabled) {
  background: #2b3a55;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 11px;
  border-radius: 7px;
}

/* Main Grid */
.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 14px;
  padding: 14px 16px 24px;
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 1100px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.card-pad {
  padding: 14px 16px;
}

/* Video Player Stage */
.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #020617;
  overflow: hidden;
}

.video-frame video,
.video-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  object-fit: contain;
  background: #020617;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at center, #1e293b 0%, #020617 75%);
  gap: 10px;
}

.video-placeholder h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.video-placeholder p {
  margin: 0;
  font-size: 13px;
  color: #cbd5e1;
  max-width: 520px;
  line-height: 1.5;
}

.video-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: #0f172a;
  border-top: 1px solid var(--border);
}

.node-selector-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #cbd5e1;
}

select,
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  background: #0b1220;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

/* Banners */
.pinned-banner {
  background: linear-gradient(90deg, rgba(79, 70, 229, 0.22), rgba(14, 165, 233, 0.16));
  border: 1px solid rgba(99, 102, 241, 0.55);
  border-radius: 12px;
  padding: 11px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.voice-broadcast-banner {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.2), rgba(6, 182, 212, 0.16));
  border: 1px solid rgba(16, 185, 129, 0.55);
  border-radius: 12px;
  padding: 11px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stage-callout-card {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(79, 70, 229, 0.2));
  border: 2px solid #10b981;
  border-radius: 14px;
  padding: 14px 16px;
}

/* Viewer Stage PiP Panel & Resizable Native-Aspect Camera */
.stage-size-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid #2b384e;
  border-radius: 9px;
  padding: 5px 9px;
}

.stage-size-bar input[type="range"] {
  width: 110px;
  accent-color: #10b981;
  cursor: pointer;
  padding: 0;
  border: 0;
  background: transparent;
}

.stage-preview-stage {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.stage-native-video {
  width: min(100%, calc(var(--stage-video-h, 360px) * var(--vid-ar, 1.3333)));
  height: auto;
  max-width: 100%;
  max-height: var(--stage-video-h, 360px);
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border-radius: 8px;
  background: #000000;
}

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

.stage-mini-box {
  background: #020617;
  border: 1px solid #334155;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.stage-mini-video-wrap {
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.stage-mini-box video {
  width: min(100%, calc(var(--viewer-stage-h, 360px) * var(--vid-ar, 1.3333)));
  height: auto;
  max-width: 100%;
  max-height: var(--viewer-stage-h, 360px);
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border-radius: 6px;
}

.stage-mini-label {
  padding: 8px 10px;
  background: #0f172a;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Host Control Panel */
.host-panel {
  background: linear-gradient(180deg, #131d35 0%, #0f172a 100%);
  border: 1px solid #3b4b75;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.host-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.mode-switch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 960px) {
  .mode-switch-grid {
    grid-template-columns: 1fr;
  }
}

.mode-card {
  background: #0b1220;
  border: 2px solid #2b384e;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  text-align: left;
  color: #f8fafc;
  transition: all 0.15s ease;
}

.mode-card.active-b {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}

.mode-card.active-c {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.mode-card.active-d {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.16);
}

.pill-mode-d {
  background: rgba(99, 102, 241, 0.22);
  border-color: rgba(129, 140, 248, 0.7);
  color: #c7d2fe;
}

.cluster-nodes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 820px) {
  .cluster-nodes-grid {
    grid-template-columns: 1fr;
  }
}

.node-box {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.node-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}

.dot-online { background: #10b981; }
.dot-offline { background: #ef4444; }

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: #1e293b;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #10b981, #38bdf8);
  transition: width 0.3s ease;
}

/* Right Column: Interactive Sidebar */
.right-col {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  height: calc(100vh - 88px);
  position: sticky;
  top: 72px;
}

@media (max-width: 1100px) {
  .right-col {
    height: 620px;
    position: static;
  }
}

.tabs-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #0f172a;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 11px 6px;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.tab-btn.active {
  color: #ffffff;
  border-bottom-color: #6366f1;
  background: rgba(99, 102, 241, 0.12);
}

.tab-badge {
  background: #334155;
  color: #f8fafc;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
}

.tab-btn.active .tab-badge {
  background: #4f46e5;
}

.tab-pane {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
}

.tab-pane.active {
  display: flex;
}

.scroll-feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.msg-item {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12.5px;
}

.msg-item.is-question {
  border-color: rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.07);
}

.msg-item.is-answered {
  opacity: 0.68;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.msg-author {
  font-weight: 800;
  font-size: 12px;
  color: #f8fafc;
}

.msg-inst {
  font-size: 10.5px;
  color: #94a3b8;
  font-weight: 500;
}

.msg-text {
  margin: 0;
  color: #e2e8f0;
  line-height: 1.45;
  word-break: break-word;
}

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 90;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 460px;
  background: #111827;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-box h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 800;
}

.modal-box p {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 11px;
}

.form-field label {
  font-size: 11.5px;
  font-weight: 700;
  color: #cbd5e1;
}

.toast-wrap {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #1e293b;
  color: #ffffff;
  border: 1px solid #475569;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  max-width: 340px;
}

.toast.ok { border-color: #10b981; background: #064e3b; }
.toast.err { border-color: #ef4444; background: #7f1d1d; }

.code-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #020617;
  border: 1px solid #334155;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 11.5px;
  color: #a5b4fc;
}

.hidden {
  display: none !important;
}
