@font-face {
  font-family: "Noto Sans Thai";
  src: url("./fonts/NotoSansThai-Regular.ttf") format("truetype");
  font-weight: 400;
}

@font-face {
  font-family: "Noto Sans Thai";
  src: url("./fonts/NotoSansThai-SemiBold.ttf") format("truetype");
  font-weight: 600;
}

@font-face {
  font-family: "Noto Sans Thai";
  src: url("./fonts/NotoSansThai-Bold.ttf") format("truetype");
  font-weight: 700;
}

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #101828;
  --muted: #667085;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #15803d;
  --danger: #b42318;
  --shadow: 0 16px 36px rgba(15, 23, 42, 0.07);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 1200px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

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

h1,
h2,
p {
  margin-top: 0;
}

.app-shell {
  width: 1180px;
  margin: 0 auto;
  padding: 28px 0 34px;
}

.hero,
.builder,
.preview,
.runner-notes {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 20px;
  align-items: center;
  padding: 20px 26px;
}

.hero-copy {
  display: grid;
  align-content: center;
}

.hero-brand {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0;
  background: transparent;
}

.hero-brand img {
  display: block;
  width: min(100%, 360px);
  height: auto;
  object-fit: contain;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.2rem, 4.4vw, 4rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.08rem;
  line-height: 1.32;
}

.eyebrow,
.lead,
.section-title p,
.runner-notes p,
.plan-item p,
.run-log {
  color: var(--muted);
  line-height: 1.65;
}

.eyebrow {
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-weight: 600;
}

.lead {
  max-width: 760px;
  margin-bottom: 0;
  font-size: 1.02rem;
}

.workspace {
  margin-top: 20px;
}

.builder {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.preview {
  margin-top: 20px;
  padding: 20px;
}

.setup-panel {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.section-title {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.section-icon {
  display: inline-grid;
  width: 38px;
  min-width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
}

.section-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.inline-title {
  justify-content: space-between;
}

.inline-title > div {
  display: grid;
  gap: 3px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
}

.field span {
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

textarea[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 96px;
  padding: 11px 12px;
  line-height: 1.65;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #98a2b3;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 92, 255, 0.14);
}

.grid-2,
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.actions.compact {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  margin-bottom: 10px;
}

.actions.stacked {
  flex-direction: column;
  align-items: stretch;
}

button,
.link-button {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border-radius: 8px;
  text-decoration: none;
}

button {
  padding: 0 16px;
  border: 0;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--primary-hover);
}

button.secondary,
.link-button {
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
}

button.secondary:hover:not(:disabled),
.link-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

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

button:disabled {
  cursor: not-allowed;
  background: #e5e7eb;
  color: #98a2b3;
}

.primary-cta {
  min-width: 190px;
  min-height: 48px;
}

.question-list {
  display: grid;
  gap: 12px;
}

.question-empty-state,
.empty-state {
  display: grid;
  min-height: 170px;
  place-items: center;
  padding: 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.question-empty-state strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.question-card,
.plan-item,
.run-result-item,
.run-output,
.metric {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.question-card,
.plan-item,
.run-result-item,
.run-output {
  padding: 16px;
}

.question-card-head,
.plan-item header,
.run-result-item header,
.run-output-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.question-card-head {
  padding-bottom: 13px;
  border-bottom: 1px solid var(--border);
}

.question-card-head div {
  display: grid;
  gap: 3px;
}

.question-card-head span {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
}

.question-card-head strong {
  font-size: 1.08rem;
}

.question-type-chip {
  width: fit-content;
  min-height: 26px;
  margin-top: 4px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.question-type-chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.question-answer-heading {
  display: grid;
  gap: 2px;
  margin: 4px 0 10px;
}

.question-answer-heading strong {
  font-size: 0.98rem;
}

.question-answer-heading span {
  color: var(--muted);
  font-size: 0.88rem;
}

.icon-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #fecaca;
  background: #fff7f7;
  color: var(--danger);
  font-size: 0.86rem;
}

.answer-choice-list {
  display: grid;
  gap: 8px;
}

.answer-choice-list[hidden],
.question-answer-heading[hidden] {
  display: none;
}

.answer-choice {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-weight: 600;
}

.answer-choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.answer-choice[data-disabled] {
  border-color: var(--border);
  background: #f8fafc;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.72;
}

.answer-choice span {
  line-height: 1.45;
}

.answer-choice input,
.assist-toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.choice-empty {
  width: 100%;
  padding: 12px;
  color: var(--muted);
  text-align: center;
}

.text-answer-note {
  padding: 13px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.text-answer-field {
  margin-top: 14px;
}

.assist-toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 0;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.question-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.assist-toggle[hidden] {
  display: none;
}

.assist-toggle span {
  display: grid;
  gap: 2px;
}

.assist-toggle small,
.metric span,
.plan-item header span,
.run-output-title span {
  color: var(--muted);
  font-size: 0.82rem;
}

.extract-status {
  min-height: 26px;
  color: var(--muted);
  font-size: 0.92rem;
}

.extract-status[data-state="success"],
.run-result-item span {
  color: var(--success);
  font-weight: 700;
}

.extract-status[data-state="error"] {
  color: var(--danger);
  font-weight: 700;
}

.extract-status[data-state="loading"] {
  color: var(--primary);
  font-weight: 700;
}

.metric {
  display: grid;
  gap: 6px;
  min-height: 74px;
  padding: 13px;
  background: var(--surface-soft);
}

.metric strong {
  font-size: 1rem;
}

.plan-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  min-height: 188px;
  margin: 14px 0;
  overflow: auto;
  padding-right: 3px;
}

.plan-item p,
.run-result-item p {
  margin-bottom: 0;
}

.plan-item p + p {
  margin-top: 7px;
}

.run-output {
  margin-top: 14px;
}

.run-log {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
}

.runner-notes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 20px;
  align-items: center;
  margin-top: 20px;
  padding: 20px;
}

.note-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.note-grid span {
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  font-weight: 700;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(100%, 460px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
  padding: 20px;
}

.modal-copy {
  display: grid;
  gap: 6px;
}

.modal-copy span {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
}

.modal-copy h2 {
  margin-bottom: 0;
  font-size: 1.28rem;
}

.modal-copy p {
  margin-bottom: 0;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.modal-card[data-tone="danger"] #modalConfirm {
  background: var(--danger);
}

.modal-type-options {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.modal-type-options[hidden] {
  display: none;
}

.type-option {
  display: grid;
  justify-items: start;
  min-height: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.type-option:hover,
.type-option[data-active="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.type-option span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 400;
}

@media (max-width: 1199px), (hover: none), (pointer: coarse) {
  html,
  body {
    min-width: 0;
    min-height: 100vh;
    overflow: hidden;
    background: #ffffff;
  }

  body > * {
    display: none !important;
  }
}
