:root {
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --ink: #18242c;
  --muted: #63737b;
  --line: #d6e0e2;
  --nav: #18333c;
  --nav-soft: #264951;
  --accent: #087f73;
  --accent-dark: #05685e;
  --accent-soft: #d8f1ed;
  --warning: #b96c0a;
  --warning-soft: #fff1dc;
  --danger: #b63b3b;
  --danger-soft: #fae5e5;
  --shadow: 0 18px 48px rgba(16, 42, 50, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-content: center;
  padding: 32px 20px;
  background:
    linear-gradient(135deg, rgba(8, 127, 115, 0.08), transparent 44%),
    var(--bg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 22px;
}

.login-brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.login-brand p {
  margin: 3px 0 0;
  color: var(--muted);
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-content: center;
  border-radius: var(--radius);
  background: var(--nav);
  color: white;
  font-weight: 800;
  letter-spacing: 1px;
}

.brand-mark.small {
  width: 40px;
  height: 40px;
  font-size: 12px;
}

.login-panel {
  width: min(390px, calc(100vw - 40px));
  padding: 26px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.form-heading h2 {
  margin: 0;
  font-size: 20px;
}

.domain-label {
  overflow: hidden;
  max-width: 160px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  color: #34464e;
  font-weight: 600;
}

label small,
small {
  color: var(--muted);
  font-weight: 400;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #b9c8cc;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 115, 0.12);
}

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

.check-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.form-error {
  min-height: 20px;
  margin: 0 0 10px;
  color: var(--danger);
}

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
}

.btn:disabled {
  cursor: wait;
  opacity: 0.55;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-secondary {
  border-color: #b7c6ca;
  background: white;
  color: #28414a;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  border-color: #d99a9a;
  background: white;
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-soft);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: inherit;
}

.btn-block {
  width: 100%;
}

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

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 24px;
  background: var(--nav);
  color: white;
}

.topbar-brand,
.topbar-account {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-brand strong {
  display: block;
  font-size: 17px;
}

.topbar-subtitle {
  display: block;
  overflow: hidden;
  max-width: 360px;
  color: #b8d0d3;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .btn-quiet {
  color: #d6e7e8;
}

.user-label {
  color: #e7f1f2;
}

.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  background: #2d535b;
  padding: 4px 10px;
  color: #d8eeee;
  font-size: 12px;
}

.status-pill.ok {
  background: #155f4f;
  color: #dcfff4;
}

.status-pill.error {
  background: #6e3333;
  color: #ffe6e6;
}

.workspace {
  display: grid;
  min-width: 0;
  min-height: calc(100vh - 68px);
  grid-template-columns: 210px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  background: #213e46;
  padding: 20px 12px;
}

.sidebar nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0 6px 6px 0;
  background: transparent;
  color: #d3e0e2;
  padding: 10px 14px;
  text-align: left;
}

.nav-item:hover {
  background: var(--nav-soft);
}

.nav-item.active {
  border-left-color: #32c1ae;
  background: #31545c;
  color: white;
}

.sidebar-foot {
  display: grid;
  gap: 5px;
  color: #9db5ba;
  padding: 12px 10px;
  font-size: 12px;
}

.content {
  min-width: 0;
  padding: 28px clamp(16px, 3vw, 42px) 48px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.view-heading h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: 0;
}

.view-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.toolbar select {
  min-width: 180px;
}

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

.metric {
  display: grid;
  min-height: 112px;
  align-content: space-between;
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
}

.metric:nth-child(3) {
  border-top-color: #3e73a8;
}

.metric:nth-child(4) {
  border-top-color: var(--danger);
}

.metric span {
  color: var(--muted);
}

.metric strong {
  font-size: 32px;
}

