:root {
  --navy: #0F2A44;
  --navy-2: #16375a;
  --purple: #6B4E9E;
  --purple-lt: #8f6fd0;
  --bg: #0b1a2b;
  --panel: #12263c;
  --panel-2: #17304a;
  --line: #223a56;
  --text: #e7eef6;
  --muted: #9db2c9;
  --ok: #3fb27f;
  --warn: #e0a340;
  --bad: #e0605f;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #143050 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px; background: rgba(15,42,68,.7);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 26px; color: var(--purple-lt);
  background: rgba(107,78,158,.18); width: 44px; height: 44px;
  display: grid; place-items: center; border-radius: 10px;
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.pipeline-legend { display: flex; align-items: center; gap: 8px; }
.step-chip {
  font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 999px;
}
.step-chip b { color: var(--purple-lt); margin-right: 4px; }
.arrow { color: var(--muted); }

/* Layout */
main { max-width: 980px; margin: 0 auto; padding: 28px 20px 80px; display: grid; gap: 20px; }

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
  min-width: 0;            /* don't let wide tables stretch the card past the page */
  overflow: hidden;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h2 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 10px; }
.card-head .n {
  background: var(--purple); color: #fff; width: 24px; height: 24px;
  border-radius: 7px; display: grid; place-items: center; font-size: 13px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 34px; text-align: center; cursor: pointer; transition: .18s;
  background: rgba(255,255,255,.02);
}
.dropzone.drag { border-color: var(--purple-lt); background: rgba(107,78,158,.12); }
.dz-icon { font-size: 34px; color: var(--purple-lt); }
.dropzone p { margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 12px; }
.link { background: none; border: none; color: var(--purple-lt); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }

.upload-meta { display: flex; align-items: center; gap: 12px; margin: 14px 0 8px; flex-wrap: wrap; }
.pill { background: var(--purple); color: #fff; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.cols { color: var(--muted); font-size: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; min-width: 0; max-width: 100%; }
.table-wrap td { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: rgba(0,0,0,.15); }
tbody tr:hover { background: rgba(255,255,255,.03); }

/* Company selector */
.company-bar .card-head { margin-bottom: 12px; }
.company-bar select { font-size: 15px; font-weight: 600; max-width: 340px; }

/* Config */
.explainer { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 18px; max-width: 640px; }
.fieldhint { color: var(--muted); font-size: 11.5px; font-weight: 400; opacity: .85; display: block; margin-top: 3px; }
.advanced { margin: 4px 0 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--purple-lt); font-size: 13px; font-weight: 600; margin-bottom: 10px; list-style: none; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: "▸ "; }
.advanced[open] summary::before { content: "▾ "; }
.config-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 20px; margin-bottom: 18px; align-items: start; }
.limit-row { display: flex; gap: 8px; align-items: center; }
.limit-row input { flex: 1; min-width: 0; }
.btn.small { padding: 9px 14px; font-size: 13px; white-space: nowrap; }
.ctl { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.ctl span { font-weight: 500; }
.ctl select, .ctl input[type=number] {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font: inherit;
}
.ctl.toggle { flex-direction: row; align-items: center; gap: 10px; }
.ctl.toggle input { width: 18px; height: 18px; accent-color: var(--purple); }

/* Buttons */
.btn {
  display: inline-block; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 11px 18px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: .15s;
}
.btn:hover { border-color: var(--purple-lt); }
.btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.primary:hover { background: var(--purple-lt); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.cost-note { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

/* Progress */
.run-status { font-size: 12px; color: var(--warn); font-weight: 600; }
.run-status.done { color: var(--ok); }
.run-status.error { color: var(--bad); }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--purple), var(--purple-lt)); transition: width .3s; }
.progress-text { color: var(--muted); font-size: 12px; margin: 6px 0 16px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.stat span { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat.ok span { color: var(--ok); }
.stat.warn span { color: var(--warn); }
.stat.bad span { color: var(--bad); }
.stat.err span { color: var(--bad); }
.stat.cost span { color: var(--purple-lt); }

/* Lead table badges */
.lead-table td { white-space: normal; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.pending { opacity: .6; }
.badge.active { background: rgba(107,78,158,.25); color: var(--purple-lt); border-color: var(--purple); }
.badge.ok { background: rgba(63,178,127,.16); color: var(--ok); border-color: rgba(63,178,127,.4); }
.badge.warn { background: rgba(224,163,64,.16); color: var(--warn); border-color: rgba(224,163,64,.4); }
.badge.bad { background: rgba(224,96,95,.16); color: var(--bad); border-color: rgba(224,96,95,.4); }

/* Per-cell DQ reason in the live table */
.cell-reason { font-size: 11px; color: var(--muted); margin-top: 5px; line-height: 1.4; max-width: 360px; white-space: normal; }

/* Disqualified reasons panel in results */
.dq-panel { margin-top: 18px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.dq-panel summary { cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--bad); list-style: none; }
.dq-panel summary::-webkit-details-marker { display: none; }
.dq-panel summary::before { content: "▸ "; }
.dq-panel[open] summary::before { content: "▾ "; }
.dq-item { padding: 10px 16px; border-top: 1px solid var(--line); }
.dq-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.dq-reason { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Downloads + previews */
.downloads { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.cost-final { color: var(--muted); font-size: 13px; margin-left: auto; }
.cost-final b { color: var(--purple-lt); }
.email-card { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; overflow: hidden; background: var(--bg); }
.email-card summary { padding: 12px 16px; cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.email-card summary::-webkit-details-marker { display: none; }
.email-card summary .co { color: var(--muted); font-weight: 400; font-size: 12px; }
.email-body { padding: 4px 16px 16px; }
.eml { border-top: 1px solid var(--line); padding: 12px 0; }
.eml h4 { margin: 0 0 4px; font-size: 13px; color: var(--purple-lt); }
.eml .subj { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.eml p { margin: 0; font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
.viol { color: var(--warn); font-size: 11px; margin-top: 6px; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bad); color: #fff; padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; z-index: 50; }

.hidden { display: none !important; }

@media (max-width: 720px) {
  .pipeline-legend { display: none; }
  .config-grid, .stats { grid-template-columns: 1fr 1fr; }
}
