:root {
  color-scheme: light;
  --bg: #eef1ec;
  --surface: #fbfcfa;
  --surface-2: #f4f7f3;
  --ink: #17211d;
  --muted: #64706a;
  --line: #d7ded6;
  --line-strong: #bec8c0;
  --green: #1f8a5b;
  --green-deep: #12613f;
  --red: #c84a40;
  --amber: #b97916;
  --blue: #2f65c2;
  --aqua: #257b82;
  --shadow: 0 18px 48px rgba(22, 33, 29, 0.09);
  --shadow-soft: 0 8px 24px rgba(22, 33, 29, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62) 0 25%, transparent 25% 50%, rgba(255, 255, 255, 0.46) 50% 75%, transparent 75%),
    linear-gradient(180deg, #f6f6f0 0%, var(--bg) 46%, #e6ebe5 100%);
  background-size: 26px 26px, auto;
  color: var(--ink);
  font-family:
    "Noto Sans Thai",
    "Leelawadee UI",
    "Segoe UI",
    ui-sans-serif,
    system-ui,
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  display: block;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(190, 200, 192, 0.82);
  border-radius: 8px;
  background: rgba(251, 252, 250, 0.84);
  box-shadow: var(--shadow-soft);
  padding: 14px 16px;
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(31, 138, 91, 0.34);
  border-radius: 8px;
  background: linear-gradient(135deg, #e9f8ee, #f7fbf6);
}

.brand-mark svg {
  width: 35px;
  height: 35px;
  fill: none;
  stroke: var(--green-deep);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.brand-mark circle {
  fill: #fff;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  overflow-wrap: anywhere;
  font-size: clamp(1.4rem, 2.1vw, 2.2rem);
  line-height: 1.12;
}

h2 {
  font-size: 1.1rem;
  line-height: 1.28;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.model-pill,
.status-pill,
.verdict-badge {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.model-pill {
  border-color: rgba(47, 101, 194, 0.25);
  background: #edf3ff;
  color: #244f97;
}

.status-pill.ready,
.verdict-badge.value {
  border-color: rgba(31, 138, 91, 0.34);
  background: #e7f7ee;
  color: var(--green-deep);
}

.status-pill.demo,
.verdict-badge.no-edge {
  border-color: rgba(185, 121, 22, 0.34);
  background: #fff1d7;
  color: #80500d;
}

.status-pill.error,
.verdict-badge.avoid {
  border-color: rgba(200, 74, 64, 0.32);
  background: #fde8e6;
  color: #96372f;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(540px, 1.05fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid rgba(190, 200, 192, 0.82);
  border-radius: 8px;
  background: rgba(251, 252, 250, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.input-panel,
.result-panel,
.json-panel {
  padding: 18px;
}

.panel:not(.input-panel):not(.result-panel):not(.json-panel) {
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-head.compact {
  margin-bottom: 12px;
}

.button-row {
  display: flex;
  gap: 8px;
}

.icon-button,
.ghost-button {
  display: inline-grid;
  min-width: 38px;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.icon-button:hover,
.ghost-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  box-shadow: var(--shadow-soft);
}

.icon-button:active,
.ghost-button:active,
.primary-button:active {
  transform: translateY(1px);
}

.ghost-button {
  padding: 0 12px;
  font-size: 0.85rem;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: #34413b;
  font-size: 0.84rem;
  font-weight: 900;
}

input,
textarea {
  width: 100%;
  border: 1px solid #ccd5ce;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
  resize: vertical;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  min-height: 92px;
}

input::placeholder,
textarea::placeholder {
  color: #8a958f;
}

input:focus,
textarea:focus {
  border-color: rgba(31, 138, 91, 0.72);
  background: #fffefb;
  box-shadow: 0 0 0 3px rgba(31, 138, 91, 0.13);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.primary-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #14231d, #24332e);
  color: #fff;
  padding: 0 15px;
  font-weight: 950;
  transition: filter 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.primary-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.primary-button:hover {
  filter: brightness(1.06);
  box-shadow: 0 12px 24px rgba(23, 33, 29, 0.18);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.results-stack {
  display: grid;
  gap: 16px;
}

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

.metric-card {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, var(--surface-2));
  padding: 12px;
}

.metric-card.primary-metric {
  border-color: rgba(47, 101, 194, 0.25);
  background: linear-gradient(180deg, #f5f8ff, #eef4ff);
}

.metric-card span,
.action-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  font-size: clamp(1.05rem, 1.8vw, 1.55rem);
  line-height: 1.12;
}

.probability-view {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 17px;
}

.probability-row {
  display: grid;
  gap: 8px;
}

.prob-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.prob-label b {
  color: var(--ink);
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebe6;
}

.bar-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  transition: width 420ms ease;
}

.bar-fill.market {
  background: linear-gradient(90deg, var(--blue), var(--aqua));
}

.bar-fill.ai {
  background: linear-gradient(90deg, var(--green), #58a668);
}

.action-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.action-strip > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px;
}

.action-strip strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}

.analysis-list,
.risk-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
  color: #2d3933;
  line-height: 1.55;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.score-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, var(--surface-2));
  padding: 11px;
}

.score-item span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score-item strong {
  display: block;
  margin-top: 7px;
  font-size: 1.12rem;
}

pre {
  max-height: 370px;
  margin: 0;
  overflow: auto;
  border: 1px solid #24352f;
  border-radius: 8px;
  background: #111a16;
  color: #dcefe5;
  padding: 14px;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.loading {
  position: relative;
}

.loading::after {
  content: "";
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.loading svg {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

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

@media (max-width: 1120px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 12px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
  }

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

  .field-grid,
  .field-grid.four,
  .metric-grid,
  .score-grid,
  .action-strip {
    grid-template-columns: 1fr;
  }

  .status-pill,
  .model-pill {
    justify-content: flex-start;
  }
}
