:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #19201c;
  --muted: #657066;
  --line: #dfe4dc;
  --accent: #176b5b;
  --accent-dark: #0f4d43;
  --amber: #b87216;
  --red: #b33838;
  --blue: #315f8f;
  --soft: #eef3ef;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost {
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost:hover {
  background: #e4ece6;
}

.danger {
  background: #f5e9e8;
  color: var(--red);
  border: 1px solid #ebcfcc;
}

.danger:hover {
  background: #efd9d6;
}

.topbar {
  min-height: 96px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

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

h1 {
  font-size: 28px;
  line-height: 1.12;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.status-pill {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.85fr) minmax(520px, 1.15fr);
  gap: 18px;
  padding: 18px;
}

.simple-layout {
  display: grid;
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
}

.work-panel {
  display: grid;
  gap: 16px;
}

.panel-heading,
.subhead,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.button-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.subhead {
  margin-top: 18px;
  margin-bottom: 8px;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 13px;
}

.field.compact {
  margin-top: 10px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.saved-clients {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.client-tile {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  text-align: left;
}

.client-tile:hover,
.client-tile.active {
  border-color: var(--accent);
  background: #edf6f2;
}

.client-tile strong {
  display: block;
  font-size: 14px;
}

.client-tile span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 290px;
}

.steps {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.7fr;
  gap: 12px;
}

.step-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  min-height: 156px;
  padding: 14px;
}

.step-number {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.upload-step {
  cursor: pointer;
}

.upload-step:hover {
  border-color: var(--accent);
  background: #edf6f2;
}

.upload-step input {
  display: none;
}

.upload-step strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  padding: 0 14px;
  margin-top: 14px;
}

.upload-step span:not(.step-number) {
  color: var(--muted);
  display: block;
  margin-top: 8px;
}

.quick-count {
  margin-top: 14px;
}

.quick-count strong {
  display: block;
  color: var(--accent);
  font-size: 48px;
  line-height: 1;
}

.quick-count span {
  color: var(--muted);
  font-weight: 700;
}

.empty-note {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
}

input,
select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(23, 107, 91, 0.15);
}

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

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

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

.checks {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checks input,
.required {
  width: 17px;
  height: 17px;
  min-height: 0;
}

.mapping-head,
.mapping-row,
.header-row {
  display: grid;
  align-items: center;
  gap: 8px;
}

.mapping-head {
  grid-template-columns: 1.1fr 0.7fr 1fr 1fr 42px 36px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 36px 6px 0;
}

.mapping-row {
  grid-template-columns: 1.1fr 0.7fr 1fr 1fr 42px 36px;
  margin-bottom: 8px;
}

.header-row {
  grid-template-columns: 1fr 1.4fr 36px;
  margin-bottom: 8px;
}

.icon-btn {
  min-height: 36px;
  height: 36px;
  width: 36px;
  padding: 0;
}

.actions {
  margin-top: 18px;
}

.dropzone {
  margin-top: 16px;
  min-height: 126px;
  border: 1px dashed #aeb9ae;
  border-radius: 8px;
  background: #fbfcfb;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  cursor: pointer;
}

.dropzone input {
  display: none;
}

.dropzone strong {
  display: block;
  font-size: 18px;
}

.dropzone span {
  color: var(--muted);
  margin-top: 6px;
  display: block;
  max-width: 540px;
}

.progress-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 16px 0;
  background: #fbfcfb;
}

.progress-status {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
}

.progress-status span:last-child {
  color: var(--accent);
  font-size: 16px;
}

.progress-bar {
  height: 10px;
  border-radius: 6px;
  background: var(--line);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 0.2s ease;
}

.progress-current {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.client-quota-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.quota-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.quota-row:last-child {
  margin-bottom: 0;
}

.quota-row span {
  color: var(--muted);
  font-size: 13px;
}

.quota-row strong {
  color: var(--accent);
  font-size: 16px;
}

#runControls {
  margin-top: 12px;
}

.muted {
  color: var(--muted);
}

.usage-readout {
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fbfcfb;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-running {
  background: #e7f5ee;
  color: #1f8a4c;
}

.status-paused {
  background: #fef3e0;
  color: var(--amber);
}

.status-limit_exhausted {
  background: #fbe9e8;
  color: var(--red);
}

.status-completed {
  background: #e8eef7;
  color: var(--blue);
}

.status-stopped {
  background: #f0e8f5;
  color: #7b3fa0;
}

.run-limit-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.run-limit-field input {
  width: 80px;
  min-height: 36px;
  font-size: 13px;
  padding: 6px 8px;
}

.pending-run-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  margin-bottom: 8px;
}

.pending-run-card strong {
  display: block;
  font-size: 14px;
}

.pending-run-card span {
  color: var(--muted);
  font-size: 13px;
}

.progress-counts {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 700;
  flex-wrap: wrap;
}

.progress-counts .count-success {
  color: var(--accent);
}

.progress-counts .count-duplicate {
  color: var(--amber);
}

.progress-counts .count-failed {
  color: var(--red);
}

.mapping-suggestion {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #f3fbf6;
  font-size: 13px;
}

.mapping-suggestion ul {
  margin: 8px 0 10px;
  padding-left: 18px;
}

.mapping-suggestion .button-group {
  margin-top: 4px;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfb;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.metric.success strong {
  color: var(--accent);
}

.metric.duplicate strong {
  color: var(--amber);
}

.metric.failed strong {
  color: var(--red);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: 360px;
}

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

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

th {
  background: var(--soft);
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 1;
}

.history-heading {
  margin-top: 0;
}

.advanced-panel summary {
  cursor: pointer;
  list-style: none;
}

.advanced-panel summary::-webkit-details-marker {
  display: none;
}

.advanced-panel summary span {
  display: grid;
  gap: 3px;
}

.advanced-panel summary strong {
  font-size: 18px;
}

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

.settings-heading {
  margin-top: 18px;
}

.runs {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.run-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.run-item span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 3px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #17201b;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  max-width: 360px;
}

@media (max-width: 980px) {
  .layout,
  .steps {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar,
  .panel-heading,
  .actions,
  .run-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout,
  .simple-layout {
    padding: 10px;
  }

  .two,
  .three,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .mapping-head {
    display: none;
  }

  .mapping-row,
  .header-row {
    grid-template-columns: 1fr;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
  }
}

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 1000;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}

.login-error {
  background: #fbe9e8;
  border: 1px solid #ebcfcc;
  color: var(--red);
  border-radius: 7px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 13px;
}

/* ── Radio group (limit type) ────────────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

.radio-group input {
  width: 16px;
  height: 16px;
  min-height: 0;
  cursor: pointer;
}
