:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #eef5f2;
  --text: #17201d;
  --muted: #64736e;
  --border: #d8e1dd;
  --accent: #19715a;
  --accent-strong: #115e4a;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(23, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: 0;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

select {
  min-height: 42px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(25, 113, 90, 0.12);
}

.app-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.16;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 20px;
}

.key-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.key-form label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.identity-strip,
.metrics-grid,
.workspace-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.identity-strip {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.identity-strip.test-strip {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.identity-strip div,
.metric {
  min-width: 0;
}

.identity-strip span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.identity-strip strong {
  display: block;
  overflow: hidden;
  margin-top: 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(23, 32, 29, 0.04);
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.workspace-grid {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
}

.test-workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.panel {
  min-width: 0;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.test-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field-toolbar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field span,
.cost-pill span,
.result-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.upload-button {
  display: inline-flex;
  position: relative;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  overflow: hidden;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.upload-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-button.uploading {
  opacity: 0.72;
  pointer-events: none;
}

.full-span {
  grid-column: 1 / -1;
}

.is-hidden {
  display: none !important;
}

.option-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-button {
  min-width: 46px;
  min-height: 38px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  padding: 0 12px;
}

.option-button:hover,
.option-button.active {
  border-color: var(--accent);
  background: #fff;
  color: var(--accent-strong);
}

.submit-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding-top: 4px;
}

.cost-pill {
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 9px 12px;
}

.cost-pill strong {
  color: var(--accent-strong);
}

.result-body {
  display: grid;
  gap: 12px;
}

.result-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.result-strip div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 11px;
}

.result-strip strong {
  display: block;
  overflow: hidden;
  margin-top: 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-preview {
  display: grid;
  place-items: center;
  min-height: 260px;
  margin: 0 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdfc;
}

.media-preview video,
.media-preview img {
  display: block;
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  background: #0f1714;
}

.media-preview a {
  justify-self: start;
  padding: 10px 12px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.loading-state,
.task-message {
  display: grid;
  place-items: center;
  gap: 10px;
  min-width: min(100%, 360px);
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.loading-state strong,
.task-message strong {
  color: var(--text);
  font-size: 16px;
}

.loading-state span:last-child,
.task-message span {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.job-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

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

.ghost-button:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.request-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.request-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdfc;
}

.request-main {
  min-width: 0;
}

.request-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.request-main span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.request-status {
  font-weight: 800;
}

.request-status.ok {
  color: var(--accent-strong);
}

.request-status.error {
  color: var(--danger);
}

.empty-state {
  margin: 0;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.code-block {
  overflow-x: auto;
  margin: 0;
  padding: 18px;
  background: #111916;
  color: #e8f5ef;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateY(16px);
  border-radius: 8px;
  background: #17201d;
  color: #fff;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
  }
}

@media (max-width: 900px) {
  .topbar,
  .test-workspace,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .identity-strip,
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .identity-strip.test-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1120px);
    padding-top: 18px;
  }

  h1 {
    font-size: 26px;
  }

  .key-form,
  .test-form,
  .request-item {
    grid-template-columns: 1fr;
  }

  .identity-strip,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .identity-strip.test-strip {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .submit-row,
  .panel-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .result-strip {
    grid-template-columns: 1fr;
  }
}
