:root {
  color-scheme: dark;
  --bg: #0f1419;
  --panel: #171d25;
  --panel-2: #1f2732;
  --text: #e8edf2;
  --muted: #9aa7b5;
  --accent: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --border: #2a3441;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-size: 0.85rem;
  color: var(--muted);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.95);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__brand a {
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
}

.topbar__meta { color: var(--muted); font-size: 0.9rem; }

.topbar__nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar__nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
}

.topbar__nav a:hover,
.topbar__nav a.is-active {
  color: var(--text);
  border-color: var(--border);
  background: var(--panel);
  text-decoration: none;
}

.topbar__nav a.is-active {
  border-color: rgba(59, 130, 246, 0.45);
}

.panel {
  margin-bottom: 24px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
}

.panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel__head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.panel__hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.hero__stat {
  margin-top: 8px;
  color: var(--ok);
}

.empty-state {
  color: var(--muted);
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.rtmp-cell code {
  display: block;
  margin-bottom: 8px;
  word-break: break-all;
  color: #bfdbfe;
}

.actions-cell {
  white-space: nowrap;
}

.admin-form--stack {
  display: block;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.checkbox-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
}

.checkbox-item input {
  margin-top: 4px;
}

.checkbox-item strong {
  display: block;
}

.room-card--static {
  display: block;
  position: relative;
}

.room-card__link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.room-card__link:hover {
  text-decoration: none;
}

.room-card__actions {
  padding: 0 18px 18px;
}

.btn--danger {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.btn--danger:hover {
  border-color: var(--err);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.hero { margin-bottom: 24px; }
.hero--compact {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.hero h1 { margin: 0 0 8px; font-size: 1.8rem; }
.hero p { margin: 0; color: var(--muted); }

.admin-panel {
  margin-bottom: 24px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
}

.admin-panel__head h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}

.admin-panel__head p {
  margin: 0 0 14px;
  color: var(--muted);
}

.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.admin-form__label {
  display: block;
  width: 100%;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: -4px;
}

.admin-form__input {
  flex: 1 1 240px;
  min-width: 200px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.admin-result,
.admin-error {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: var(--panel-2);
}

.admin-error {
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.admin-result__title {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.admin-result__meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.copy-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.copy-row code {
  word-break: break-all;
  color: #bfdbfe;
}

.hidden { display: none !important; }

.btn--primary {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.45);
}

.room-card--issued .room-card__rtmp {
  margin: 10px 0;
  font-size: 0.8rem;
  word-break: break-all;
}

.room-card--issued .room-card__rtmp code {
  color: #bfdbfe;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.room-card {
  display: block;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.room-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}

.room-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.room-card h2 { margin: 0; font-size: 1.2rem; }

.badge {
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}

.screen-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}

.screen-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--err);
  flex: 0 0 auto;
}

.status-dot--on { background: var(--ok); }
.status-dot--unknown { background: var(--warn); }

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}

.video-tile {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel);
}

.video-tile__header,
.video-tile__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.video-tile__header h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.tile-status {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.tile-status.is-live { color: var(--ok); }
.tile-status.is-error { color: var(--err); }

.video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

.video-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.95rem;
}

.video-overlay.hidden { display: none; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); }
.btn--small { padding: 6px 10px; font-size: 0.85rem; }
.btn--block { width: 100%; }

.viewer-page .topbar {
  padding: 10px 18px;
}

.viewer-main {
  max-width: none;
  margin: 0;
  padding: 0;
  height: calc(100vh - 49px);
  overflow: hidden;
}

.viewer-shell {
  --sidebar-width: 300px;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  transition: grid-template-columns 0.2s ease;
}

.viewer-shell--sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.stream-sidebar {
  width: var(--sidebar-width);
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  min-height: 0;
  overflow: hidden;
}

.stream-sidebar__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.stream-sidebar__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.stream-sidebar__head h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

.stream-sidebar__count {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 0 0 auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn--accent {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.35);
  color: #bfdbfe;
}

