:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #18212f;
  --muted: #687487;
  --border: #d7dde7;
  --accent: #16a34a;
  --accent-2: #0891b2;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --panel: #151b23;
    --panel-2: #10161d;
    --text: #e5edf7;
    --muted: #8b97a8;
    --border: #263241;
    --accent: #22c55e;
    --accent-2: #06b6d4;
    --warn: #f59e0b;
    --danger: #f87171;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

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

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 8px 24px;
  font-weight: 750;
  font-size: 20px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #05070a;
  background-image: url("/watchlink-icon-64.png");
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.22);
  overflow: hidden;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel-2);
  color: var(--text);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 8px 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.main {
  min-width: 0;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.title-block h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.title-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-row,
.stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.stat,
.panel,
.auth-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat {
  padding: 14px;
}

.stat span,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.good {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--accent);
}

.badge.warn {
  border-color: color-mix(in srgb, var(--warn) 45%, var(--border));
  color: var(--warn);
}

.badge.info {
  border-color: color-mix(in srgb, var(--accent-2) 45%, var(--border));
  color: var(--accent-2);
}

.badge.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger);
}

.room-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

.panel {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 14px;
}

.video-frame {
  position: relative;
  display: grid;
  min-height: 430px;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(34, 197, 94, 0.08), transparent 36%),
    #05070a;
}

.video-state {
  width: min(520px, 86%);
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 22px;
  background: rgba(15, 23, 42, 0.82);
  color: #e5edf7;
}

.media-embed {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 430px;
  border: 0;
  background: #05070a;
}

.twitch-embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.youtube-embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.player-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  background: rgba(5, 7, 10, 0.78);
  color: #e5edf7;
  text-align: center;
}

.player-overlay h2,
.player-overlay p {
  margin: 0;
}

.compact-overlay {
  inset: auto 16px 16px 16px;
  place-content: start;
  justify-items: start;
  border: 1px solid #263449;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.94);
  text-align: left;
}

.video-state h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.controls {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 12px;
}

.button,
.icon-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.rail-tabs button:hover:not(:disabled),
.tab:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent-2) 45%, var(--border));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.10);
}

.button:active:not(:disabled),
.icon-button:active:not(:disabled),
.rail-tabs button:active:not(:disabled),
.tab:active {
  transform: translateY(0) scale(0.98);
}

.button.primary {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  color: var(--accent);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.input {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 10px;
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.checkbox-grid {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0;
  padding: 10px;
}

.checkbox-grid legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 4px;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.inline-check {
  display: flex !important;
  align-items: center;
  gap: 8px !important;
  color: var(--text) !important;
}

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

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

.row:last-child {
  border-bottom: 0;
}

.row-title {
  display: grid;
  gap: 3px;
}

.row-main {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.row-title strong {
  font-size: 14px;
}

.row-title span {
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--avatar-color) 42%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--avatar-color) 18%, var(--panel));
  color: var(--avatar-color);
  font-weight: 800;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 140px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: left;
}

.table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 22px;
}

.form {
  display: grid;
  gap: 12px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-error {
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 10%, var(--panel));
  color: var(--danger);
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
}

.form-success {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  color: var(--accent);
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
}

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

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

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
  }

  .sidebar-user {
    display: none;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    white-space: nowrap;
  }

  .stats-grid,
  .controls {
    grid-template-columns: 1fr;
  }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-header h1 {
  margin: 4px 0 0;
  font-size: 28px;
  line-height: 1.15;
}

.toolbar,
.row-actions,
.account-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-tile {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.metric-tile.good {
  border-left-color: var(--accent);
}

.metric-tile.warn {
  border-left-color: var(--warn);
}

.metric-tile.danger {
  border-left-color: var(--danger);
}

.metric-tile.info {
  border-left-color: var(--accent-2);
}

.metric-top,
.metric-tile p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metric-tile strong {
  font-size: 28px;
  font-weight: 800;
}

.metric-tile p {
  margin: 0;
}

.overview-grid,
.rooms-layout,
.watch-console,
.split-grid {
  display: grid;
  gap: 18px;
}

.overview-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  margin-bottom: 18px;
}

.rooms-layout {
  grid-template-columns: 320px minmax(0, 1fr);
}

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

.split-grid,
.console-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.player-column,
.right-rail,
.people-list,
.queue-list,
.timeline-list,
.settings-list,
.action-list {
  display: grid;
  gap: 10px;
}

