:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface2: #eef2f7;
  --surface3: #f8fafc;
  --ink: #18202f;
  --muted: #5f6b7e;
  --faint: #8893a5;
  --line: #d9dfeb;
  --soft: #eef2f7;
  --green: #2db87a;
  --green-deep: #167047;
  --blue: #2463a6;
  --blue-soft: rgba(36, 99, 166, 0.12);
  --red: #d84a4a;
  --red-soft: rgba(216, 74, 74, 0.12);
  --amber: #a66a00;
  --amber-soft: rgba(232, 162, 26, 0.12);
  --shadow: 0 8px 22px rgba(20, 28, 42, 0.08);
  --topbar-bg: rgba(255, 255, 255, 0.94);
  --radius: 8px;
}

html[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171b24;
  --surface2: #202636;
  --surface3: #121620;
  --ink: #edf0f7;
  --muted: #9aa4b7;
  --faint: #69748a;
  --line: #2b3242;
  --soft: #202636;
  --green: #2db87a;
  --green-deep: #2db87a;
  --blue: #4d8dff;
  --blue-soft: rgba(77, 141, 255, 0.14);
  --red: #d84a4a;
  --red-soft: rgba(216, 74, 74, 0.12);
  --amber: #e8a21a;
  --amber-soft: rgba(232, 162, 26, 0.12);
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.26);
  --topbar-bg: rgba(23, 27, 36, 0.96);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.topbar-inner {
  width: min(1560px, calc(100% - 44px));
  min-height: 64px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 22px;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: var(--radius);
  background: var(--surface2);
  color: #fff;
  font-weight: 900;
}

.brand-logo {
  width: 52px;
  height: 42px;
  flex-basis: 52px;
  background: transparent;
  color: inherit;
  border-radius: 0;
}

.brand-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand small,
.muted {
  color: var(--muted);
}

.nav-links,
.subnav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-links {
  justify-content: center;
}

.nav-links a,
.subnav a,
.account-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-links a:hover,
.subnav a:hover,
.account-pill:hover,
.nav-links a.active,
.subnav a.active,
.account-pill.active {
  background: var(--blue-soft);
  color: var(--ink);
}

.nav-links a:hover,
.subnav a:hover {
  transform: translateY(-1px);
}

.nav-links svg,
.subnav svg,
.button svg,
.icon-button svg,
.notice-bar svg,
.account-pill svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.account-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle {
  width: 36px;
  height: 36px;
}

.theme-toggle.active {
  color: var(--amber);
  border-color: rgba(232, 162, 26, 0.36);
  background: var(--amber-soft);
}

.page,
.page-narrow {
  width: min(1560px, calc(100% - 44px));
  margin: 0 auto;
  padding: 22px 0 60px;
  flex: 1;
}

.page-narrow {
  width: min(740px, calc(100% - 32px));
}

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

.page-title h1,
.login-card h1,
.empty-state h1 {
  margin: 0;
  font-size: 2.1rem;
  line-height: 1.08;
}

.page-title p,
.empty-state p {
  margin: 8px 0 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

.surface,
.stream-card,
.empty-state,
.storage-panel,
.notice-bar,
.stat-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.surface,
.empty-state {
  padding: 18px;
}

.storage-panel {
  padding: 16px;
  margin: 16px 0;
}

.storage-topline,
.section-heading,
.list-row,
.stream-card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.storage-available {
  text-align: right;
}

.storage-available strong {
  display: block;
  color: var(--green);
  font-size: 1.6rem;
  line-height: 1;
}

.storage-available span,
.storage-metrics span,
.list-row span {
  color: var(--muted);
  font-size: 0.92rem;
}

.storage-meter {
  height: 5px;
  margin: 13px 0 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface2);
}

.storage-meter span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 250ms ease;
}

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

.storage-metrics div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface3);
}

.storage-metrics strong {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.notice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 20px;
  padding: 13px 15px;
  background: var(--blue-soft);
  color: var(--ink);
  box-shadow: none;
}

