:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #637083;
  --line: #d9e0e8;
  --primary: #147a73;
  --primary-strong: #0d5d58;
  --danger: #b42318;
  --warn: #a15c07;
  --ok: #18794e;
  --shadow: 0 10px 28px rgba(29, 36, 48, 0.08);
}

* {
  box-sizing: border-box;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.button-row,
.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

button,
select,
input,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9aa8b8;
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-strong);
}

button.danger {
  color: var(--danger);
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
  gap: 16px;
  padding: 16px;
}

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

.panel.wide,
.status-panel {
  grid-column: 1 / -1;
}

.badge {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #f8fafc;
}

.badge.ok {
  color: var(--ok);
  border-color: #a8d8be;
  background: #eef9f3;
}

.badge.warn {
  color: var(--warn);
  border-color: #f0c98d;
  background: #fff7e8;
}

.badge.bad {
  color: var(--danger);
  border-color: #f0b2ac;
  background: #fff1f0;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
}

.kv {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fbfcfd;
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.kv strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.35;
}

.field-stack,
.field-grid,
.inline-form,
.raw-grid {
  display: grid;
  gap: 8px;
}

.field-stack {
  margin-top: 14px;
}

.field-stack.compact {
  margin-top: 0;
  margin-bottom: 12px;
}

.field-grid {
  grid-template-columns: 1.2fr 1fr 1fr;
  margin-bottom: 12px;
}

.inline-form {
  grid-template-columns: 120px minmax(220px, 1fr);
  align-items: center;
  margin-bottom: 12px;
}

.raw-grid {
  grid-template-columns: 160px 1fr;
  margin-bottom: 10px;
}

label,
.block-label {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 122, 115, 0.14);
}

textarea {
  min-height: 118px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.output {
  min-height: 170px;
  max-height: 420px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101820;
  color: #d6e4f0;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 36px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  background: #1d2430;
  color: #fff;
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.callback {
  max-width: 520px;
  margin: 12vh auto 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.callback p {
  margin: 12px 0 18px;
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  padding: 0 12px;
  text-decoration: none;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .kv-grid,
  .field-grid,
  .inline-form,
  .raw-grid {
    grid-template-columns: 1fr;
  }
}
