:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18222d;
  --muted: #667085;
  --line: #d7dde5;
  --brand: #08786c;
  --brand-dark: #075f57;
  --good: #067647;
  --bad: #b42318;
  --warn: #9a6700;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main { max-width: 1180px; margin: 0 auto; padding: 24px; }

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
h1 span { color: var(--brand); }
header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
#status { max-width: 420px; color: var(--brand-dark); text-align: right; overflow-wrap: anywhere; }

.auth-band {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) 90px 110px 100px 70px;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid #b9d7d2;
  border-radius: 8px;
  background: #f2fbf9;
  margin-bottom: 10px;
}

.proxy-band {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(270px, 1.5fr) 100px 100px 100px minmax(150px, auto);
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid #d7dde5;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 18px;
}

label { display: block; color: #344054; font-weight: 650; }
label > span { display: block; margin-bottom: 6px; }
small { color: var(--muted); font-weight: 500; }

textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  outline: none;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(8, 120, 108, .13);
}

input, select { height: 38px; padding: 0 10px; }
textarea { min-height: 145px; resize: vertical; padding: 11px; }
.auth-band button { white-space: nowrap; }
.token-field { grid-column: span 3; }
.account-field { grid-column: span 2; }
#proxyState { min-height: 38px; display: flex; align-items: center; justify-content: flex-end; color: var(--brand-dark); font-size: 12px; overflow-wrap: anywhere; }

button.danger { border-color: #f0b8b3; background: #fff; color: var(--bad); }
button.danger:hover:not(:disabled) { background: #fef3f2; }

.workspace { margin-bottom: 14px; }
.workspace > label { margin-bottom: 7px; }
.controls { display: grid; grid-template-columns: 140px 120px 140px 100px; gap: 10px; align-items: end; margin-top: 12px; }
.controls label { color: var(--muted); font-size: 12px; }

button {
  height: 38px;
  border: 1px solid var(--brand-dark);
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--brand-dark); }
button:disabled { opacity: .55; cursor: wait; }
button.secondary { border-color: var(--line); background: #fff; color: #344054; }
button.secondary:hover:not(:disabled) { background: #f8fafc; }

.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 18px 0; }
.metrics div { border-top: 3px solid #a8bbb8; background: var(--panel); padding: 12px; }
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics b { display: block; margin-top: 2px; font-size: 22px; }

.batch-tools { display: grid; grid-template-columns: minmax(300px, 1fr) 110px 110px minmax(210px, auto); gap: 10px; align-items: end; margin-bottom: 12px; }
.batch-tools label { color: var(--muted); font-size: 12px; }
#batchState { min-height: 38px; display: flex; align-items: center; justify-content: flex-end; color: var(--muted); font-size: 12px; text-align: right; overflow-wrap: anywhere; }
.result-tools { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(220px, 2fr) 90px 155px; gap: 10px; align-items: end; margin-bottom: 10px; }
.result-tools label { color: var(--muted); font-size: 12px; }
#filterCount { height: 38px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--muted); font-weight: 700; }

.table-wrap { max-height: calc(100vh - 510px); min-height: 180px; overflow: auto; border: 1px solid var(--line); background: #fff; }
table { width: 100%; min-width: 800px; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 9px 10px; border-bottom: 1px solid #e9edf2; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { position: sticky; top: 0; z-index: 1; background: #f8fafb; color: #475467; font-size: 12px; }
th:nth-child(1) { width: 18%; } th:nth-child(2) { width: 8%; } th:nth-child(3) { width: 10%; } th:nth-child(4) { width: 24%; } th:nth-child(5) { width: 40%; }
.code, .raw { font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.raw { max-height: 68px; overflow: auto; white-space: pre-wrap; color: #475467; }
.empty { height: 150px; text-align: center; vertical-align: middle; color: var(--muted); }
.pill { display: inline-flex; min-width: 62px; justify-content: center; padding: 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.yes { color: var(--good); background: #ecfdf3; }
.pill.no { color: var(--bad); background: #fef3f2; }
.pill.unknown { color: var(--warn); background: #fffaeb; }

.region-panel { margin: 18px 0; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.region-panel h2 { margin: 0; font-size: 17px; }
.region-panel p { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.region-panel > label { margin-top: 12px; }
.region-panel textarea { min-height: 100px; }
.region-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-top: 12px; }
.region-actions button { padding: 0 14px; }
.region-actions label { width: 130px; font-size: 12px; }
.region-table { max-height: 380px; }
.region-table th:nth-child(1) { width: 15%; }
.region-table th:nth-child(2) { width: 20%; }
.region-table th:nth-child(3) { width: 13%; }
.region-table th:nth-child(4) { width: 10%; }
.region-table th:nth-child(5) { width: 20%; }
.region-table th:nth-child(6) { width: 22%; }

@media (max-width: 720px) {
  main { padding: 15px; }
  header { display: block; }
  #status { display: block; margin-top: 8px; text-align: left; }
  .auth-band, .proxy-band, .controls, .metrics, .batch-tools, .result-tools { grid-template-columns: 1fr; }
  .token-field, .account-field { grid-column: auto; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  #batchState { justify-content: flex-start; text-align: left; }
  #proxyState { justify-content: flex-start; }
  .table-wrap { max-height: 430px; }
}