.notice-bar a,
.text-link {
  color: var(--blue);
  font-weight: 900;
  text-decoration: none;
}

.notice-bar a {
  margin-left: auto;
}

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

.stat-tile {
  display: grid;
  gap: 4px;
  min-height: 118px;
  padding: 16px;
  text-decoration: none;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.stat-tile:hover,
.stream-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 34px rgba(31, 41, 51, 0.11);
}

.stat-tile span {
  color: var(--muted);
  font-weight: 800;
}

.stat-tile strong {
  font-size: clamp(22px, 2.1vw, 30px);
  line-height: 1;
}

.two-column,
.management-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.list-stack {
  display: grid;
  gap: 8px;
}

.list-row {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.list-row:first-child {
  border-top: 0;
}

.list-row strong {
  display: block;
}

.stream-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 14px;
  align-items: start;
}

.stream-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  min-width: 0;
  position: relative;
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.stream-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--line);
}

.stream-card[data-stream-state="online"]::before {
  background: var(--green);
}

.stream-card[data-stream-state="offline"]::before {
  background: var(--red);
}

.stream-card > *,
.stream-card form,
.stream-card details {
  min-width: 0;
}

.stream-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.stream-card-head h2 {
  font-size: 1.12rem;
  overflow-wrap: anywhere;
}

.stream-card-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.stream-preview {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  background: #10141d;
  color: #fff;
  text-decoration: none;
}

.stream-preview img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 220ms ease, filter 220ms ease;
}

.stream-preview:hover img {
  transform: scale(1.03);
  filter: saturate(1.08);
}

.preview-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  background:
    linear-gradient(135deg, rgba(45, 184, 122, 0.22), transparent),
    var(--surface3);
}

.preview-fallback small {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.preview-fallback svg {
  width: 42px;
  height: 42px;
}

.preview-overlay {
  position: absolute;
  z-index: 2;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-weight: 900;
}

.preview-stamp {
  position: absolute;
  z-index: 2;
  left: 10px;
  bottom: 10px;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 18, 24, 0.72);
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.preview-overlay svg {
  width: 16px;
  height: 16px;
}

.stream-recording-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px;
  border: 1px solid rgba(232, 162, 26, 0.36);
  border-radius: var(--radius);
  background: rgba(232, 162, 26, 0.12);
}

.stream-recording-state[hidden] {
  display: none;
}

.stream-recording-state strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.9fr) minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.stream-actions > form,
.stream-actions > button {
  width: 100%;
}

.form-stack,
.compact-form,
.schedule-panel,
.modal-form {
  display: grid;
  gap: 12px;
}

.builder-form,
.assignment-form,
.inline-actions,
.row-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.builder-form {
  margin-top: 14px;
}

.builder-form label,
.assignment-form label,
.inline-actions label {
  flex: 1 1 190px;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface3);
  color: var(--ink);
}

input:focus,
select:focus {
  border-color: rgba(45, 184, 122, 0.75);
  outline: 3px solid rgba(45, 184, 122, 0.14);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 900;
  font-size: 0.86rem;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease;
}