.icon-burger {
  position: relative;
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.icon-burger::before,
.icon-burger::after {
  content: "";
  position: absolute;
  left: 0;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.icon-burger::before { top: -5px; }
.icon-burger::after { top: 5px; }

.icon-plus {
  position: relative;
  display: block;
  width: 14px;
  height: 14px;
}

.icon-plus::before,
.icon-plus::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 1px;
}

.icon-plus::before {
  left: 6px;
  top: 0;
  width: 2px;
  height: 14px;
}

.icon-plus::after {
  left: 0;
  top: 6px;
  width: 14px;
  height: 2px;
}

.icon-close {
  position: relative;
  display: block;
  width: 14px;
  height: 14px;
}

.icon-close::before,
.icon-close::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  width: 2px;
  height: 14px;
  background: currentColor;
  border-radius: 1px;
}

.icon-close::before { transform: rotate(45deg); }
.icon-close::after { transform: rotate(-45deg); }

.viewer-stage__sidebar-open {
  display: none;
}

.viewer-shell--sidebar-collapsed .viewer-stage__sidebar-open {
  display: inline-flex;
}

.viewer-shell--sidebar-collapsed #sidebar-collapse {
  display: none;
}

.stream-sidebar__empty {
  margin: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.stream-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.stream-list__item {
  position: relative;
  margin-bottom: 4px;
}

.stream-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.stream-item:hover {
  background: var(--panel-2);
  border-color: var(--border);
}

.stream-item.is-active {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
}

.stream-item__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--err);
}

.stream-item__dot.is-live { background: var(--ok); }
.stream-item__dot.is-unknown { background: var(--warn); }

.stream-item__body {
  min-width: 0;
  flex: 1 1 auto;
}

.stream-item__title {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-item__key {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-item__delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.stream-list__item:hover .stream-item__delete {
  opacity: 1;
}

.stream-item__delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal__panel {
  position: relative;
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal__head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.viewer-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

.viewer-stage__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.viewer-stage__meta {
  min-width: 0;
  flex: 1 1 auto;
}

.viewer-stage__meta h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.viewer-stage__meta code {
  font-size: 0.8rem;
}

.viewer-stage__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.viewer-stage__status {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.viewer-stage__status.is-live { color: var(--ok); }
.viewer-stage__status.is-error { color: var(--err); }
.viewer-stage__status.is-waiting { color: var(--warn); }

.viewer-stage__video {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}

.viewer-stage__video video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
  pointer-events: none;
}

.viewer-stage__video video::-webkit-media-controls {
  display: none !important;
}

.video-fs-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(15, 20, 25, 0.72);
  color: #e8edf2;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.video-fs-btn:hover {
  background: rgba(31, 39, 50, 0.92);
  border-color: rgba(255, 255, 255, 0.4);
}

.video-fs-btn__icon {
  width: 18px;
  height: 18px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M8 3H3v5M16 3h5v5M16 21h5v-5M8 21H3v-5'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M8 3H3v5M16 3h5v5M16 21h5v-5M8 21H3v-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.viewer-stage__video:fullscreen,
.viewer-stage__video:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: #000;
}

.viewer-stage__video:fullscreen video,
.viewer-stage__video:-webkit-full-screen video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.viewer-stage__foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex: 0 0 auto;
}

.viewer-stage__rtmp {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.viewer-stage__foot-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.viewer-stage__rtmp code {
  flex: 1 1 auto;
  min-width: 200px;
  word-break: break-all;
  color: #bfdbfe;
}

.viewer-stage__empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

@media (max-width: 720px) {
  .viewer-shell {
    --sidebar-width: min(300px, 88vw);
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .viewer-shell--sidebar-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .topbar { flex-direction: column; align-items: flex-start; }
  .hero--compact { flex-direction: column; }
  .video-grid { grid-template-columns: 1fr; }
  .panel__head { flex-direction: column; align-items: flex-start; }
}

.login-main,
.users-page .container {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 16px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}

.login-panel h1 {
  margin: 0 0 8px;
}

.login-panel__hint {
  margin: 0 0 20px;
  color: var(--muted);
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__user {
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar__logout {
  margin: 0;
}

.users-panel {
  max-width: 900px;
  margin: 24px auto;
}

.users-form {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
}

.users-table th,
.users-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.users-table th {
  color: var(--muted);
  font-weight: 600;
}

.btn--danger {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}
