:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --panel-quiet: #f0f4f1;
  --ink: #1d2522;
  --muted: #68736e;
  --border: #d8ded9;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ef;
  --gold: #b97912;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(29, 37, 34, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1,
.brand p,
.panel-header h2,
.panel-header p,
.section-heading h2,
.field-card h3,
.field-card p,
.response-heading h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand p,
.panel-header p,
.field-card p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  height: calc(100vh - 73px);
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(360px, 1fr) minmax(340px, 430px);
  gap: 14px;
  padding: 14px;
  min-height: 620px;
}

.tool-panel,
.builder-panel,
.inspector-panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tool-panel,
.inspector-panel {
  overflow: auto;
}

.builder-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: 0;
}

.compact-section {
  display: grid;
  gap: 12px;
}

.section-heading {
  margin-bottom: 12px;
}

.section-heading h2,
.panel-header h2 {
  font-size: 15px;
  line-height: 1.2;
}

.panel-header {
  min-height: 68px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-button,
.icon-button,
.ghost-button,
.small-button,
.tab-button,
.field-action {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
}

.tool-button {
  min-height: 62px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px;
  text-align: left;
}

.tool-button:hover,
.icon-button:hover,
.ghost-button:hover,
.small-button:hover,
.tab-button:hover,
.field-action:hover {
  border-color: #aeb8b1;
  background: var(--panel-quiet);
}

.tool-icon,
.icon-button span:first-child {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  line-height: 1;
}

.tool-label {
  font-size: 13px;
  font-weight: 700;
}

.icon-button,
.file-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  text-decoration: none;
}

.file-button input {
  display: none;
}

.ghost-button,
.small-button {
  min-height: 34px;
  padding: 6px 10px;
}

.small-button {
  min-height: 30px;
  font-size: 12px;
}

.full-width {
  width: 100%;
}

.builder-list {
  overflow: auto;
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.empty-state {
  min-height: 240px;
  border: 1px dashed #b8c2bb;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  background: #fbfcfb;
}

.field-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px;
}

.field-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-card button {
  min-height: 32px;
}

.field-card h3 {
  font-size: 14px;
  line-height: 1.25;
}

.field-type-badge {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #eef2f7;
  color: #384152;
  font-weight: 800;
}

.field-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.field-action {
  min-width: 32px;
  height: 32px;
  padding: 0;
}

.field-action.danger {
  color: var(--danger);
}

.tabs {
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 5;
}

.tab-button {
  min-height: 34px;
  font-size: 13px;
  font-weight: 700;
}

.tab-button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.tab-panel {
  display: none;
  padding: 14px;
}

.tab-panel.active {
  display: block;
}

.field-control {
  display: grid;
  gap: 6px;
}

.field-control span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.field-control input,
.field-control textarea,
.field-control select,
.live-form input,
.live-form textarea,
.live-form select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

.field-control input:focus,
.field-control textarea:focus,
.field-control select:focus,
.live-form input:focus,
.live-form textarea:focus,
.live-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-editor {
  display: grid;
  gap: 12px;
}

.editor-actions,
.export-actions,
.response-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.live-form {
  display: grid;
  gap: 14px;
}

.preview-title {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.preview-title h2,
.preview-title p {
  margin: 0;
}

.preview-title h2 {
  font-size: 20px;
}

.preview-title p {
  color: var(--muted);
  margin-top: 5px;
}

.preview-field {
  display: grid;
  gap: 7px;
}

.preview-label {
  font-size: 13px;
  font-weight: 800;
}

.required-mark {
  color: var(--danger);
}

.help-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.choice-stack {
  display: grid;
  gap: 7px;
}

.choice-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.choice-label input {
  width: 16px;
  height: 16px;
}

.signature-box {
  height: 96px;
  border: 1px dashed #aeb8b1;
  border-radius: var(--radius);
  background:
    linear-gradient(transparent 62px, #d7dfda 63px, transparent 64px),
    #fbfcfb;
}

.submit-button {
  border: 0;
  border-radius: 7px;
  min-height: 40px;
  padding: 9px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}

.response-box {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfb;
}

.response-box pre,
#json-output {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(12px);
  background: #1d2522;
  color: #fff;
  border-radius: 7px;
  padding: 10px 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1120px) {
  .workspace {
    height: auto;
    min-height: calc(100vh - 73px);
    grid-template-columns: minmax(220px, 280px) 1fr;
  }

  .inspector-panel {
    grid-column: 1 / -1;
    min-height: 520px;
  }
}

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

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

  .workspace {
    grid-template-columns: 1fr;
    padding: 10px;
    min-height: 0;
  }

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

  .field-card {
    grid-template-columns: 34px 1fr;
  }

  .field-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}