.section-band {
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-heading h3,
.settings-panel h3,
.anchor-section h3 {
  margin: 0;
  font-size: 17px;
}

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

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

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

th,
td {
  border-bottom: 1px solid #e5ebec;
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

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

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

tbody tr:hover {
  background: #f6faf9;
}

.channel-cell {
  display: grid;
  gap: 3px;
}

.channel-cell strong {
  max-width: 260px;
  overflow-wrap: anywhere;
}

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

.state-badge {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  border-radius: 999px;
  background: #edf1f2;
  padding: 3px 9px;
  color: #495c64;
  font-size: 12px;
  font-weight: 700;
}

.state-badge.streaming {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.state-badge.watching {
  background: #e8eff7;
  color: #315f91;
}

.state-badge.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.state-badge.paused {
  background: var(--warning-soft);
  color: var(--warning);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions .btn {
  min-height: 31px;
  padding: 5px 9px;
  font-size: 12px;
}

.log-output {
  overflow: auto;
  min-height: 520px;
  max-height: calc(100vh - 220px);
  margin: 0;
  border: 1px solid #23393f;
  border-radius: var(--radius);
  background: #101d21;
  color: #d7e5e7;
  padding: 18px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.settings-panel {
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
}

.settings-panel h3 {
  margin-bottom: 18px;
}

.settings-panel.compact {
  position: sticky;
  top: 88px;
}

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

.subheading {
  margin: 22px 0 12px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.subheading h4 {
  margin: 0;
  font-size: 15px;
}

.domain-row {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
}

.domain-row code {
  overflow-wrap: anywhere;
  color: var(--accent-dark);
  font-size: 14px;
}

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

.info-item {
  border-left: 3px solid #b9c8cc;
  padding: 4px 10px;
}

.info-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.info-item strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.user-row,
.anchor-item {
  display: grid;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #e6ecec;
  padding: 10px 0;
}

.user-row {
  grid-template-columns: minmax(130px, 1fr) 130px 90px auto;
}

.user-row:last-child,
.anchor-item:last-child {
  border-bottom: 0;
}

.anchor-item {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.anchor-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.anchor-meta strong,
.anchor-meta span {
  overflow-wrap: anywhere;
}

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

.anchor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.anchor-actions .btn {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.empty {
  color: var(--muted);
  padding: 24px 10px;
  text-align: center;
}

.inline-form {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(160px, 1fr) minmax(130px, 0.8fr) auto;
  margin-bottom: 14px;
}

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  overflow-y: auto;
  place-items: start center;
  background: rgba(12, 27, 32, 0.65);
  padding: 28px 16px;
}

.modal {
  width: min(760px, 100%);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

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

.modal-heading h2 {
  margin: 0;
  font-size: 21px;
}

.proxy-fields {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.proxy-fields legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.modal-actions,
.channel-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .btn-primary {
  margin-left: auto;
}

.anchor-section {
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.channel-action-bar {
  position: sticky;
  bottom: -22px;
  margin: 22px -22px -22px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 22px;
}

.toast {
  position: fixed;
  z-index: 80;
  right: 20px;
  bottom: 20px;
  max-width: min(440px, calc(100vw - 40px));
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: #13262c;
  color: white;
  padding: 13px 16px;
  box-shadow: var(--shadow);
}

.toast.error {
  border-left-color: #f06b6b;
}

@media (max-width: 980px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .settings-panel.compact {
    position: static;
  }

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

@media (max-width: 760px) {
  .topbar {
    position: static;
    align-items: flex-start;
    padding: 12px 16px;
  }

  .topbar-subtitle,
  .user-label,
  .status-pill {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    padding: 8px;
  }

  .sidebar nav {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    border-bottom: 3px solid transparent;
    border-left: 0;
    padding: 10px 13px;
    white-space: nowrap;
  }

  .nav-item.active {
    border-bottom-color: #32c1ae;
    border-left-color: transparent;
  }

  .sidebar-foot {
    display: none;
  }

  .content {
    padding: 20px 14px 36px;
  }

  .view-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar .btn,
  .toolbar select {
    flex: 1 1 130px;
  }

  .metric {
    min-height: 94px;
    padding: 14px;
  }

  .metric strong {
    font-size: 27px;
  }

  .form-grid,
  .inline-form,
  .user-row {
    grid-template-columns: 1fr;
  }

  .domain-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal {
    min-height: 100vh;
    border-radius: 0;
    padding: 16px;
  }

  .channel-action-bar {
    bottom: -16px;
    margin: 20px -16px -16px;
    padding: 12px 16px;
  }

  .anchor-item {
    grid-template-columns: 1fr;
  }

  .anchor-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 460px) {
  .metric-grid,
  .info-grid {
    grid-template-columns: 1fr;
  }
}
