:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #60646c;
  --line: #d9d6cc;
  --field: #fbfaf6;
  --green: #16784f;
  --amber: #b36b00;
  --cyan: #247a85;
  --red: #b42318;
  --shadow: 0 18px 45px rgba(32, 33, 36, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  width: min(1100px, calc(100% - 48px));
  margin: 0 auto;
  padding: 14px 0;
}

.topbar {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.topbar > div:first-child {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

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

.status {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.dot-ok {
  background: var(--green);
}

.dot-pending {
  background: var(--amber);
}

.dot-error {
  background: var(--red);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

.query-panel,
.results-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.query-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px 12px 12px;
}

.query-toolbar,
.query-entry {
  min-width: 0;
}

.query-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.query-entry {
  display: grid;
  gap: 8px;
}

.field-row {
  flex: 1 1 620px;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 126px 140px;
  gap: 8px;
  align-items: center;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-row label {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  outline: none;
}

input {
  height: 34px;
  padding: 0 9px;
}

input[readonly] {
  border-style: dashed;
  background: #efede5;
  color: #3f4146;
  cursor: default;
}

.namespace-field {
  position: relative;
}

.namespace-field input {
  padding-right: 50px;
}

.namespace-field::after {
  content: "fixed";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
  text-transform: uppercase;
}

.query-box input {
  height: 42px;
  font-size: 15px;
}

textarea {
  min-height: 70px;
  max-height: 112px;
  resize: vertical;
  padding: 9px;
  line-height: 1.45;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
}

input:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(36, 122, 133, 0.14);
}

.query-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  flex: 0 0 184px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.query-switch-button {
  height: 30px;
  border-color: transparent;
  background: transparent;
}

.query-switch-button.active {
  border-color: var(--line);
  background: #ffffff;
  color: var(--green);
}

.query-switch-button:disabled {
  cursor: default;
}

.vector-box {
  margin-top: 0;
}

.vector-view textarea {
  color: var(--muted);
  cursor: text;
}

.vector-view textarea:focus {
  border-color: var(--line);
  box-shadow: none;
}

.query-meta,
.actions,
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.query-meta {
  min-height: auto;
  margin: 0;
  color: var(--muted);
}

.query-meta span {
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--green);
}

.actions {
  flex-wrap: wrap;
  justify-content: flex-start;
}

button {
  min-width: 0;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  border-color: var(--cyan);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.primary {
  min-width: 92px;
  border-color: #14583d;
  background: var(--green);
  color: #ffffff;
}

.results-panel {
  min-width: 0;
  padding: 14px;
  outline: none;
}

.result-head {
  min-height: 44px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.latency {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.result-title-block {
  display: grid;
  gap: 0;
}

.tech-details {
  margin: 10px 0;
}

.raw-json-details {
  margin-bottom: 0;
}

.stage-grid,
.scan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}

.stage-grid {
  margin: 0 0 8px;
}

.scan-grid {
  margin: 0;
}

.stage-item,
.scan-item {
  min-height: 52px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.stage-item {
  background: #f4f7f6;
}

.stage-pending strong {
  color: var(--amber);
}

.stage-item span,
.scan-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stage-item strong,
.scan-item strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 10px 0;
}

.image-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.image-card a {
  display: block;
  aspect-ratio: 1 / 1;
  background: #e9e5da;
}

.image-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.image-card-body {
  padding: 10px;
}

.image-card-body strong,
.image-card-body span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.image-card-body p {
  min-height: 40px;
  margin: 7px 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  height: 38px;
  padding: 0 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

th {
  background: #efede5;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.raw-output {
  overflow-x: auto;
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202124;
  color: #f8f7f2;
  font-size: 12px;
  line-height: 1.45;
}

.raw-output:empty {
  display: none;
}

@media (max-width: 960px) {
  .workspace,
  .query-panel {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 110px;
    max-height: 180px;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(1100px, calc(100% - 20px));
    padding: 10px 0;
  }

  .topbar,
  .result-head {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 18px;
    max-width: min(100%, 320px);
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .stage-grid,
  .scan-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .stage-grid {
    margin-bottom: 4px;
  }

  .stage-item,
  .scan-item {
    min-height: 40px;
    padding: 5px;
  }

  .stage-item span,
  .scan-item span {
    overflow: hidden;
    font-size: 9px;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stage-item strong,
  .scan-item strong {
    margin-top: 4px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  .image-card-body {
    padding: 7px;
  }

  .image-card-body p {
    min-height: 0;
    max-height: 34px;
    overflow: hidden;
    margin: 5px 0;
    font-size: 12px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions > *,
  .actions button {
    width: 100%;
  }
}

/* Turnstile escalation slot — empty when challenge is silent; reserves a row
   for the "I'm not a robot" widget when Cloudflare needs interaction. */
.turnstile-slot { min-height: 0; transition: min-height .14s ease; }
.turnstile-slot:has(iframe) { min-height: 65px; margin-top: 4px; }
.turnstile-slot iframe { display: block; }
