:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f7f8fb;
  color: #161b22;
}

body {
  margin: 0;
}

button,
input,
select,
.button-link {
  font: inherit;
}

button,
.button-link {
  border: 1px solid #1f6feb;
  background: #1f6feb;
  color: white;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-block;
  line-height: 1.2;
  text-decoration: none;
}

button.secondary-button,
.button-link.secondary-button,
.app-nav a {
  border-color: #c9d1d9;
  background: #ffffff;
  color: #161b22;
}

button.danger-button {
  border-color: #cf222e;
  background: #cf222e;
}

button.success-button {
  border-color: #1a7f37;
  background: #1a7f37;
}

.app-nav a.active {
  border-color: #1f6feb;
  background: #eaf3ff;
  color: #0a58ca;
}

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

button + button {
  margin-left: 8px;
}

input,
select {
  border: 1px solid #c9d1d9;
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  box-sizing: border-box;
  min-height: 38px;
  width: 100%;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

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

th {
  font-size: 14px;
  font-weight: 700;
}

tbody td {
  font-size: 13px;
  line-height: 1.35;
}

.vpn-configs-table .created-column {
  white-space: nowrap;
}

.vpn-configs-table .mode-column {
  max-width: 108px;
  white-space: normal;
  width: 108px;
}

.vpn-configs-table tbody .mode-column strong {
  display: inline-block;
  max-width: 108px;
  white-space: normal;
}

.vpn-configs-table thead .source-column,
.vpn-configs-table thead .target-column,
.vpn-configs-table thead .ingress-column,
.vpn-configs-table thead .egress-column {
  white-space: nowrap;
}

.status-column {
  min-width: 104px;
}

.status-cell {
  align-content: center;
  display: grid;
  gap: 2px;
  min-height: 32px;
}

.status-cell strong {
  font-size: inherit;
}

.status-cell small {
  color: #57606a;
  font-size: 11px;
  line-height: 1.25;
  margin: 0;
}

.status-error strong,
.status-error small {
  color: #b42318;
}

.actions-column {
  min-width: 180px;
  text-align: left;
  white-space: normal;
  width: 180px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
}

.action-buttons button + button {
  margin-left: 0;
}

.action-buttons button {
  font-size: 12px;
  padding: 6px 8px;
}

.table-sort {
  border: 0;
  background: transparent;
  color: #161b22;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}

.table-sort:hover {
  color: #0a58ca;
}

.latency-cell {
  min-width: 150px;
}

.latency-result {
  display: grid;
  min-height: 38px;
}

.latency-result strong {
  line-height: 18px;
}

.latency-result small {
  line-height: 16px;
}

.benchmark-routes {
  display: grid;
  gap: 14px;
}

.benchmark-routes-heading {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.benchmark-routes-heading h3 {
  font-size: 15px;
  margin: 0 0 4px;
}

.benchmark-routes-heading p {
  color: #57606a;
  font-size: 13px;
  margin: 0;
}

.benchmark-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  min-width: 260px;
}

.benchmark-summary span {
  background: #f6f8fa;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  color: #57606a;
  font-size: 12px;
  padding: 5px 8px;
}

.benchmark-summary strong {
  color: #161b22;
}

.benchmark-controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.benchmark-filter-label {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  max-width: none;
  white-space: nowrap;
}

.benchmark-filter-label select {
  font-size: 12px;
  line-height: 1.2;
  min-height: 30px;
  min-width: 128px;
  padding: 4px 28px 4px 8px;
  width: auto;
}

.benchmark-route-table {
  min-width: 0;
  table-layout: fixed;
}

.benchmark-route-table th,
.benchmark-route-table td {
  padding: 8px 6px;
  vertical-align: top;
}

.benchmark-route-table thead th {
  background: #f6f8fa;
  font-size: 11px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.benchmark-route-table td {
  font-size: 11px;
}

.benchmark-rtt-table th:nth-child(1) {
  width: 18%;
}

.benchmark-rtt-table th:nth-child(2),
.benchmark-rtt-table th:nth-child(3),
.benchmark-rtt-table th:nth-child(5),
.benchmark-rtt-table th:nth-child(6),
.benchmark-rtt-table th:nth-child(9) {
  width: 7%;
}

.benchmark-rtt-table th:nth-child(4),
.benchmark-rtt-table th:nth-child(8) {
  width: 9%;
}

.benchmark-rtt-table th:nth-child(10) {
  width: 9%;
}

.benchmark-rtt-table th:nth-child(11),
.benchmark-rtt-table th:nth-child(12) {
  width: 10%;
}

.benchmark-rtt-table th:nth-child(7) {
  width: 8%;
}

.benchmark-one-way-table th:nth-child(1) {
  width: 16%;
}

.benchmark-one-way-table th:nth-child(2),
.benchmark-one-way-table th:nth-child(3),
.benchmark-one-way-table th:nth-child(5),
.benchmark-one-way-table th:nth-child(7),
.benchmark-one-way-table th:nth-child(8),
.benchmark-one-way-table th:nth-child(10) {
  width: 6%;
}

.benchmark-one-way-table th:nth-child(4),
.benchmark-one-way-table th:nth-child(6),
.benchmark-one-way-table th:nth-child(9) {
  width: 8%;
}

.benchmark-one-way-table th:nth-child(11),
.benchmark-one-way-table th:nth-child(12) {
  width: 10%;
}

.benchmark-route-table .table-sort {
  line-height: 1.15;
  white-space: normal;
}

.benchmark-table-section {
  display: grid;
  gap: 8px;
}

.benchmark-table-section + .benchmark-table-section {
  margin-top: 20px;
}

.benchmark-table-heading h3 {
  font-size: 15px;
  margin: 0;
}

.benchmark-route-table tbody .numeric-cell {
  white-space: nowrap;
}

.estimated-metric {
  align-items: center;
  display: inline-flex;
  gap: 4px;
  justify-content: flex-end;
}

.stacked-metric {
  display: grid;
  gap: 2px;
}

.info-symbol {
  color: #57606a;
  display: inline-block;
  font-size: 11px;
  line-height: 1;
}

.numeric-cell {
  text-align: right;
}

.route-pair {
  align-items: center;
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.benchmark-failed {
  color: #b42318;
  font-weight: 700;
}

.benchmark-improvement {
  border-radius: 4px;
  display: inline-flex;
  font-weight: 400;
  padding: 2px 6px;
}

.benchmark-improvement-good {
  background: #DBFCE7;
  border-color: #86efac;
  color: #16a34a;
}

.benchmark-improvement-similar {
  background: #FEF9C2;
  border-color: #fde047;
  color: #ca8a04;
}

.benchmark-improvement-internet {
  background: #FFE2E2;
  border-color: #f9a8d4;
  color: #dc2626;
}

.gate-clock-error {
  border-radius: 4px;
  display: inline-flex;
  font-weight: 400;
  padding: 2px 6px;
}

.gate-clock-error-good {
  background: #DBFCE7;
  color: #16a34a;
}

.gate-clock-error-warning {
  background: #FEF9C2;
  color: #ca8a04;
}

.gate-clock-error-bad {
  background: #FFE2E2;
  color: #dc2626;
}

.benchmark-legend {
  align-items: center;
  color: #57606a;
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 10px 18px;
}

.benchmark-legend > span {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.legend-swatch {
  border: 1px solid;
  border-radius: 4px;
  display: inline-block;
  height: 14px;
  width: 14px;
}

.empty-state-text {
  color: #57606a;
  margin: 8px 0 0;
}

small {
  display: block;
  color: #57606a;
  margin-top: 4px;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

.topbar p {
  margin: 0;
  color: #57606a;
}

.identity {
  display: flex;
  gap: 12px;
  align-items: center;
}

.identity-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 32px;
}

.app-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.app-nav a + a {
  margin-left: 0;
}

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(420px, 1.2fr);
  gap: 16px;
}

.panel {
  background: white;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.primary-panel {
  padding: 20px;
}

.secondary-panel {
  background: #fbfcfe;
}

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

.panel-heading h2 {
  margin: 0;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 12px;
  padding: 18px 0 4px;
}

.empty-state p {
  margin: 0;
  color: #57606a;
}

.auth-panel {
  max-width: 520px;
}

.auth-form,
.session-form {
  display: grid;
  gap: 14px;
}

.auth-subform {
  border-top: 1px solid #d8dee8;
  margin-top: 14px;
  padding-top: 14px;
}

.auth-provider-button {
  margin-top: 14px;
  width: 100%;
}

.auth-divider {
  align-items: center;
  color: #57606a;
  display: grid;
  font-size: 12px;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  margin: 16px 0;
}

.auth-divider::before,
.auth-divider::after {
  background: #d8dee8;
  content: "";
  height: 1px;
}

.auth-form h2 {
  margin: 0 0 8px;
}

.auth-form p {
  color: #57606a;
  margin: 0;
}

.auth-switch {
  font-size: 14px;
}

.auth-switch a {
  color: #0969da;
  font-weight: 700;
}

.session-form {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  align-items: start;
}

.mode-summary {
  align-content: start;
  display: grid;
  gap: 6px;
  min-height: 62px;
}

.mode-summary span {
  color: #161b22;
  font-size: 14px;
  font-weight: 600;
}

.mode-summary strong {
  align-items: center;
  display: flex;
  font-size: 15px;
  min-height: 38px;
}

.field-error {
  color: #b42318;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  margin: 2px 0 0;
}

[aria-invalid="true"] {
  border-color: #d92d20;
}

.form-group {
  display: grid;
  gap: 8px;
}

.client-key-group {
  grid-column: 1 / -1;
}

.route-policy-group {
  grid-column: 1 / -1;
}

.route-policy-group details {
  border-top: 1px solid #d8dee8;
  padding-top: 8px;
}

.route-policy-group summary {
  cursor: pointer;
  font-weight: 600;
}

.policy-option-grid {
  display: grid;
  gap: 6px 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding-top: 8px;
}

.compact-checkbox {
  font-size: 13px;
}

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

.checkbox-line input {
  width: 16px;
  height: 16px;
}

.input-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-action-row button {
  white-space: nowrap;
}

.gate-select-row {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.gate-select-row select {
  height: 38px;
}

.key-instructions {
  background: #fbfcfe;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-column: 1 / -1;
  padding: 14px;
}

.key-instructions-header {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.key-instructions h3 {
  font-size: 15px;
  margin: 0 0 4px;
}

.key-instructions p {
  color: #57606a;
  font-size: 13px;
  margin: 0;
}

.key-instruction-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.key-instruction-tab {
  border-color: #c9d1d9;
  background: #ffffff;
  color: #161b22;
  padding: 6px 10px;
}

.key-instruction-tab.active {
  border-color: #1f6feb;
  background: #eaf3ff;
  color: #0a58ca;
}

.key-script-wrap {
  position: relative;
}

.copy-code-button {
  align-items: center;
  background: #21262d;
  border-color: #30363d;
  border-radius: 6px;
  display: flex;
  height: 32px;
  justify-content: center;
  padding: 0;
  position: absolute;
  right: 8px;
  top: 8px;
  width: 32px;
  z-index: 1;
}

.copy-code-button:hover,
.copy-code-button.copied {
  background: #30363d;
  border-color: #8b949e;
}

.copy-icon {
  height: 16px;
  position: relative;
  width: 16px;
}

.copy-icon::before,
.copy-icon::after {
  border: 1.5px solid #c9d1d9;
  border-radius: 2px;
  content: "";
  height: 10px;
  position: absolute;
  width: 9px;
}

.copy-icon::before {
  left: 2px;
  top: 4px;
}

.copy-icon::after {
  background: #21262d;
  left: 5px;
  top: 1px;
}

.copy-code-button:hover .copy-icon::after,
.copy-code-button.copied .copy-icon::after {
  background: #30363d;
}

.key-script {
  background: #0d1117;
  border-radius: 8px;
  color: #d8dee8;
  margin: 0;
  overflow-x: auto;
  padding: 14px 52px 14px 14px;
}

.key-script code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}

.syntax-comment {
  color: #8b949e;
}

.syntax-command {
  color: #d2a8ff;
}

.syntax-string {
  color: #a5d6ff;
}

.syntax-variable {
  color: #ffa657;
}

.syntax-operator {
  color: #ff7b72;
}

.key-docs a {
  color: #0969da;
  font-weight: 700;
}

.panel-actions {
  margin-top: 14px;
}

.account-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.account-card {
  border: 1px solid #d8dee8;
  border-radius: 8px;
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 14px;
}

.account-card h3 {
  font-size: 15px;
  margin: 0;
}

.account-card small,
.topup-row small {
  color: #57606a;
  display: block;
  font-size: 12px;
  line-height: 1.35;
}

.balance-value {
  font-size: 24px;
}

.wallet-row {
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.inline-form {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.topup-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.billing-ledger {
  border-top: 1px solid #d8dee8;
  display: grid;
  gap: 8px;
  margin-top: 16px;
  min-width: 0;
  padding-top: 14px;
}

.billing-ledger > * {
  min-width: 0;
}

.billing-ledger h3 {
  font-size: 15px;
  margin: 0;
}

.billing-ledger-row {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.billing-ledger-row > div,
.topup-row > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.billing-ledger-row small {
  color: #57606a;
  display: block;
  overflow-wrap: anywhere;
}

.billing-ledger .mono {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.amount-credit { color: #1a7f37; }
.amount-debit { color: #cf222e; }

.topup-row {
  align-items: center;
  border-top: 1px solid #d8dee8;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1fr) minmax(280px, 1.5fr);
  padding-top: 12px;
}

.support-contact,
.compact-copy {
  color: #57606a;
  font-size: 13px;
  margin: 14px 0 0;
}

.admin-actions {
  min-width: 260px;
}

.admin-actions form {
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(70px, 1fr) minmax(90px, 1.3fr) auto;
  margin-bottom: 8px;
}

.admin-actions form:last-child {
  grid-template-columns: minmax(140px, 1fr) auto;
  margin-bottom: 0;
}

.admin-plan-create {
  align-items: end;
  border-bottom: 1px solid #d8dee8;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(5, minmax(120px, 1fr)) auto;
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.qr-overlay {
  align-items: center;
  background: rgba(22, 27, 34, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 1000;
}

.qr-dialog {
  background: #ffffff;
  border-radius: 8px;
  max-width: 480px;
  padding: 16px;
  width: min(100%, 480px);
}

.config-qr {
  margin: 12px auto;
  max-width: 420px;
}

.config-qr svg {
  display: block;
  height: auto;
  width: 100%;
}

.session-form button {
  align-self: end;
}

.session-form > button[type="submit"] {
  justify-self: start;
}

.configure-step,
.review-step {
  display: grid;
  gap: 16px;
}

.step-caption {
  color: #57606a;
  margin: 0;
}

.review-card,
.policy-panel {
  border: 1px solid #d8dee8;
  border-radius: 8px;
  padding: 16px;
}

.review-card h3,
.policy-panel h3 {
  font-size: 16px;
  margin: 0 0 12px;
}

.route-overview {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 10px 0 18px;
}

.summary-pill {
  background: #f6f8fa;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-width: 132px;
  padding: 10px 12px;
  text-align: center;
}

.summary-pill span,
.review-field span {
  color: #57606a;
  font-size: 12px;
  font-weight: 600;
}

.summary-pill strong,
.review-field strong {
  overflow-wrap: anywhere;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

.route-arrow {
  color: #1f6feb;
  font-weight: 700;
}

.review-grid {
  border-top: 1px solid #d8dee8;
  display: grid;
  gap: 14px;
  padding-top: 16px;
}

.review-row {
  display: grid;
  gap: 14px;
}

.review-row-primary {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.review-row-secondary {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.review-field {
  display: grid;
  gap: 4px;
}

.policy-panel {
  border-color: #b7e4c7;
  background: #f6fff9;
}

.policy-panel p {
  margin: 0;
}

.full-tunnel-alert {
  background: #fff8c5;
  border: 1px solid #d4a72c;
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 14px 16px;
}

.full-tunnel-alert strong {
  color: #633c01;
}

.full-tunnel-alert p {
  color: #3b2300;
  margin: 0;
}

.client-key-notice {
  background: #fff8c5;
  border: 1px solid #d4a72c;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 14px 16px;
}

.client-key-notice strong {
  color: #633c01;
}

.client-key-notice p {
  color: #3b2300;
  margin: 0;
}

.notice-code-wrap {
  position: relative;
}

.notice-copy-button {
  background: #fffdf0;
  border-color: #d4a72c;
  height: 24px;
  right: 6px;
  top: 5px;
  width: 24px;
}

.notice-copy-button:hover,
.notice-copy-button.copied {
  background: #fff8c5;
  border-color: #9a6700;
}

.notice-copy-button .copy-icon {
  height: 13px;
  width: 13px;
}

.notice-copy-button .copy-icon::before,
.notice-copy-button .copy-icon::after {
  border-color: #633c01;
  height: 8px;
  width: 7px;
}

.notice-copy-button .copy-icon::before {
  left: 2px;
  top: 4px;
}

.notice-copy-button .copy-icon::after {
  background: #fffdf0;
  left: 5px;
  top: 1px;
}

.notice-copy-button:hover .copy-icon::after,
.notice-copy-button.copied .copy-icon::after {
  background: #fff8c5;
}

.client-key-notice code {
  background: #ffffff;
  border: 1px solid #c9d1d9;
  border-radius: 6px;
  color: #161b22;
  display: block;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  overflow-x: auto;
  padding: 8px 40px 8px 10px;
  white-space: nowrap;
}

.run-instructions {
  background: #fbfcfe;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.run-instructions h3 {
  font-size: 16px;
  margin: 0 0 4px;
}

.run-instructions p {
  color: #57606a;
  font-size: 13px;
  margin: 0;
}

.run-instructions .key-script {
  padding: 14px 52px 14px 14px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.ok {
  color: #1a7f37;
  font-weight: 700;
}

.bad {
  color: #cf222e;
  font-weight: 700;
}

.muted {
  color: #57606a;
}

.empty-marker {
  color: #57606a;
  font-weight: 600;
}

.event-log {
  min-height: 80px;
  max-height: 280px;
  overflow: auto;
  background: #0d1117;
  color: #d8dee8;
  border-radius: 8px;
  padding: 14px;
}

@media (max-width: 860px) {
  .shell {
    padding: 18px;
  }

  .topbar,
  .grid,
  .account-grid,
  .admin-plan-create,
  .gate-select-row,
  .inline-form,
  .review-grid,
  .review-row,
  .session-form,
  .topup-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .form-actions {
    display: grid;
  }

  .key-instructions-header {
    display: grid;
  }

  .panel-heading {
    align-items: stretch;
    display: grid;
  }
}