.player-panel .panel-body {
  padding: 0;
}

.transport-bar {
  display: grid;
  grid-template-columns: 38px 38px 38px minmax(180px, 1fr) auto;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 12px;
}

.provider-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.provider-note a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent-2);
  font-weight: 800;
}

.queue-row,
.timeline-item,
.action-row,
.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px;
}

.queue-row.active-row {
  border-color: color-mix(in srgb, var(--accent-2) 70%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-2) 28%, transparent);
}

.chat-messages {
  display: grid;
  max-height: 420px;
  gap: 10px;
  overflow: auto;
}

.timeline-item.interactive:hover,
.action-row:hover {
  border-color: color-mix(in srgb, var(--accent-2) 45%, var(--border));
}

.queue-index {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 7px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.queue-thumbnail {
  display: grid;
  width: 72px;
  aspect-ratio: 16 / 9;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #05070a;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
}

.queue-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.queue-row .row-title,
.timeline-item .row-title {
  min-width: 0;
  flex: 1;
}

.queue-row .row-title strong,
.timeline-item .row-title strong,
.action-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-row span,
.setting-row span {
  display: grid;
  gap: 2px;
}

.action-row small,
.setting-row small {
  color: var(--muted);
  font-size: 12px;
}

.tabs,
.rail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tab,
.rail-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 750;
}

.tab.active,
.rail-tabs button.active {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--accent);
}

.tab-count {
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #94a3b8;
}

.status-dot.good::before {
  background: var(--accent);
}

.status-dot.warn::before {
  background: var(--warn);
}

.status-dot.danger::before {
  background: var(--danger);
}

.status-dot.info::before {
  background: var(--accent-2);
}

.table-wrap {
  overflow-x: auto;
}

.compact-button,
.icon-button.compact {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.icon-button.danger {
  color: var(--danger);
}

.button.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger);
}

.text-link,
.inline-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 750;
}

.search-field {
  display: inline-flex;
  min-width: 220px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 7px 9px;
}

.search-field input,
.chat-input input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.compact-form {
  gap: 10px;
}

.sidebar {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  gap: 14px;
}

.sidebar-section {
  min-height: 0;
  border-top: 1px solid var(--border);
  padding: 14px 4px 0;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.room-nav-list {
  display: grid;
  gap: 6px;
}

.room-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 8px;
  padding: 8px;
}

.room-nav-item:hover {
  background: var(--panel-2);
}

.room-nav-item span:first-child,
.room-nav-meta {
  display: grid;
  gap: 3px;
}

.room-nav-item strong {
  font-size: 13px;
}

.room-nav-item small,
.sidebar-empty {
  color: var(--muted);
  font-size: 12px;
}

.room-nav-meta {
  justify-items: end;
}

.sidebar-user {
  margin-top: auto;
  position: relative;
}

.account-menu {
  margin-left: auto;
  position: relative;
}

.account-menu summary {
  list-style: none;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-menu-popover {
  position: absolute;
  right: 0;
  bottom: 38px;
  z-index: 20;
  display: grid;
  min-width: 170px;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 6px;
}

.account-menu-popover a,
.account-menu-popover button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 8px;
  text-align: left;
}

.account-menu-popover a:hover,
.account-menu-popover button:hover {
  background: var(--panel-2);
}

.instance-status {
  display: grid;
  gap: 7px;
  border-top: 1px solid var(--border);
  padding: 14px 8px 0;
}

.instance-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.instance-metrics span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.auth-shell {
  display: grid;
  width: min(920px, 100%);
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 18px;
}

.auth-intro {
  display: grid;
  align-content: center;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
}

.auth-intro .brand-mark {
  margin: 0;
}

.setup-checklist {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.setup-checklist div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setup-checklist span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
}

.profile-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  margin-top: 10px;
  padding: 9px;
  color: var(--muted);
}

.disabled-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1180px) {
  .overview-grid,
  .rooms-layout,
  .watch-console {
    grid-template-columns: 1fr;
  }

  .right-rail {
    order: 2;
  }
}

@media (max-width: 860px) {
  .metrics-grid,
  .split-grid,
  .console-grid,
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
  }

  .transport-bar {
    grid-template-columns: repeat(3, 38px) 1fr;
  }

  .transport-bar .button.primary {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .sidebar {
    min-height: auto;
  }

  .sidebar-section,
  .instance-status {
    display: none;
  }
}
