:root {
  --bg: #f4f2ec;
  --bg-deep: #ded7c9;
  --panel: rgba(255, 255, 255, 0.82);
  --text: #1d1a16;
  --muted: #6c6459;
  --accent: #b23a2f;
  --accent-2: #0f766e;
  --line: rgba(29, 26, 22, 0.14);
  --shadow: 0 20px 50px rgba(70, 43, 26, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 8% 8%, #fff6cf 0, transparent 35%),
    radial-gradient(circle at 90% 20%, #ffd8bf 0, transparent 32%),
    linear-gradient(140deg, var(--bg) 0%, var(--bg-deep) 100%);
  font-family: "Manrope", sans-serif;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(50px);
  z-index: -1;
  opacity: 0.45;
}

.orb-a {
  width: 300px;
  height: 300px;
  background: #ffab8a;
  top: -40px;
  left: -40px;
  animation: floatA 9s ease-in-out infinite;
}

.orb-b {
  width: 280px;
  height: 280px;
  background: #8be0d8;
  right: -60px;
  bottom: -20px;
  animation: floatB 11s ease-in-out infinite;
}

.app-shell {
  width: min(1200px, 95vw);
  margin: 1.2rem auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.eyebrow {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-size: 0.72rem;
}

h1 {
  margin: 0.2rem 0 0;
  font-family: "DM Serif Display", serif;
  font-weight: 400;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: #fff;
}

.tabs {
  display: flex;
  gap: 0.7rem;
  margin: 0.8rem 0 1rem;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 700;
}

.tab.is-active {
  border-color: transparent;
  background: linear-gradient(90deg, var(--accent), #db5e43);
  color: #fff;
}

.panel {
  display: none;
}

.panel.is-active {
  display: grid;
  animation: enter 280ms ease;
}

#chat-panel {
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 1rem;
}

.sidebar,
.json-builder,
.messages,
.composer,
.schema-list-wrap {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.sidebar,
.json-builder {
  padding: 0.9rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.field span {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
}

.image-scale-field input[type="range"] {
  padding: 0;
}

.range-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.range-meta strong {
  color: var(--accent-2);
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.65rem;
}

.file-list,
.schema-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.file-list li,
.schema-list li {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  font-size: 0.82rem;
}

.chat-area {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 0.8rem;
  min-height: 70vh;
}

.messages {
  padding: 1rem;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 0.8rem;
}

.message {
  max-width: min(860px, 94%);
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
  line-height: 1.45;
  word-break: break-word;
}

.message.user {
  justify-self: end;
  background: #fff4ef;
  border: 1px solid #f5c6b5;
  white-space: pre-wrap;
}

.message.assistant {
  justify-self: start;
  background: #f0fbfa;
  border: 1px solid #b7e8e1;
}

/* ── Rendered markdown inside assistant messages ── */

.message.assistant .answer-body > *:first-child,
.message.assistant .thinking-body > *:first-child {
  margin-top: 0;
}

.message.assistant .answer-body > *:last-child,
.message.assistant .thinking-body > *:last-child {
  margin-bottom: 0;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
  margin: 0.6em 0 0.3em;
  font-family: "DM Serif Display", serif;
  font-weight: 400;
}

.message.assistant h1 { font-size: 1.3em; }
.message.assistant h2 { font-size: 1.15em; }
.message.assistant h3 { font-size: 1.05em; }

.message.assistant p {
  margin: 0.4em 0;
}

.message.assistant ul,
.message.assistant ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}

.message.assistant li {
  margin: 0.15em 0;
}

.message.assistant strong {
  font-weight: 700;
}

.message.assistant em {
  font-style: italic;
}

.message.assistant code {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.88em;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 0.15em 0.35em;
}

.message.assistant pre {
  margin: 0.5em 0;
  padding: 0.7em 0.85em;
  background: #1d1a16;
  color: #e8e2d8;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.5;
}

.message.assistant pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

.message.assistant blockquote {
  margin: 0.5em 0;
  padding: 0.3em 0.8em;
  border-left: 3px solid var(--accent-2);
  background: rgba(15, 118, 110, 0.06);
  border-radius: 0 8px 8px 0;
}

.message.assistant table {
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.88em;
  width: 100%;
}

.message.assistant th,
.message.assistant td {
  border: 1px solid var(--line);
  padding: 0.35em 0.6em;
  text-align: left;
}

.message.assistant th {
  background: rgba(0, 0, 0, 0.04);
  font-weight: 700;
}

.message.assistant hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0.8em 0;
}

/* ── Thinking block ── */

.thinking-block {
  margin-bottom: 0.6em;
  border: 1px dashed var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.thinking-block summary {
  cursor: pointer;
  padding: 0.4em 0.7em;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.03);
}

.thinking-block summary:hover {
  color: var(--text);
}

.thinking-body {
  padding: 0.5em 0.7em;
  font-size: 0.88em;
  color: var(--muted);
  border-top: 1px dashed var(--line);
}

.composer {
  padding: 0.8rem;
  display: grid;
  gap: 0.6rem;
}

.composer-actions,
.builder-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.58rem 0.95rem;
  background: linear-gradient(90deg, var(--accent), #d35842);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button.ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.schema-list-wrap {
  margin-top: 0.8rem;
  padding: 0.8rem;
}

.visual-builder {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  margin-bottom: 0.9rem;
  background: #fff;
}

.visual-builder h3 {
  margin: 0;
  font-size: 1rem;
}

.helper {
  margin: 0.3rem 0 0.7rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.field-rows {
  display: grid;
  gap: 0.55rem;
}

.field-tree-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-node {
  border-left: 2px solid rgba(15, 118, 110, 0.18);
  padding-left: 0.6rem;
}

.field-path {
  font-size: 0.75rem;
  color: var(--accent-2);
  margin-bottom: 0.35rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1.2fr 130px 130px 95px auto;
  gap: 0.5rem;
  align-items: center;
}

.array-item-type {
  min-width: 120px;
}

.required-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
}

.field-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

.field-row .remove-field {
  padding: 0.45rem 0.5rem;
}

.schema-list li.active {
  border-style: solid;
  border-color: var(--accent-2);
  background: #e8faf8;
}

@media (max-width: 940px) {
  #chat-panel {
    grid-template-columns: 1fr;
  }

  .chat-area {
    min-height: 55vh;
  }

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

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

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes floatA {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(18px);
  }
}

@keyframes floatB {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-16px);
  }
}
