:root {
  color: #17201c;
  background: #f3f6f4;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --ink: #17201c;
  --muted: #66716b;
  --line: #d7ddd9;
  --surface: #ffffff;
  --surface-soft: #edf2ef;
  --green: #087a59;
  --green-dark: #056047;
  --green-pale: #dff2e9;
  --red: #b33a32;
  --amber: #9b6500;
  --shadow: 0 16px 44px rgba(28, 47, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #f3f6f4;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(8, 122, 89, 0.06), transparent 48%),
    #eef3f0;
}

.login-panel {
  width: min(420px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 6px;
  color: white;
  background: var(--green);
  font-size: 18px;
  font-weight: 800;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.2;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.brand-login {
  margin-bottom: 30px;
}

.brand-login .brand-mark {
  width: 46px;
  height: 46px;
  flex-basis: 46px;
  font-size: 22px;
}

.brand-login h1 {
  font-size: 21px;
}

.login-form,
#subscription-form,
#account-form {
  display: grid;
  gap: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #34403a;
  font-size: 13px;
  font-weight: 650;
}

input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #c8d0cb;
  border-radius: 5px;
  outline: none;
  color: var(--ink);
  background: var(--surface);
}

input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 122, 89, 0.12);
}

input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--green);
}

.button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 700;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:active,
.icon-button:active {
  transform: translateY(1px);
}

.button {
  padding: 0 16px;
}

.button.primary {
  color: white;
  background: var(--green);
}

.button.primary:hover {
  background: var(--green-dark);
}

.button.secondary {
  color: var(--green-dark);
  border-color: #aed1c4;
  background: var(--green-pale);
}

.button.quiet {
  color: #47534d;
  border-color: var(--line);
  background: var(--surface);
}

