:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #18202f;
  --muted: #667085;
  --line: #d8dee9;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #027a48;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: inherit;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.page {
  margin: 0 auto;
  max-width: 1180px;
  padding: 28px 24px 48px;
}

.section-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 20px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.button,
button {
  align-items: center;
  background: #eef2f7;
  border: 1px solid #cdd5df;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  text-decoration: none;
  white-space: nowrap;
}

.button.primary,
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.button.primary:hover,
button.primary:hover {
  background: var(--primary-dark);
}

.button.danger,
button.danger {
  background: #fff1f0;
  border-color: #fecdca;
  color: var(--danger);
}

.button.small {
  min-height: 30px;
  padding: 4px 10px;
}

.app-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
}

.app-card,
.empty-state,
.form-panel,
.toolbar-band,
.upload-band,
.table-wrap,
.job-summary,
.split > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.app-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 160px;
  padding: 18px;
}

.app-card.is-disabled {
  opacity: 0.72;
}

.app-card-top {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.app-card-title {
  text-decoration: none;
}

.app-card p {
  color: var(--muted);
  margin: 4px 0 0;
}

.stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 1fr);
  margin: auto 0 0;
}

.stats dt {
  color: var(--muted);
  font-size: 12px;
}

.stats dd {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.empty-state {
  padding: 36px;
  text-align: center;
}

.empty-state p,
.muted {
  color: var(--muted);
}

.form-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.notice {
  background: #ecfdf3;
  border: 1px solid #abefc6;
  border-radius: 6px;
  color: #075e45;
  padding: 12px 14px;
}

.settings-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: #344054;
  font-weight: 700;
}

input,
textarea {
  background: #ffffff;
  border: 1px solid #cdd5df;
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}

textarea {
  min-height: 160px;
  resize: vertical;
}

.actions,
.row-actions,
.inline-form,
.upload-band form {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.actions form,
.row-actions form {
  margin: 0;
}

.row-actions {
  align-items: center;
  gap: 8px;
}

.inline-form label {
  width: 140px;
}

.toolbar-band,
.upload-band {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 16px;
}

.sourcing-upload {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 18px;
}

.sourcing-upload form {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.sourcing-summary {
  margin-top: 0;
}

.sourcing-result-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 22px;
}

.markdown-panel,
.log-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 16px;
}

.markdown-body {
  color: #18202f;
  overflow-wrap: anywhere;
}

.markdown-body h1 {
  font-size: 26px;
  margin: 0 0 14px;
}

.markdown-body h2 {
  border-top: 1px solid var(--line);
  font-size: 20px;
  margin: 24px 0 10px;
  padding-top: 18px;
}

.markdown-body h3,
.markdown-body h4 {
  font-size: 16px;
  margin: 18px 0 8px;
}

.markdown-body p {
  margin: 0 0 12px;
}

.markdown-body ul {
  margin: 0 0 14px;
  padding-left: 22px;
}

.markdown-body table {
  margin: 10px 0 18px;
  min-width: 680px;
}

.markdown-body pre {
  background: #111827;
  border-radius: 6px;
  color: #e5e7eb;
  overflow: auto;
  padding: 12px;
}

.markdown-body code {
  font-family: Consolas, Monaco, monospace;
  font-size: 0.92em;
}

.compact-log {
  height: 260px;
}

.worker-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.table-head,
.panel-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 22px 0 10px;
}

.counts {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
}

th {
  color: #475467;
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  background: #eef2f7;
  border-radius: 999px;
  color: #344054;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
}

.status-pill.running {
  background: #e0f2fe;
  color: #075985;
}

.status-pill.done {
  background: #dcfae6;
  color: var(--ok);
}

.status-pill.failed,
.status-pill.failed_missing_result,
.status-pill.crashed,
.status-pill.stopped,
.status-pill.stopping {
  background: #fee4e2;
  color: var(--danger);
}

.status-pill.pending {
  background: #fef0c7;
  color: var(--warn);
}

.job-summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 18px;
  padding: 16px;
}

.job-summary span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.job-summary strong {
  display: block;
  font-size: 18px;
  margin-top: 4px;
  word-break: break-word;
}

.split {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.split > div {
  min-width: 0;
  padding: 16px;
}

.log-view,
.json-view {
  background: #111827;
  border-radius: 6px;
  color: #e5e7eb;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  height: 380px;
  margin: 0 0 16px;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.json-view {
  background: #ffffff;
  border: 1px solid var(--line);
  color: #101828;
}

@media (max-width: 760px) {
  .topbar,
  .section-head,
  .toolbar-band,
  .upload-band {
    align-items: stretch;
    flex-direction: column;
  }

  .job-summary,
  .split,
  .settings-grid,
  .sourcing-result-layout,
  .sourcing-upload form {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-actions .button {
  white-space: nowrap;
}

.button.disabled,
.button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- File upload ---------- */

.upload-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 18px;
}

.upload-panel > h2 {
  font-size: 15px;
  margin: 0 0 14px;
}

.uploader {
  display: grid;
  gap: 14px;
}

.dropzone {
  align-items: center;
  background: #fbfcfe;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
  padding: 26px 20px;
  position: relative;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dropzone:hover {
  background: #f4faf9;
  border-color: var(--primary);
}

.dropzone:focus-within {
  border-color: var(--primary);
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.dropzone.is-dragging {
  background: #ecfdf5;
  border-color: var(--primary);
  border-style: solid;
}

/* Hidden but still focusable, so the keyboard can reach the picker. */
.dropzone input[type="file"] {
  height: 1px;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  width: 1px;
}

.dropzone-icon {
  color: var(--primary);
  display: block;
  margin-bottom: 4px;
}

.dropzone-title {
  font-weight: 700;
  margin: 0;
}

.dropzone-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.dropzone-hint em {
  color: var(--primary);
  font-style: normal;
  font-weight: 700;
  text-decoration: underline;
}

.file-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.file-item {
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  padding: 8px 10px;
}

.file-icon {
  align-items: center;
  color: var(--muted);
  display: flex;
}

.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.file-remove {
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  min-height: 0;
  padding: 0 6px;
}

.file-remove:hover {
  background: #fff1f0;
  color: var(--danger);
}

.uploader-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.uploader-summary {
  color: var(--muted);
  font-size: 13px;
}

.uploader-error {
  background: #fff4f3;
  border: 1px solid #fecdca;
  border-radius: 8px;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 10px;
}

.progress {
  background: #e6eaf0;
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-bar {
  background: var(--primary);
  height: 100%;
  transition: width 0.2s ease;
  width: 0;
}

/* Bytes are sent but the server is still working: show motion, not a number. */
.progress-bar.is-indeterminate {
  animation: progress-pulse 1.1s ease-in-out infinite;
}

@keyframes progress-pulse {
  50% { opacity: 0.45; }
}

.uploader.is-busy .dropzone {
  cursor: default;
  opacity: 0.55;
  pointer-events: none;
}

.uploader.is-busy .file-remove {
  pointer-events: none;
  visibility: hidden;
}

.spinner {
  animation: spin 0.7s linear infinite;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  border-top-color: #ffffff;
  display: inline-block;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  width: 14px;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .progress-bar { transition: none; }
  .progress-bar.is-indeterminate { animation: none; }
}

button[disabled],
.button[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}

.stamp {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
