:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --text: #17202a;
  --muted: #687382;
  --border: #dce2ea;
  --primary: #1769e0;
  --primary-dark: #0f55ba;
  --danger: #d33a2c;
  --ok: #198754;
  --warn: #a86700;
  --shadow: 0 12px 32px rgba(23, 32, 42, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.12);
}

.primary-btn,
.ghost-btn,
.icon-btn {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 650;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

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

.primary-btn.small {
  min-height: 36px;
}

.ghost-btn {
  color: var(--text);
  background: #fff;
  border-color: var(--border);
}

.ghost-btn:hover {
  border-color: #b9c4d2;
}

.icon-btn {
  width: 40px;
  padding: 0;
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
  padding-bottom: 78px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  font-size: 19px;
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

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

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.panel-card,
.inbound-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 6px 22px rgba(23, 32, 42, 0.05);
}

.panel-card {
  display: grid;
  gap: 12px;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card-title-row h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 750;
  background: var(--panel-2);
  color: var(--muted);
}

.status-online {
  background: rgba(25, 135, 84, 0.12);
  color: var(--ok);
}

.status-offline {
  background: rgba(211, 58, 44, 0.12);
  color: var(--danger);
}

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

.meta-item {
  min-width: 0;
  padding: 9px;
  background: var(--panel-2);
  border-radius: 7px;
}

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

.meta-item b {
  display: block;
  margin-top: 3px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.url-line,
.error-line {
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.error-line {
  color: var(--danger);
}

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

.danger-btn {
  color: var(--danger);
}

.filter-row {
  margin-bottom: 12px;
}

.inbound-list {
  display: grid;
  gap: 12px;
}

.inbound-card {
  display: grid;
  gap: 12px;
}

.inbound-card.disabled {
  opacity: 0.72;
}

.inbound-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.inbound-top h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.inbound-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}

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

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #ccd4df;
  transition: background 0.16s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
  transition: transform 0.16s ease;
}

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

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

.client-box {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: grid;
  gap: 8px;
}

.client-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.client-row b {
  overflow-wrap: anywhere;
}

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

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  height: 66px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fff;
  border-top: 1px solid var(--border);
}

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  min-width: 0;
}

.nav-btn span {
  font-size: 18px;
  line-height: 1;
}

.nav-btn b {
  font-size: 12px;
}

.nav-btn.active {
  color: var(--primary);
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(620px, calc(100vw - 24px));
}

.modal::backdrop {
  background: rgba(10, 18, 28, 0.45);
}

.modal-card {
  display: grid;
  gap: 13px;
  background: var(--panel);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 82px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  background: #17202a;
  color: #fff;
  border-radius: 8px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.empty-state {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px 18px;
  text-align: center;
}

.empty-card {
  background: var(--panel);
  border: 1px dashed #b9c4d2;
  border-radius: 8px;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .topbar {
    padding: 12px 14px;
  }

  main {
    padding: 14px;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .head-actions {
    justify-content: stretch;
  }

  .head-actions > button {
    flex: 1 1 0;
  }

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

  .two-col {
    grid-template-columns: 1fr;
  }

  .modal {
    width: 100vw;
    max-width: 100vw;
    margin: 0;
  }

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

  .modal-actions {
    position: sticky;
    bottom: 0;
    background: var(--panel);
    padding-top: 8px;
  }

  .modal-actions > button {
    flex: 1 1 0;
  }
}