.button.full {
  width: 100%;
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.icon-button {
  width: 38px;
  padding: 0;
  color: #46524c;
  border-color: var(--line);
  background: var(--surface);
  font-size: 20px;
}

.icon-button:hover,
.button.quiet:hover {
  background: var(--surface-soft);
}

.form-error {
  min-height: 18px;
  margin: -4px 0 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.topbar-inner,
.workspace {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar-inner {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.service-state {
  display: inline-flex;
  min-width: 72px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca6a0;
}

.service-state.online {
  color: var(--green-dark);
}

.service-state.online .status-dot {
  background: #10a779;
  box-shadow: 0 0 0 4px rgba(16, 167, 121, 0.12);
}

.workspace {
  padding: 34px 0 96px;
}

.status-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.connection-band {
  margin-bottom: 34px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.connection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.connection-heading h2,
.connection-heading p {
  margin: 0;
}

.connection-heading h2 {
  font-size: 17px;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
}

.mode-switch button {
  min-width: 72px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 3px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 750;
}

.mode-switch button.active {
  color: var(--green-dark);
  background: white;
  box-shadow: 0 1px 4px rgba(25, 43, 34, 0.12);
}

.connection-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
}

.connection-value input {
  color: #2d3b34;
  background: #f7f9f8;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.metric {
  min-width: 0;
  padding: 20px 22px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span,
.metric strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric span {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric strong {
  font-size: 24px;
  font-weight: 760;
}

.section {
  padding: 30px 0 34px;
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.section-heading h2,
.section-heading p {
  margin: 0;
}

.section-heading h2 {
  font-size: 20px;
}

.eyebrow {
  margin-bottom: 5px !important;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.strategy-badge {
  padding: 6px 9px;
  border: 1px solid #c8d2cc;
  border-radius: 4px;
  color: #4f5b55;
  background: #e9eeeb;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 310px));
  gap: 24px;
}

.policy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.toggle-setting,
.country-field {
  min-height: 70px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.toggle-setting {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.toggle-setting strong,
.toggle-setting small {
  display: block;
}

.toggle-setting strong {
  color: var(--ink);
  font-size: 13px;
}

.toggle-setting small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.45;
}

.country-field {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.country-field input {
  height: 38px;
  font-family: "Cascadia Code", Consolas, monospace;
  text-transform: uppercase;
}

.probe-summary {
  display: grid;
  grid-template-columns: 0.8fr 0.8fr 0.7fr 2fr;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.probe-summary > div {
  min-width: 0;
  padding: 13px 14px;
  border-right: 1px solid var(--line);
}

.probe-summary > div:last-child {
  border-right: 0;
}

.probe-summary span,
.probe-summary strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.probe-summary span {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.probe-summary strong {
  font-size: 13px;
}

.text-error {
  color: var(--red);
}

.node-results {
  overflow: hidden;
  max-height: 430px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.node-results-header,
.node-result-row {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(120px, 1fr) 62px 90px 64px;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
}

.node-results-header {
  position: sticky;
  z-index: 1;
  top: 0;
  min-height: 38px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #f7f9f8;
  font-size: 10px;
  font-weight: 750;
}

.node-result-row {
  min-height: 45px;
  border-bottom: 1px solid #e4e8e5;
  font-size: 11px;
}

.node-result-row:last-child {
  border-bottom: 0;
}

.node-result-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-result-row span:nth-child(2) {
  font-family: "Cascadia Code", Consolas, monospace;
}

.decision {
  width: fit-content;
  padding: 3px 6px;
  border-radius: 4px;
  font-weight: 750;
}

.decision.allowed {
  color: var(--green-dark);
  background: var(--green-pale);
}

.decision.blocked {
  color: #8b2f29;
  background: #fae8e6;
}

.input-with-unit {
  position: relative;
  display: block;
}

.input-with-unit input {
  padding-right: 58px;
}

.input-with-unit > span {
  position: absolute;
  top: 50%;
  right: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transform: translateY(-50%);
}

.subscription-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.table-header,
.subscription-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(260px, 1.8fr) 94px;
  align-items: center;
  gap: 18px;
}

.table-header {
  min-height: 42px;
  padding: 0 18px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #f7f9f8;
  font-size: 11px;
  font-weight: 750;
}

.subscription-row {
  min-height: 68px;
  padding: 12px 18px;
  border-bottom: 1px solid #e4e8e5;
}

.subscription-row:last-child {
  border-bottom: 0;
}

.subscription-name,
.subscription-url {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subscription-name {
  font-size: 14px;
  font-weight: 700;
}

.subscription-url {
  color: var(--muted);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.row-actions button {
  min-width: 38px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: #48534e;
  background: white;
  font-size: 12px;
  font-weight: 700;
}

.row-actions .delete-button {
  width: 34px;
  min-width: 34px;
  padding: 0;
  color: var(--red);
  font-size: 18px;
}

.empty-state {
  min-height: 140px;
  display: grid;
  place-content: center;
  gap: 5px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.empty-state strong {
  color: #45514b;
  font-size: 14px;
}

.save-bar {
  position: static;
  z-index: 5;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
  padding: 11px 13px 11px 18px;
  border: 1px solid #cbd3ce;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 34px rgba(30, 47, 39, 0.14);
  backdrop-filter: blur(10px);
}

.save-bar span {
  color: var(--muted);
  font-size: 12px;
}

dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 24, 20, 0.48);
  backdrop-filter: blur(2px);
}

#subscription-form,
#account-form {
  padding: 26px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 19px;
}

.field-note {
  margin: -12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100% - 48px));
  padding: 12px 15px;
  border: 1px solid #a9cabd;
  border-radius: 6px;
  color: #074a37;
  background: #e5f5ed;
  box-shadow: 0 12px 30px rgba(22, 44, 34, 0.16);
  font-size: 13px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  color: #79251f;
  border-color: #e2b4af;
  background: #fae8e6;
}

@media (max-width: 720px) {
  .topbar-inner,
  .workspace {
    width: min(100% - 24px, 1120px);
  }

  .topbar-inner {
    min-height: 62px;
  }

  .brand p,
  .topbar-actions .button.quiet {
    display: none;
  }

  .workspace {
    padding-top: 20px;
  }

  .status-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 24px;
  }

  .connection-band {
    margin-bottom: 24px;
    padding: 16px;
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n+2) {
    border-bottom: 1px solid var(--line);
  }

  .metric {
    padding: 16px;
  }

  .metric strong {
    font-size: 20px;
  }

  .setting-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .policy-grid {
    grid-template-columns: 1fr;
  }

  .probe-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .probe-summary > div:nth-child(2) {
    border-right: 0;
  }

  .probe-summary > div:nth-child(-n+2) {
    border-bottom: 1px solid var(--line);
  }

  .node-results {
    overflow-x: auto;
  }

  .node-results-header,
  .node-result-row {
    min-width: 700px;
  }

  .subscriptions-heading {
    align-items: flex-end;
  }

  .region-heading {
    align-items: flex-end;
  }

  .table-header {
    display: none;
  }

  .subscription-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 12px;
    min-height: 86px;
  }

  .subscription-url {
    grid-column: 1;
  }

  .row-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .save-bar {
    margin-top: 18px;
  }
}

@media (max-width: 430px) {
  .login-panel {
    padding: 28px 22px;
  }

  .service-state {
    min-width: 0;
  }

  .section-heading {
    align-items: flex-start;
  }

  .subscriptions-heading {
    flex-direction: column;
  }

  .connection-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-switch,
  .connection-value {
    width: 100%;
  }

  .connection-value {
    grid-template-columns: 1fr;
  }

  .subscriptions-heading .button {
    width: 100%;
  }

  .region-heading {
    flex-direction: column;
  }

  .region-heading .button,
  .country-field {
    width: 100%;
  }

  .country-field {
    grid-template-columns: 1fr;
  }

  .save-bar span {
    max-width: 130px;
  }
}
