:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #182033;
  --muted: #6f7890;
  --line: #e7eaf1;
  --nav: #11172a;
  --nav2: #1a2340;
  --brand: #6758e8;
  --brand-soft: #edf2ff;
  --component: #506fda;
  --risk: #b7476b;
  --control: #2f8a72;
  --amber: #b7791f;
  --red: #b43d3a;
  --shadow: 0 15px 38px rgba(35, 44, 75, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button, .link-button {
  min-height: 40px;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 9px 14px;
  font-weight: 760;
  cursor: pointer;
}
button:disabled { cursor: not-allowed; opacity: .5; }

.app-header {
  min-height: 66px;
  padding: 0 max(26px, calc((100vw - 1220px) / 2));
  background: linear-gradient(90deg, var(--nav), var(--nav2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 5px 20px rgba(12, 18, 38, .18);
}
.app-header > div:first-child {
  display: grid;
  grid-template-columns: 31px 1fr;
  column-gap: 11px;
  align-items: center;
}
.app-header > div:first-child::before {
  content: "AI";
  width: 31px;
  height: 31px;
  border-radius: 10px;
  background: linear-gradient(135deg, #9287ff, #5d73e8);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
}
.eyebrow, .kicker {
  margin: 0 0 3px;
  text-transform: uppercase;
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
}
.app-header .eyebrow { display: none; }
h1 { margin: 0; font-size: 20px; letter-spacing: 0; font-weight: 760; }
h2 { margin: 0; font-size: 21px; letter-spacing: 0; }
.service-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #dce3f7;
  font-size: 12px;
  border: 1px solid #ffffff29;
  padding: 7px 10px;
  border-radius: 999px;
}
.service-state span:first-child { width: 9px; height: 9px; border-radius: 50%; background: #d49b42; }
.service-state.ready span:first-child { background: #56d99b; }

.steps {
  max-width: 1220px;
  margin: 18px auto 0;
  padding: 4px;
  display: inline-flex;
  background: #eceff5;
  border: 0;
  border-radius: 11px;
  transform: translateX(max(24px, calc((100vw - 1220px) / 2)));
}
.step {
  background: transparent;
  color: #697289;
  border: 0;
  border-radius: 8px;
  min-width: 126px;
  height: 40px;
  padding: 0 16px;
  font-size: 13px;
}
.step span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  margin-right: 7px;
  background: #dde2ec;
}
.step.active {
  color: #242d46;
  background: #fff;
  box-shadow: 0 3px 10px rgba(38, 46, 79, .08);
}
.step.active span { background: var(--brand); color: #fff; }

main { max-width: 1220px; margin: 0 auto; padding: 18px 24px 60px; }
.panel {
  display: none;
  min-height: 460px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel.active { display: block; }
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.section-head.compact { margin-bottom: 0; }
.section-meta { max-width: 560px; margin: 0; color: var(--muted); text-align: right; font-size: 12px; }

.model-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.model-card {
  display: block;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(37, 45, 78, .06);
}
.model-card:has(input:checked) {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(103, 88, 232, .14);
}
.model-card input { position: absolute; opacity: 0; }
.model-top { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.model-top strong { font-size: 16px; }
.tag { border-radius: 999px; padding: 3px 7px; background: var(--brand-soft); color: var(--brand); font-size: 11px; font-weight: 800; }
.model-card p { min-height: 42px; color: var(--muted); }
.model-price { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 10px; }
.model-price strong { color: var(--component); font-size: 17px; }
.model-rates { margin-top: 8px; color: var(--muted); font-size: 12px; }

.custom-toggle { margin: 18px 0 10px; font-weight: 760; }
.custom-toggle input { accent-color: var(--brand); }
.custom-fields {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fcfdff;
}
.custom-fields[hidden], [hidden] { display: none !important; }
.field { min-width: 0; }
.field.wide { grid-column: span 2; }
.field.small { max-width: 140px; }
.field label { display: block; margin-bottom: 6px; color: #495368; font-size: 12px; font-weight: 800; }
.field input, .field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd2dc;
  border-radius: 8px;
  background: white;
  padding: 9px 10px;
  color: var(--ink);
}
.field input:focus, .field select:focus { outline: 3px solid rgba(103, 88, 232, .14); border-color: var(--brand); }
.api-example { grid-column: 1 / -1; }
.api-example summary { color: var(--component); cursor: pointer; font-weight: 760; }
pre {
  overflow: auto;
  background: #192237;
  color: #e9eeff;
  border-radius: 8px;
  padding: 12px;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.connection-actions, .form-actions, .run-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.connection-actions #connection-result { flex: 1; color: var(--muted); white-space: pre-wrap; }
.primary { background: var(--brand); color: white; border-color: var(--brand); }
.secondary { background: white; color: #39425a; border-color: var(--line); }
.text-button { background: transparent; color: var(--component); padding-inline: 6px; }

.project-fields { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.upload-zone {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 145px;
  border: 1px dashed #aab2c1;
  border-radius: 14px;
  background: #fcfdff;
  padding: 22px;
  cursor: pointer;
  text-align: center;
}
.upload-zone:hover { border-color: var(--brand); background: #f9faff; }
.upload-zone strong { font-size: 16px; }
.upload-zone span { margin-top: 7px; color: var(--muted); overflow-wrap: anywhere; }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.cost-summary {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 14px;
  background: #fff7e8;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  padding: 11px 13px;
  color: #6d4a12;
}
.form-actions { justify-content: space-between; }

.progress-track { height: 12px; border-radius: 999px; background: #e4e8f0; overflow: hidden; }
#progress-bar { width: 0; height: 100%; background: var(--brand); transition: width .35s ease; }
.progress-copy { display: grid; grid-template-columns: 70px 1fr auto; gap: 12px; margin: 9px 0 22px; color: var(--muted); }
.progress-copy strong { color: var(--brand); }
.stage-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.stage-list li { min-height: 58px; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.stage-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #e3e7ef; color: var(--muted); font-size: 11px; font-weight: 900; }
.stage-list li.completed .stage-icon { background: var(--control); color: white; }
.stage-list li.running .stage-icon { background: var(--component); color: white; }
.stage-message { color: var(--muted); font-size: 12px; text-align: right; }
.error-box { margin-top: 14px; border-left: 4px solid var(--red); background: #fff0ef; color: #81312d; border-radius: 8px; padding: 12px; white-space: pre-wrap; }
.link-button { display: inline-flex; align-items: center; text-decoration: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }

.history-band {
  margin-top: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.table-wrap { overflow-x: auto; background: white; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
td:first-child { white-space: normal; min-width: 220px; }
.status { border-radius: 999px; padding: 3px 7px; background: #f0f2f6; font-size: 11px; font-weight: 800; }
.status.completed { color: var(--control); background: #eaf8f3; }
.status.failed { color: var(--red); background: #fff0ef; }
a { color: var(--component); font-weight: 760; }

@media (max-width: 850px) {
  .app-header { min-height: 66px; padding: 0 18px; }
  h1 { font-size: 18px; }
  .steps { margin-top: 14px; transform: none; margin-left: 16px; max-width: calc(100vw - 32px); overflow-x: auto; }
  .step { min-width: 118px; padding: 0 10px; }
  main { padding: 16px 16px 44px; }
  .section-head { align-items: start; flex-direction: column; gap: 7px; }
  .section-meta { text-align: left; }
  .model-grid, .project-fields, .upload-grid { grid-template-columns: 1fr; }
  .custom-fields { grid-template-columns: 1fr 1fr; }
  .field.wide { grid-column: span 2; }
  .progress-copy { grid-template-columns: 64px 1fr; }
  #actual-cost { grid-column: 2; }
}
@media (max-width: 520px) {
  .service-state { display: none; }
  .custom-fields { grid-template-columns: 1fr; }
  .field.wide, .api-example { grid-column: 1; }
  .connection-actions { align-items: stretch; flex-direction: column; }
  .connection-actions button { width: 100%; }
  .stage-list li { grid-template-columns: 28px 1fr; padding: 8px 0; }
  .stage-message { grid-column: 2; text-align: left; }
}
