:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-synthesis: none;
  --page: #f4f6f5;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --ink: #17201c;
  --muted: #66716b;
  --line: #dfe5e1;
  --line-strong: #cbd4cf;
  --brand: #176b52;
  --brand-strong: #10543f;
  --brand-soft: #e5f3ed;
  --success: #13795b;
  --danger: #b73e3e;
  --danger-soft: #fbeaea;
  --warning: #996515;
  --warning-soft: #fff4d9;
  --shadow: 0 12px 32px rgba(27, 44, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

img {
  display: block;
}

[hidden] {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--ink);
}

.brand-mark img {
  width: 18px;
  filter: invert(1);
}

.topbar-actions,
.scan-indicator {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 14px;
}

.scan-indicator {
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page {
  width: min(1440px, calc(100% - 48px));
  margin: 24px auto 56px;
}

.active-band {
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 28px 30px;
  border: 1px solid #c9ddd4;
  border-radius: 8px 8px 0 0;
  background: var(--brand-soft);
}

.section-label {
  margin-bottom: 8px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
}

.active-summary h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.active-meta {
  margin-top: 9px;
  color: #466359;
  font-size: 14px;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.tab {
  border: 0;
  border-radius: 6px;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 650;
}

.primary-button {
  background: var(--brand);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.primary-button img,
.secondary-button img {
  width: 17px;
}

.primary-button img {
  filter: invert(1);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover,
.icon-button:hover {
  background: #edf1ef;
}

.text-button {
  min-height: 40px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  background: transparent;
}

.icon-button img {
  width: 18px;
  height: 18px;
}

.subscription-band {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--surface);
}

.subscription-row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
}

.subscription-row + .subscription-row {
  border-left: 1px solid var(--line);
}

.subscription-row > div {
  min-width: 0;
}

.subscription-type {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.subscription-row code {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr)) minmax(190px, 1.5fr);
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

.metric + .metric {
  border-left: 1px solid var(--line);
}

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

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 23px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.metric-wide strong {
  font-size: 15px;
  font-weight: 650;
}

.tabs {
  display: flex;
  align-items: end;
  gap: 4px;
  margin-top: 26px;
  border-bottom: 1px solid var(--line-strong);
}

.tab {
  height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 15px;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
}

.tab img {
  width: 17px;
  opacity: 0.72;
}

.tab.active {
  border-bottom-color: var(--brand);
  color: var(--brand-strong);
  font-weight: 700;
}

.panel {
  display: none;
  min-height: 240px;
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--surface);
}

.panel.active {
  display: block;
}

.panel-toolbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-toolbar-end {
  justify-content: flex-end;
}

.search-box {
  width: min(380px, 100%);
  height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
}

.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 82, 0.12);
}

.search-box img {
  width: 17px;
  opacity: 0.55;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

th:nth-child(1) {
  width: 105px;
}

th:nth-child(2) {
  width: 35%;
}

th:nth-child(3) {
  width: 150px;
}

th:nth-child(4) {
  width: 190px;
}

th:nth-child(5) {
  width: 90px;
}

th.actions-column {
  width: 170px;
  text-align: right;
}

tbody tr:hover {
  background: #fafcfb;
}

tbody tr.is-active {
  background: #f0f8f4;
}

.status-badge,
.origin-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}

.status-badge::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.status-available {
  background: var(--brand-soft);
  color: var(--success);
}

.status-invalid {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pending {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-disabled {
  background: #ecefed;
  color: #6c756f;
}

.source-main {
  min-width: 0;
}

.source-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-name {
  overflow: hidden;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.origin-badge {
  min-height: 21px;
  padding: 0 7px;
  background: #eef1f7;
  color: #535f76;
  font-weight: 600;
}

.source-url,
.cell-secondary,
.source-error {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.source-url {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-error {
  overflow: hidden;
  color: var(--danger);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-primary {
  font-size: 13px;
  font-weight: 650;
}

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

.row-actions .icon-button {
  width: 32px;
  height: 32px;
}

.row-actions .danger-button:hover {
  background: var(--danger-soft);
}

.empty-state {
  padding: 54px 20px;
  color: var(--muted);
  text-align: center;
}

.events-list {
  padding: 0 20px;
}

.event-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 12px;
  padding: 17px 0;
  border-bottom: 1px solid var(--line);
}

.event-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--muted);
}

.event-success .event-dot {
  background: var(--success);
}

.event-warning .event-dot {
  background: var(--warning);
}

.event-error .event-dot {
  background: var(--danger);
}

.event-message {
  font-size: 14px;
  font-weight: 650;
}

.event-detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.event-time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(20, 28, 24, 0.48);
}

dialog form {
  display: grid;
  gap: 17px;
  padding: 22px;
}

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

.dialog-header h2 {
  margin: 0;
  font-size: 19px;
}

dialog label,
.mode-block {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

dialog input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: 0;
  color: var(--ink);
}

dialog input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 82, 0.12);
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 42px;
  padding: 0 2px;
}

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

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #eef1ef;
}

.segmented-control label {
  display: block;
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
}

.segmented-control span {
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.segmented-control input:checked + span {
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(27, 44, 36, 0.12);
  color: var(--ink);
  font-weight: 650;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 5px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: min(420px, calc(100% - 48px));
  padding: 12px 15px;
  border-radius: 7px;
  background: var(--ink);
  box-shadow: var(--shadow);
  color: #ffffff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 900px) {
  .active-summary h1 {
    font-size: 26px;
  }

  .page {
    width: min(100% - 28px, 1440px);
  }

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

  .metric + .metric {
    border-left: 0;
  }

  .metric:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  .metric:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .metric-wide {
    grid-column: 1 / -1;
  }

  .metric-wide:nth-child(odd) {
    border-left: 0;
  }
}

@media (max-width: 680px) {
  .topbar {
    height: 56px;
    padding: 0 16px;
  }

  .page {
    width: 100%;
    margin-top: 0;
  }

  .active-band {
    min-height: 170px;
    align-items: flex-start;
    flex-direction: column;
    padding: 24px 18px;
    border-width: 0 0 1px;
    border-radius: 0;
  }

  .active-band .primary-button {
    width: 100%;
  }

  .subscription-band {
    grid-template-columns: 1fr;
    border-width: 0 0 1px;
  }

  .subscription-row + .subscription-row {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .metrics {
    margin: 14px;
  }

  .tabs {
    margin-top: 18px;
    padding: 0 8px;
  }

  .tab {
    flex: 1;
    justify-content: center;
    padding: 0 6px;
    font-size: 13px;
  }

  .panel {
    border-right: 0;
    border-left: 0;
  }

  .panel-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-toolbar-end {
    align-items: flex-end;
  }

  .search-box,
  .panel-toolbar .secondary-button {
    width: 100%;
  }

  .event-row {
    grid-template-columns: 14px minmax(0, 1fr);
  }

  .event-time {
    grid-column: 2;
  }

  .toast {
    right: 16px;
    bottom: 16px;
    max-width: calc(100% - 32px);
  }
}
