:root {
  color-scheme: light;
  --page: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --muted-light: #94a3b8;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-bg: #f0fdfa;
  --teal-border: #99f6e4;
  --blue: #0369a1;
  --blue-bg: #f0f9ff;
  --blue-border: #bae6fd;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --red: #b91c1c;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p,
pre {
  margin: 0;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

[hidden] {
  display: none !important;
}

.font-mono,
code {
  font-family: var(--mono);
}

.login-shell {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

.login-panel {
  display: flex;
  width: 100%;
  max-width: 380px;
  flex-direction: column;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(15 23 42 / 5%);
  padding: 20px;
}

.login-brand {
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 16px;
}

.login-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.login-field .field-input {
  height: 36px;
  font-size: 13px;
}

.btn-primary {
  display: inline-flex;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  outline: 0;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: background 150ms ease;
}

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

.login-notice {
  border: 1px solid var(--red-border);
  border-radius: 6px;
  background: var(--red-bg);
  color: var(--red);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 550;
}

.debug-shell {
  display: flex;
  width: 100%;
  max-width: 1360px;
  min-height: 100vh;
  flex-direction: column;
  margin: 0 auto;
  padding: 12px 16px 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.brand,
.topbar-status,
.connection-strip,
.connection-meta,
.oauth-compact,
.section-head,
.result-head,
.api-main,
.api-actions,
.scope-list,
.control-actions {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-copy {
  min-width: 0;
}

.brand h1 {
  overflow: hidden;
  color: #020617;
  font-size: 16px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p {
  overflow: hidden;
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-status {
  flex: 0 0 auto;
  gap: 7px;
}

.state-badge,
.meta-badge,
.scope-chip,
.method,
.param-chip,
.http-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  white-space: nowrap;
}

.state-badge,
.meta-badge {
  min-height: 26px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
}

.state-badge {
  gap: 6px;
}

.state-badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.state-badge.loading,
.meta-badge {
  background: #fff;
  color: var(--muted);
}

.state-badge.success {
  border-color: var(--teal-border);
  background: var(--teal-bg);
  color: var(--teal);
}

.state-badge.error {
  border-color: var(--red-border);
  background: var(--red-bg);
  color: var(--red);
}

.control-panel,
.api-list-panel,
.result-panel {
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(250px, 1.1fr) minmax(150px, 0.6fr) auto;
  align-items: end;
  gap: 8px;
  padding: 10px 16px;
}

.control-field {
  min-width: 0;
}

.control-field > span,
.api-params label > span {
  display: block;
  overflow: hidden;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-field em {
  margin-left: 5px;
  color: var(--muted-light);
  font-size: 10px;
  font-style: normal;
  font-weight: 500;
}

.field-input {
  width: 100%;
  height: 30px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: var(--ink-soft);
  padding: 0 9px;
  font-size: 12px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px #ccfbf1;
}

.readonly-input,
.field-input:read-only {
  background: var(--surface-muted);
  color: var(--muted);
}

.control-actions {
  min-width: 0;
  flex-wrap: wrap;
  gap: 5px;
}

.btn-secondary,
.btn-quiet,
.action-link {
  display: inline-flex;
  height: 30px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 6px;
  outline: 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink-soft);
  padding: 0 10px;
}

.btn-secondary:hover:not(:disabled):not(.is-disabled) {
  border-color: #cbd5e1;
  background: var(--surface-muted);
}

.btn-secondary svg {
  width: 13px;
  height: 13px;
}

.btn-quiet {
  background: transparent;
  color: var(--muted);
  padding: 0 6px;
}

.btn-quiet:hover:not(:disabled) {
  background: var(--surface-muted);
  color: var(--ink-soft);
}

.icon-button {
  width: 30px;
  padding: 0;
}

button:disabled,
.is-disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.connection-strip {
  min-height: 39px;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  background: rgb(248 250 252 / 70%);
  padding: 5px 16px;
}

.connection-meta {
  min-width: 0;
  flex-wrap: wrap;
  gap: 4px 18px;
  color: var(--muted);
  font-size: 11px;
}

.connection-meta strong {
  margin-left: 4px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-weight: 600;
}

.oauth-compact {
  min-width: 0;
  flex: 0 0 auto;
  gap: 10px;
}

.token-note {
  color: var(--muted-light);
  font-size: 10px;
}

.inline-notice {
  margin: 8px 16px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 550;
}

.inline-notice.loading {
  background: var(--surface-muted);
  color: var(--muted);
}

.inline-notice.success {
  border-color: var(--teal-border);
  background: var(--teal-bg);
  color: var(--teal-dark);
}

.inline-notice.warning {
  border-color: var(--amber-border);
  background: var(--amber-bg);
  color: var(--amber);
}

.inline-notice.error {
  border-color: var(--red-border);
  background: var(--red-bg);
  color: var(--red);
}

.section-head {
  min-height: 55px;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border-soft);
  padding: 9px 16px;
}

.section-head h2 {
  color: #020617;
  font-size: 15px;
  font-weight: 650;
}

.section-head p {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.scope-list {
  max-width: 58%;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.scope-chip {
  min-height: 20px;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
}

.scope-chip.granted {
  border-color: var(--teal-border);
  background: var(--teal-bg);
  color: var(--teal);
}

.scope-chip.pending {
  border-color: var(--amber-border);
  background: var(--amber-bg);
  color: var(--amber);
}

.scope-chip.unknown {
  background: var(--surface-muted);
  color: var(--muted-light);
}

.api-list-heading,
.api-row {
  display: grid;
  grid-template-columns: minmax(360px, 1.05fr) 160px minmax(260px, 0.85fr) 78px;
  align-items: center;
  gap: 12px;
  padding-right: 16px;
  padding-left: 16px;
}

.api-list-heading {
  min-height: 31px;
  border-bottom: 1px solid var(--border-soft);
  background: rgb(248 250 252 / 70%);
  color: var(--muted-light);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.api-row {
  min-height: 72px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.api-row + .api-row {
  border-top: 1px solid var(--border-soft);
}

.api-main {
  min-width: 0;
  gap: 11px;
}

.method {
  width: 43px;
  height: 20px;
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
}

.method.get {
  border-color: var(--teal-border);
  background: var(--teal-bg);
  color: var(--teal);
}

.method.post {
  border-color: var(--blue-border);
  background: var(--blue-bg);
  color: var(--blue);
}

.api-title {
  min-width: 0;
}

.api-title h3 {
  overflow: hidden;
  color: #020617;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-title p {
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-meta {
  display: block;
  overflow: hidden;
  color: var(--muted-light);
  font-size: 11px;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-meta.loading {
  color: var(--muted);
}

.debug-meta.success {
  color: var(--teal);
}

.debug-meta.error {
  color: var(--red);
}

.api-params {
  display: flex;
  min-width: 0;
  flex-wrap: nowrap;
  gap: 5px;
}

.api-params label {
  min-width: 0;
  flex: 0 1 72px;
}

.api-params label.cursor-param {
  flex-basis: 122px;
}

.api-params label > span {
  margin-bottom: 2px;
  font-size: 9px;
}

.api-params .field-input {
  min-width: 0;
  height: 25px;
  padding: 0 6px;
  font-size: 10px;
}

.api-params.muted {
  color: var(--muted-light);
  font-size: 11px;
}

.api-actions {
  justify-content: flex-end;
}

.action-link {
  min-width: 64px;
  background: transparent;
  color: var(--teal);
  padding: 0 4px;
}

.action-link:hover:not(:disabled) {
  color: var(--teal-dark);
}

.action-link svg {
  width: 13px;
  height: 13px;
}

.result-head .btn-secondary {
  flex: 0 0 auto;
}

.result-meta-grid {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) 120px 110px 150px;
  gap: 0;
  border-bottom: 1px solid var(--border-soft);
  background: rgb(248 250 252 / 70%);
}

.result-meta-grid > div {
  min-width: 0;
  padding: 7px 16px;
}

.result-meta-grid > div + div {
  border-left: 1px solid var(--border-soft);
}

.result-meta-grid span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted-light);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.result-meta-grid code,
.result-meta-grid strong {
  display: block;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.http-status {
  width: max-content;
  min-height: 19px;
  padding: 0 6px;
}

.http-status.idle {
  background: #fff;
  color: var(--muted-light);
}

.http-status.loading {
  border-color: var(--blue-border);
  background: var(--blue-bg);
  color: var(--blue);
}

.http-status.success {
  border-color: var(--teal-border);
  background: var(--teal-bg);
  color: var(--teal);
}

.http-status.error {
  border-color: var(--red-border);
  background: var(--red-bg);
  color: var(--red);
}

.result-panel pre {
  max-height: 420px;
  min-height: 190px;
  overflow: auto;
  margin: 12px 16px 16px;
  border-radius: 6px;
  outline: 0;
  background: #020617;
  padding: 14px;
  color: #e2e8f0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  max-width: calc(100vw - 36px);
  border-radius: 6px;
  background: #0f172a;
  box-shadow: 0 10px 30px rgb(15 23 42 / 20%);
  color: #fff;
  padding: 8px 11px;
  font-size: 11px;
  font-weight: 600;
}

.is-busy {
  cursor: wait !important;
}

@media (max-width: 1020px) {
  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-actions {
    align-self: end;
  }

  .api-list-heading {
    display: none;
  }

  .api-row {
    grid-template-columns: minmax(0, 1fr) 130px;
    gap: 8px 12px;
    padding-top: 11px;
    padding-bottom: 11px;
  }

  .api-debug {
    justify-self: end;
  }

  .api-params {
    grid-column: 1;
  }

  .api-actions {
    grid-column: 2;
    grid-row: 2;
  }

  .result-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-meta-grid > div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--border-soft);
  }

  .result-meta-grid > div:nth-child(4) {
    border-top: 1px solid var(--border-soft);
  }
}

@media (max-width: 680px) {
  .debug-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .topbar-status {
    width: 100%;
    flex-wrap: wrap;
  }

  .control-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .control-actions {
    display: flex;
    width: 100%;
    justify-content: flex-end;
  }

  .connection-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .oauth-compact {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .token-note {
    max-width: none;
    white-space: normal;
  }

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

  .scope-list {
    max-width: 100%;
    justify-content: flex-start;
  }

  .api-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .api-debug,
  .api-actions {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
  }

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

  .api-params {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .api-params label,
  .api-params label.cursor-param {
    width: auto;
  }

  .api-params label.cursor-param {
    grid-column: 1 / -1;
  }

  .result-meta-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-meta-grid > div + div,
  .result-meta-grid > div:nth-child(3) {
    border-top: 1px solid var(--border-soft);
    border-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