.button:disabled,
.button.is-busy {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.stream-actions .button {
  width: 100%;
  padding-inline: 9px;
  font-size: 0.96rem;
}

.button:hover {
  transform: translateY(-1px);
  filter: brightness(0.97);
}

.button-primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.button-secondary {
  background: rgba(77, 141, 255, 0.14);
  border-color: rgba(77, 141, 255, 0.35);
  color: var(--blue);
}

.button-record {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.button-muted {
  background: var(--surface2);
  color: var(--ink);
  border-color: var(--line);
}

.button-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(216, 74, 74, 0.32);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-recording {
  color: var(--green);
  border-color: rgba(45, 184, 122, 0.34);
  background: rgba(45, 184, 122, 0.12);
}

.badge-warn {
  color: var(--amber);
  border-color: rgba(232, 162, 26, 0.36);
  background: rgba(232, 162, 26, 0.12);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
  animation: modal-fade 140ms ease-out;
}

.modal-backdrop[hidden] {
  display: none;
}

.recording-modal {
  position: relative;
  width: min(100%, 470px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: modal-rise 160ms ease-out;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.recording-modal h2 {
  margin-right: 42px;
  font-size: 1.55rem;
}

.modal-stream {
  margin: 5px 42px 18px 0;
  color: var(--muted);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.recording-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface3);
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.mode-tab svg {
  width: 18px;
  height: 18px;
}

.mode-tab.is-active {
  background: var(--surface2);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.modal-form .button {
  width: 100%;
}

.modal-form[hidden] {
  display: none;
}

@keyframes modal-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: capitalize;
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 999px;
  background: currentColor;
}

.status-active,
.status-completed,
.status-online {
  border-color: rgba(45, 184, 122, 0.34);
  background: rgba(45, 184, 122, 0.12);
  color: var(--green);
}

.status-recording,
.status-running,
.status-starting,
.status-stopping,
.status-unknown {
  background: var(--amber-soft);
  border-color: rgba(232, 162, 26, 0.36);
  color: var(--amber);
}

.status-failed,
.status-cancelled,
.status-stopped,
.status-paused,
.status-offline {
  background: var(--red-soft);
  border-color: rgba(216, 74, 74, 0.36);
  color: var(--red);
}

.stream-card[data-stream-state="offline"] .stream-preview {
  filter: grayscale(0.18);
}

.stream-card[data-stream-state="offline"] .preview-overlay {
  background: rgba(169, 37, 53, 0.9);
}

.subnav {
  margin: 0 0 18px;
}

.subnav a {
  background: var(--surface);
  border: 1px solid var(--line);
}

.list-surface {
  display: grid;
  gap: 10px;
}

.manager-row {
  border-top: 1px solid var(--line);
  padding: 12px 0 0;
}

.manager-row:first-of-type {
  border-top: 0;
}

.manager-row summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 900;
}

.manager-row summary small {
  color: var(--muted);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.manager-row form {
  margin-top: 12px;
}

.split-actions {
  display: flex;
  gap: 8px;
}

.assignment-panel {
  margin-bottom: 16px;
}

.assignment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface2);
  font-weight: 800;
}

.table-surface {
  overflow-x: auto;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--surface3);
}

tr:last-child td {
  border-bottom: 0;
}

.actions-col {
  width: 250px;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 800;
}

.flash-success {
  background: rgba(45, 184, 122, 0.12);
  color: var(--green);
  border-color: rgba(45, 184, 122, 0.34);
}

.flash-error {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(216, 74, 74, 0.36);
}

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

.player {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #080a0f;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.watch-controls {
  display: grid;
  gap: 14px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(440px, 100%);
  padding: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 24px;
}

.site-footer {
  width: min(1560px, calc(100% - 44px));
  margin: auto auto 0;
  padding: 24px 0 28px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.site-footer div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.site-footer strong {
  color: var(--ink);
}

.toast-wrap {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.toast-error {
  border-left-color: var(--red);
}

@media (max-width: 1080px) {
  .topbar-inner,
  .two-column,
  .management-grid,
  .watch-layout {
    grid-template-columns: 1fr;
  }

  .nav-links {
    justify-content: flex-start;
  }

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

@media (max-width: 720px) {
  .topbar-inner,
  .page,
  .page-narrow,
  .site-footer {
    width: min(100% - 20px, 1320px);
  }

  .page-title,
  .storage-topline,
  .stream-card-head,
  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-title h1,
  .login-card h1,
  .empty-state h1 {
    font-size: 2rem;
  }

  .stream-grid,
  .storage-metrics,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .stream-actions {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .modal-backdrop {
    align-items: end;
    padding: 10px;
  }

  .recording-modal {
    width: 100%;
    padding: 18px;
    max-height: calc(100vh - 20px);
    overflow: auto;
  }

  .account-menu,
  .builder-form,
  .assignment-form,
  .inline-actions,
  .row-actions {
    align-items: stretch;
  }
}
