:root {
  color-scheme: light;
  --bg: #f4efe7;
  --panel: #fffaf3;
  --panel-2: #f0e4d3;
  --text: #1f1a17;
  --muted: #6b6258;
  --accent: #8f4e23;
  --accent-2: #dca76d;
  --border: #dfccb4;
  --danger: #a82b2b;
  --shadow: 0 18px 60px rgba(88, 55, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(220, 167, 109, 0.25), transparent 28%),
    linear-gradient(180deg, #f8f2ea 0%, var(--bg) 100%);
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 32px auto 56px;
}

.hero,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px;
  margin-bottom: 20px;
}

.panel {
  padding: 24px;
  margin-bottom: 20px;
}

.panel.muted {
  background: var(--panel-2);
}

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

h1,
h2,
h3 {
  margin: 0 0 12px;
}

.subtitle {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.5;
}

.section-help {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

.compact-top {
  margin-top: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 600;
}

label span {
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(143, 78, 35, 0.2);
  border-color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.flow-actions button {
  min-width: 120px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

button.ghost {
  background: #f0e1d0;
  color: var(--text);
}

button.danger-soft {
  background: #f3d7d7;
  color: var(--danger);
}

.output {
  margin: 0;
  min-height: 220px;
  max-height: 460px;
  overflow: auto;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #231f1d;
  color: #f7f1e8;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.output-short {
  min-height: 180px;
}

.helper-card {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fbf5ed;
}

.decision-group {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fbf5ed;
}

.decision-group[hidden] { display: none; }

#censusStageReviewJson { min-height: 320px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.helper-card strong {
  display: block;
  margin-bottom: 10px;
}

.helper-card p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.4;
}

.helper-card p:last-child {
  margin-bottom: 0;
}

code {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.08);
}

ol {
  margin: 0;
  padding-left: 20px;
  line-height: 1.6;
}

.status-ok {
  color: #157347;
}

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

.run-status-panel {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
}

.run-status-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

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

.run-status-card {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fbf5ed;
}

.run-status-card-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.timeline-block + .timeline-block {
  margin-top: 12px;
}

.timeline-label {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.run-status-text {
  margin-top: 14px;
  color: var(--text);
  line-height: 1.45;
  font-weight: 600;
}

.run-status-subtext {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.normalization-progress-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.normalization-progress-line progress {
  width: 100%;
  height: 14px;
  accent-color: var(--accent);
}

.normalization-progress-line strong {
  min-width: 52px;
  text-align: right;
}

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

.normalization-count-grid > div {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbf5ed;
}

.normalization-count-grid span,
.normalization-count-grid strong {
  display: block;
}

.normalization-count-grid span {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.normalization-items-header {
  display: flex;
  align-items: end;
  gap: 12px;
}

.normalization-items-header h3 {
  margin: 0 auto 10px 0;
}

.normalization-items-header label {
  min-width: 210px;
}

.normalization-items-header .small-control {
  min-width: 90px;
  width: 100px;
}

.normalization-items-header button {
  margin-bottom: 1px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #efe3d2;
  color: var(--text);
}

.status-badge.uploaded,
.status-badge.extracted,
.status-badge.validated,
.status-badge.chunked,
.status-badge.completed,
.status-badge.none,
.status-badge.neutral {
  background: #d7f0df;
  color: #157347;
}

.status-badge.queued,
.status-badge.in_progress,
.status-badge.polling,
.status-badge.extract\:queued,
.status-badge.extract\:in_progress,
.status-badge.validate\:queued,
.status-badge.validate\:in_progress,
.status-badge.chunk\:queued,
.status-badge.chunk\:in_progress,
.status-badge.import\:queued,
.status-badge.import\:in_progress,
.status-badge.watching {
  background: #f7e1b8;
  color: #7a4a00;
}

.status-badge.failed,
.status-badge.extract\:failed,
.status-badge.validate\:failed,
.status-badge.chunk\:failed,
.status-badge.import\:failed,
.status-badge.error {
  background: #f7d7d7;
  color: var(--danger);
}

.status-badge.stopped,
.status-badge.idle,
.status-badge.unknown {
  background: #efe3d2;
  color: var(--text);
}

.run-phase-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.run-phase-timeline span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f6eee4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.run-phase-timeline span.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.run-phase-timeline span.done {
  background: #d7f0df;
  border-color: #b9e4c6;
  color: #157347;
}

.run-phase-timeline span.failed {
  background: #f7d7d7;
  border-color: #efb5b5;
  color: var(--danger);
}

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

  .normalization-count-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .two-columns,
  .two-up,
  .run-status-grid,
  .correction-grid {
    grid-template-columns: 1fr;
  }

  .normalization-count-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .normalization-items-header {
    align-items: stretch;
    flex-direction: column;
  }

  .normalization-items-header h3 {
    margin-bottom: 0;
  }

  .normalization-items-header label {
    width: 100%;
  }

  .app-shell {
    width: min(100% - 20px, 1120px);
    margin-top: 20px;
  }

  .hero,
  .panel {
    padding: 18px;
  }
}

.normalization-table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.normalization-table {
  width: 100%;
  min-width: 800px;
  border-collapse: collapse;
  font-size: 13px;
}

.normalization-table th,
.normalization-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.normalization-table th {
  color: var(--muted);
  background: #fbf5ed;
  font-size: 11px;
  text-transform: uppercase;
}

.normalization-table tr:last-child td { border-bottom: 0; }
.normalization-table td:first-child { white-space: nowrap; font-weight: 600; }

.normalization-table td:last-child select {
  display: block;
  width: 180px;
  max-width: 100%;
  margin-bottom: 6px;
}

.normalization-table td:last-child button { white-space: nowrap; }
