:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #111a2b;
  --panel-2: #0f1725;
  --panel-3: #162133;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #edf4ff;
  --muted: #97a6ba;
  --accent: #76a9ff;
  --accent-2: #8c7bff;
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top right, rgba(118, 169, 255, 0.11), transparent 30%),
    radial-gradient(circle at top left, rgba(140, 123, 255, 0.08), transparent 24%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
code {
  padding: 0.12rem 0.4rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 264px;
  padding: 20px 16px;
  background: rgba(11, 18, 32, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 30;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-badge {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(118, 169, 255, 0.28), rgba(118, 169, 255, 0.08));
  border: 1px solid rgba(118, 169, 255, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.brand-title {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-subtitle,
.small-copy,
.card-copy,
.muted,
.helper,
.table-note,
.status-copy {
  color: var(--muted);
}

.nav-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: 120ms ease;
}

.nav-link:hover,
.nav-link[data-active="true"] {
  color: var(--text);
  background: rgba(118, 169, 255, 0.08);
  border-color: rgba(118, 169, 255, 0.18);
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: inherit;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.badge-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-size: 0.82rem;
}

.badge-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--good);
  box-shadow: 0 0 0 5px rgba(52, 211, 153, 0.12);
}

.main-shell {
  margin-left: 264px;
  min-height: 100vh;
  padding: 28px 28px 100px;
}

.main-wrap {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  gap: 24px;
}

.hero-block {
  display: grid;
  gap: 6px;
}

.hero-title {
  margin: 0;
  font-size: clamp(1.9rem, 2.4vw, 2.9rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.hero-subtitle {
  margin: 0;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.card,
.stat-card,
.action-card,
.panel,
.stream-panel,
.log-panel,
.settings-card,
.surface {
  background: linear-gradient(180deg, rgba(17, 26, 43, 0.96), rgba(12, 19, 32, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
  display: grid;
  gap: 10px;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.section-title {
  margin: 0;
  font-size: 1.15rem;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.action-card {
  padding: 22px;
  display: grid;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.action-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top left, rgba(118, 169, 255, 0.18), transparent 38%);
  pointer-events: none;
}

.action-card:hover {
  transform: translateY(-2px);
  border-color: rgba(118, 169, 255, 0.22);
}

.action-icon {
  width: 50px;
  height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  font-size: 1.2rem;
}

.action-title {
  margin: 0;
  font-size: 1.06rem;
}

.rooms-list,
.history-list,
.info-list,
.log {
  display: grid;
  gap: 12px;
}

.room-row,
.history-row,
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.room-main,
.history-main {
  display: grid;
  gap: 6px;
}

.room-title,
.history-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.room-title strong,
.history-title strong {
  font-size: 0.98rem;
}

.room-meta,
.history-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.84rem;
}

.room-actions,
.history-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
  white-space: nowrap;
}

.pill[data-variant="active"] { border-color: rgba(52, 211, 153, 0.28); color: #aaf1cf; }
.pill[data-variant="waiting"] { border-color: rgba(251, 191, 36, 0.3); color: #f7d98d; }
.pill[data-variant="control"] { border-color: rgba(118, 169, 255, 0.28); color: #c9daff; }
.pill[data-variant="idle"] { border-color: rgba(255, 255, 255, 0.12); color: var(--muted); }
.pill[data-variant="danger"] { border-color: rgba(251, 113, 133, 0.28); color: #fbb5c4; }

.button,
button,
select,
input {
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

button:hover,
.button:hover,
input:hover,
select:hover,
input:focus,
select:focus {
  border-color: rgba(118, 169, 255, 0.28);
  outline: none;
}

button:disabled,
.button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.button.primary,
button.primary {
  background: linear-gradient(180deg, rgba(118, 169, 255, 0.22), rgba(118, 169, 255, 0.12));
  border-color: rgba(118, 169, 255, 0.28);
}

.button.subtle,
button.subtle {
  background: rgba(255, 255, 255, 0.03);
}

.button.danger,
button.danger {
  background: rgba(251, 113, 133, 0.08);
  border-color: rgba(251, 113, 133, 0.18);
}

.input,
input,
select,
textarea {
  width: 100%;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.04);
}

textarea {
  min-height: 110px;
  padding: 12px 14px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.stack {
  display: grid;
  gap: 14px;
}

.card-pad,
.panel-pad {
  padding: 20px;
}

.card-title {
  margin: 0;
  font-size: 1.06rem;
}

.inline-row,
.controls,
.toggle-row,
.viewer-toolbar,
.viewer-toolbar-secondary,
.segmented {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.toggle-row {
  align-items: flex-start;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin-top: 2px;
}

.preview-frame,
.stream-frame {
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #05070d;
}

video {
  width: 100%;
  display: block;
  background: #05070d;
}

.viewer-video {
  max-height: calc(100vh - 320px);
  object-fit: contain;
}

.viewer-stage-wrap {
  position: relative;
}

.video-viewport {
  position: relative;
  overflow: hidden;
  background: #05070d;
}

.video-stage {
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
}

.control-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: transparent;
}

.control-overlay.armed {
  box-shadow: inset 0 0 0 1px rgba(118, 169, 255, 0.72);
  cursor: crosshair;
}

.log {
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--line);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.log-entry + .log-entry {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 8px;
  margin-top: 8px;
}

.empty-state {
  padding: 28px;
  border-radius: 18px;
  border: 1px dashed var(--line-strong);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  text-align: center;
}

.kv-grid {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr;
  gap: 10px 16px;
}

.kv-grid dt {
  color: var(--muted);
}

.kv-grid dd {
  margin: 0;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: none;
  gap: 8px;
  justify-content: space-around;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.96);
  backdrop-filter: blur(16px);
}

.bottom-link {
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 12px;
}

.bottom-link[data-active="true"] {
  color: var(--text);
  background: rgba(118, 169, 255, 0.08);
}

.viewer-layout,
.broadcast-layout,
.settings-grid,
.history-grid {
  display: grid;
  gap: 16px;
}

.broadcast-layout {
  grid-template-columns: minmax(340px, 420px) 1fr;
}

.viewer-layout {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  align-items: start;
}

.history-grid,
.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented {
  padding: 4px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.segmented button {
  min-width: 120px;
  border: 0;
  background: transparent;
}

.segmented button.is-active {
  background: rgba(118, 169, 255, 0.12);
  border: 1px solid rgba(118, 169, 255, 0.14);
}

.zoom-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.launch-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.launch-card {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 12px;
}

.status-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

@media (max-width: 1180px) {
  .stats-grid,
  .launch-grid,
  .actions-grid,
  .history-grid,
  .settings-grid,
  .broadcast-layout,
  .viewer-layout,
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .viewer-layout > :first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 920px) {
  .sidebar {
    display: none;
  }
  .main-shell {
    margin-left: 0;
    padding: 20px 18px 96px;
  }
  .stats-grid,
  .launch-grid,
  .actions-grid,
  .history-grid,
  .settings-grid,
  .broadcast-layout,
  .viewer-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .bottom-nav {
    display: flex;
  }
}

@media (max-width: 640px) {
  .main-shell {
    padding-inline: 14px;
  }
  .hero-title {
    font-size: 1.72rem;
  }
  .room-row,
  .history-row,
  .status-banner,
  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .room-actions,
  .history-actions,
  .viewer-toolbar,
  .viewer-toolbar-secondary {
    width: 100%;
  }
  .room-actions > *,
  .history-actions > *,
  .viewer-toolbar > *,
  .viewer-toolbar-secondary > * {
    flex: 1 1 140px;
  }
  .viewer-video {
    max-height: calc(100vh - 420px);
  }
}
