:root {
  color-scheme: dark;
  --bg: #121212;
  --panel: #1f1f1f;
  --panel-2: #2b2b2b;
  --text: #f7f7f7;
  --muted: #a8a8a8;
  --line: #3a3a3a;
  --accent: #e14b3d;
  --relay: #f0a020;
  --client: #65a7ff;
  --ok: #4fd37a;
  --shadow: 0 6px 18px rgba(0, 0, 0, .32);
  --station-list-width: 340px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f4;
  --panel: #ffffff;
  --panel-2: #f0f0f0;
  --text: #161616;
  --muted: #666666;
  --line: #d7d7d7;
  --accent: #df4638;
  --relay: #c87b00;
  --client: #1f67c7;
  --ok: #168542;
  --shadow: 0 5px 15px rgba(0, 0, 0, .16);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: 48px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 48px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 5;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
}

.theme-icon {
  font-size: 22px;
  line-height: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-title {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.connection-badge.connected { color: var(--ok); }
.connection-badge.error { color: var(--accent); }

.stat-strip {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stat-strip b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.last-update {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.workspace {
  min-height: 0;
  padding: 8px;
}

.control-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--station-list-width) minmax(320px, 430px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 8px;
  padding: 0;
  background: var(--bg);
  overflow: hidden;
}

.left-rail {
  min-height: 0;
  min-width: 0;
  width: var(--station-list-width);
  max-width: var(--station-list-width);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.filter-card {
  min-width: 0;
  max-width: 100%;
  padding: 10px 14px;
  background: var(--panel);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.relay-picker {
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 8px;
  background: var(--panel);
  border-radius: 4px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.relay-detail {
  min-height: 0;
  min-width: 0;
  overflow: auto;
}

.relay-card {
  min-height: 100%;
  padding: 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.relay-card.empty {
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.relay-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.relay-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 15px;
  font-weight: 850;
}

.relay-sub {
  margin-top: 3px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

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

.relay-metric {
  min-width: 0;
  padding: 7px 6px;
  background: var(--panel-2);
  border-radius: 4px;
  text-align: center;
}

.relay-metric b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 16px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.relay-metric em {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.relay-kv {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 4px 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.relay-kv b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 650;
}

.detail-section {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.detail-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.client-row,
.activity-row {
  display: grid;
  align-items: center;
  gap: 7px;
  min-height: 25px;
  color: var(--muted);
  font-size: 12px;
}

.client-row {
  grid-template-columns: 9px minmax(0, 1fr) minmax(52px, auto) 34px;
}

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

.client-row b,
.activity-row b,
.client-row span,
.activity-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-row b,
.activity-row b {
  color: var(--text);
}

.client-row em,
.activity-row em {
  color: var(--muted);
  font-style: normal;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--client);
}

.talking .live-dot,
.activity-row.talking span:first-child {
  color: var(--accent);
}

.talking .live-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent), transparent 78%);
}

.detail-empty {
  padding: 8px;
  color: var(--muted);
  background: var(--panel-2);
  border-radius: 4px;
  font-size: 12px;
  text-align: center;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  margin-bottom: 2px;
}

.select-control {
  width: 100%;
  height: 34px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: none;
}

.search-row {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.search-input {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: relative;
  width: 38px;
  height: 20px;
  border-radius: 20px;
  background: #777;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  transition: transform .15s ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.switch em {
  font-style: normal;
}

.list-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 5px 3px 8px;
  color: var(--muted);
  font-size: 13px;
}

.list-header span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-header strong {
  min-width: 30px;
  color: var(--text);
  text-align: right;
}

.list-action {
  height: 24px;
  padding: 0 8px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.list-action[hidden] {
  display: none;
}

.station-list {
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  display: grid;
  align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.list-column {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.station-list.compact {
  grid-template-columns: 1fr;
}

.station-list.compact .station-card {
  min-height: 78px;
}

.station-card.pinned {
  border-color: color-mix(in srgb, var(--accent), transparent 30%);
  background: color-mix(in srgb, var(--panel), var(--accent) 8%);
}

.station-list.compact .card-name {
  height: auto;
  max-height: 34px;
}

.station-card {
  min-width: 0;
  min-height: 106px;
  padding: 9px 9px 8px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: 4px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.station-card.hot,
.station-card.active {
  border-color: var(--accent);
}

.station-card:hover {
  border-color: color-mix(in srgb, var(--accent), transparent 35%);
}

.activity-card {
  cursor: default;
}

.activity-card:hover {
  border-color: transparent;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.pin-btn {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}

.pin-btn:hover {
  color: var(--text);
  border-color: var(--line);
  background: var(--panel-2);
}

.pin-btn.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.pin-btn:disabled {
  opacity: 1;
  cursor: default;
}

.role-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--client);
}

.role-dot.server {
  background: var(--relay);
}

.role-dot.talking-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent), transparent 78%);
}

.card-call {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.card-time {
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.card-name {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  height: 30px;
  overflow: hidden;
}

.card-meta {
  margin-top: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  color: var(--text);
  font-size: 13px;
}

.card-sub {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-id {
  font-variant-numeric: tabular-nums;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px 14px;
  color: var(--muted);
  text-align: center;
  background: var(--panel);
  border-radius: 4px;
}


@media (max-width: 920px) {
  .control-panel {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 340px) minmax(0, 230px) minmax(0, 1fr);
  }

  .left-rail {
    width: 100%;
    max-width: none;
  }

  .station-list {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .relay-card {
    min-height: auto;
  }

  .relay-kv,
  .detail-section + .detail-section {
    display: none;
  }

  .stat-strip {
    display: none;
  }
}

@media (max-width: 560px) {
  .brand-title {
    display: none;
  }

  .workspace {
    padding: 6px;
  }

  .station-list {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}
