:root {
  color-scheme: light;
  --ink: #142130;
  --muted: #657184;
  --quiet: #8c98a8;
  --line: rgba(32, 49, 68, 0.13);
  --line-strong: rgba(32, 49, 68, 0.2);
  --glass: rgba(255, 255, 255, 0.56);
  --glass-heavy: rgba(255, 255, 255, 0.78);
  --blue: #2563eb;
  --teal: #0f9f8a;
  --aqua: #0891b2;
  --rose: #d94c42;
  --amber: #c98316;
  --shadow: 0 22px 80px rgba(35, 54, 79, 0.16);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(244, 250, 255, 0.94), rgba(238, 250, 246, 0.92) 46%, rgba(255, 248, 236, 0.94)),
    linear-gradient(rgba(20, 33, 48, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 33, 48, 0.035) 1px, transparent 1px);
  background-size: auto, 44px 44px, 44px 44px;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(15, 159, 138, 0.16), transparent 38%),
    radial-gradient(circle at 72% 22%, rgba(217, 76, 66, 0.12), transparent 28%);
  filter: blur(8px);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.glass {
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.7), var(--glass));
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
}

.app-shell {
  width: min(1640px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 0 26px;
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  gap: 14px;
  position: relative;
}

.side-rail {
  min-height: calc(100vh - 28px);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 14px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-height: 48px;
}

.identity-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.18);
}

.identity b,
.identity small,
.identity em {
  display: block;
}

.identity b {
  font-size: 15px;
}

.identity small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.identity em {
  margin-top: 1px;
  color: var(--quiet);
  font-size: 11px;
  font-style: normal;
}

.rail-nav {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

.rail-item {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  text-align: left;
}

.rail-item span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.rail-item b {
  font-size: 13px;
}

.rail-item.active,
.rail-item:hover {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.64);
}

.rail-foot {
  margin-top: auto;
  display: flex;
  justify-content: center;
}

.mini-action {
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  font-weight: 800;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.mini-action:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.94);
}

.console {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.command-bar {
  min-height: 72px;
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: center;
  position: sticky;
  top: 14px;
  z-index: 8;
}

.command-title p,
.settings-sheet header p {
  margin: 0 0 2px;
  color: var(--aqua);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 15px;
}

.command-search {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  padding: 0 10px;
}

.command-search span {
  color: var(--quiet);
  font-size: 18px;
}

.command-search input {
  width: 100%;
  height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

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

.status-strip {
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.status-strip div {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
  padding: 9px 10px;
}

.status-strip span,
.relay-list dt {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-strip b {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.workbench {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
  align-items: start;
}

.library,
.inspector {
  border-radius: var(--radius);
}

.library {
  min-width: 0;
  padding: 12px;
}

.library-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.tabs {
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.56);
  color: var(--muted);
  padding: 0 10px;
  white-space: nowrap;
  font-weight: 800;
}

.tab.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue), var(--aqua));
}

#groupSelect,
.field-grid input,
.field-grid select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  outline: 0;
  padding: 0 10px;
}

.table-shell {
  max-height: calc(100vh - 220px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.46);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid rgba(32, 49, 68, 0.09);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  background: rgba(249, 252, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
}

tbody tr {
  background: rgba(255, 255, 255, 0.3);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.74);
}

td:nth-child(1) {
  width: 36%;
}

td:nth-child(2),
td:nth-child(3),
td:nth-child(4) {
  color: var(--muted);
}

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

.channel-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.channel-name {
  display: block;
  color: var(--ink);
  font-weight: 850;
  overflow-wrap: anywhere;
}

.state-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--teal);
  font-weight: 800;
  font-size: 12px;
}

.state-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(15, 159, 138, 0.12);
}

.action-col {
  width: 128px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.row-actions .mini-action {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
}

.empty-cell {
  height: 260px;
  color: var(--muted);
  text-align: center;
}

.inspector {
  position: sticky;
  top: 98px;
  padding: 12px;
  display: grid;
  gap: 12px;
}

.inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.now-title {
  display: grid;
  gap: 3px;
  margin-bottom: 10px;
}

.now-title b {
  overflow-wrap: anywhere;
}

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

video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: var(--radius);
  background: #101820;
  display: block;
}

.split-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.glass-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 850;
}

.glass-button.primary {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue), var(--aqua));
}

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

.relay-card {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

#relayModeBadge {
  min-width: 58px;
  border-radius: 999px;
  padding: 5px 9px;
  color: white;
  background: linear-gradient(135deg, var(--teal), var(--aqua));
  text-align: center;
  font-weight: 900;
  font-size: 12px;
}

.relay-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.relay-list div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.46);
  padding: 10px;
}

.relay-list dd {
  margin: 4px 0 0;
  color: var(--ink);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.settings-sheet {
  width: min(720px, calc(100% - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
}

.settings-sheet::backdrop,
.player-dialog::backdrop {
  background: rgba(20, 33, 48, 0.18);
  backdrop-filter: blur(10px);
}

.settings-sheet form {
  padding: 16px;
}

.settings-sheet header,
.settings-sheet footer {
  display: grid;
  align-items: center;
  gap: 10px;
}

.settings-sheet header {
  grid-template-columns: 1fr auto;
}

.settings-sheet footer {
  grid-template-columns: auto 1fr auto auto;
}

.field-grid {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.field-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.player-dialog {
  width: min(1180px, calc(100% - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
}

.player-sheet {
  padding: 14px;
}

.player-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.player-top p {
  margin: 0 0 2px;
  color: var(--aqua);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.player-top span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.player-tools {
  display: flex;
  gap: 8px;
}

.player-dialog video {
  width: 100%;
  max-height: min(72vh, 760px);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  min-width: 180px;
  max-width: min(440px, calc(100% - 28px));
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: var(--radius);
  background: rgba(20, 33, 48, 0.88);
  color: white;
  padding: 11px 14px;
  text-align: center;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .identity span:not(.identity-mark),
  .rail-item b {
    display: none;
  }

  .rail-item {
    grid-template-columns: 1fr;
    justify-items: center;
  }

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

  .inspector {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 1640px);
    grid-template-columns: 1fr;
  }

  .side-rail {
    min-height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
  }

  .rail-nav {
    margin: 0 0 0 auto;
    display: flex;
  }

  .rail-foot {
    display: none;
  }

  .command-bar {
    grid-template-columns: 1fr;
    position: static;
  }

  .command-actions {
    overflow-x: auto;
  }

  .status-strip {
    grid-template-columns: 1fr 1fr;
  }

  .library-toolbar {
    grid-template-columns: 1fr;
  }

  .table-shell {
    max-height: none;
  }

  table {
    min-width: 720px;
  }

  .settings-sheet footer {
    grid-template-columns: 1fr;
  }

  .player-dialog {
    width: calc(100% - 18px);
  }

  .player-top {
    grid-template-columns: 1fr;
  }

  .player-tools {
    justify-content: flex-end;
  }
}
