:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --panel: #ffffff;
  --ink: #20242a;
  --muted: #6d7380;
  --line: #d8d3c7;
  --blue: #276ef1;
  --blue-dark: #174ea6;
  --green: #1f7a4d;
  --red: #a23a33;
  --amber: #a16107;
  --teal: #0f766e;
  --shadow: 0 12px 30px rgba(34, 31, 24, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px clamp(16px, 4vw, 40px) 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 760;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  font-weight: 720;
}

h3 {
  font-size: 15px;
  font-weight: 720;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(280px, 420px) minmax(360px, 1fr);
  gap: 18px;
  padding: 20px clamp(16px, 4vw, 40px) 34px;
}

.control-panel,
.run-list,
.run-detail {
  min-width: 0;
  align-self: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.auth-form,
.run-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.auth-form {
  border-bottom: 1px solid var(--line);
}

.auth-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.token-row input {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--ink);
  font-size: 14px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.primary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: white;
}

.primary-button:hover {
  background: var(--blue-dark);
}

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

.icon-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button:hover {
  border-color: var(--blue);
}

.status-grid {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
}

.status-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 64%);
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}

.status-item span:first-child {
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-item .state-pill {
  justify-self: end;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  max-width: 100%;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.state-pill.good {
  background: #e7f4ec;
  color: var(--green);
}

.state-pill.bad {
  background: #f8e7e5;
  color: var(--red);
}

.state-pill.warn {
  background: #fff1d7;
  color: var(--amber);
}

.state-pill.neutral {
  background: #edf0f4;
  color: #46505e;
}

.runs-list {
  display: grid;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.run-row {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 82px;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.run-row:hover,
.run-row.active {
  background: #f3f7ff;
}

.run-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.run-id {
  overflow: hidden;
  font-size: 13px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-meta {
  color: var(--muted);
  font-size: 12px;
}

.detail-panel {
  display: grid;
  gap: 18px;
  padding: 16px;
}

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

.run-summary-strip > div,
.api-card,
.copy-block,
.report-box {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdfa;
}

.run-summary-strip .label,
.api-card .label,
.copy-block .label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.run-summary-strip strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.tab-button,
.segment-button {
  min-height: 36px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 740;
}

.tab-button {
  padding: 0 10px 10px;
}

.tab-button.active {
  border-color: var(--blue);
  color: var(--ink);
}

.tab-panel {
  display: grid;
  gap: 18px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(6, minmax(82px, 1fr));
  gap: 8px;
}

.step {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.step span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #edf0f4;
  color: #46505e;
  font-size: 12px;
  font-weight: 780;
}

.step strong {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.step.done span,
.step.active span {
  background: var(--blue);
  color: white;
}

.step.bad span {
  background: var(--red);
  color: white;
}

.step.active {
  border-color: var(--blue);
  background: #f3f7ff;
}

.empty-state {
  min-height: 180px;
  place-items: center;
  color: var(--muted);
}

.metric-grid,
.file-grid,
.batch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.metric,
.file-link,
.batch-link {
  min-width: 0;
  min-height: 68px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdfa;
}

.metric .label,
.file-link .label,
.batch-link .label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.metric .value {
  overflow-wrap: anywhere;
  font-size: 22px;
  font-weight: 780;
}

.report-box {
  display: grid;
  gap: 8px;
}

.report-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.7fr) minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.report-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.report-row span {
  color: var(--muted);
}

.report-row strong {
  overflow-wrap: anywhere;
}

.table-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, auto) auto;
  gap: 10px;
  margin-bottom: 10px;
}

.table-controls input,
.table-controls select {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: white;
}

.compact-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  font-size: 13px;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: white;
  font-size: 12px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #fbfaf7;
  color: var(--muted);
  font-weight: 780;
}

td {
  overflow-wrap: anywhere;
}

tr.winner-shipcaptain td:first-child {
  border-left: 4px solid var(--green);
}

tr.winner-shipstation td:first-child {
  border-left: 4px solid var(--blue);
}

tr.winner-tie td:first-child {
  border-left: 4px solid var(--amber);
}

tr.winner-unknown td:first-child {
  border-left: 4px solid var(--red);
}

.table-footer,
.empty-inline {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.empty-inline {
  display: grid;
  min-height: 74px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdfa;
}

.file-action-list {
  display: grid;
  gap: 10px;
}

.file-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdfa;
}

.file-action-row.active {
  border-color: var(--blue);
  background: #f3f7ff;
}

.file-action-row strong,
.file-action-row span {
  display: block;
  overflow-wrap: anywhere;
}

.file-action-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

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

.file-link a,
.link-button,
.batch-link a {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.link-button:hover {
  color: var(--blue-dark);
  text-decoration: underline;
}

.log-list {
  display: grid;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.log-row {
  display: grid;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.log-row:last-child {
  border-bottom: 0;
}

.log-row summary {
  display: grid;
  grid-template-columns: 126px 58px 1fr;
  gap: 10px;
  min-width: 0;
  padding: 9px 10px;
  cursor: pointer;
}

.log-row pre,
.code-block {
  margin: 0;
  overflow: auto;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #f7f8fa;
  font-size: 12px;
}

.log-time,
.log-level {
  color: var(--muted);
}

.log-message {
  overflow-wrap: anywhere;
}

.segmented-control {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.segment-button {
  min-height: 34px;
  padding: 0 10px;
  border-bottom: 0;
  border-right: 1px solid var(--line);
}

.segment-button:last-child {
  border-right: 0;
}

.segment-button.active {
  background: var(--blue);
  color: white;
}

.error-box {
  padding: 12px;
  border: 1px solid #e7b0aa;
  border-radius: 6px;
  background: #fff1ef;
  color: var(--red);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.structured-error {
  display: grid;
  gap: 5px;
}

.structured-error small {
  color: var(--muted);
}

.api-card a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

.copy-block {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.copy-block .section-heading-row {
  margin-bottom: 0;
}

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

  .run-detail {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

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

  .run-summary-strip,
  .stepper,
  .table-controls,
  .file-action-row,
  .report-row {
    grid-template-columns: 1fr;
  }

  .file-actions,
  .section-heading-row {
    align-items: stretch;
    flex-direction: column;
  }
}
