:root {
  color-scheme: light;
  --bg: #eef3ef;
  --bg-top: #f8fbf7;
  --panel: #ffffff;
  --panel-warm: #fbfcf8;
  --surface-green: #edf8f2;
  --surface-blue: #edf5fb;
  --surface-amber: #fbf2df;
  --surface-violet: #f3effb;
  --text: #20241f;
  --muted: #6f766d;
  --line: #dfe4dc;
  --line-strong: #cbd5c9;
  --accent: #2f6f4e;
  --accent-strong: #24593e;
  --accent-soft: #e7f2eb;
  --blue-soft: #e9f0f7;
  --blue: #315f8a;
  --amber-soft: #f7eedf;
  --violet-soft: #f0edf8;
  --violet: #67538a;
  --danger: #b33b33;
  --warning: #9a681b;
  --info: #315f8a;
  --shadow: 0 1px 2px rgba(22, 31, 22, 0.07);
  --shadow-raised: 0 14px 34px rgba(22, 31, 22, 0.1);
  --shadow-soft: 0 8px 22px rgba(22, 31, 22, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, var(--bg-top) 0, var(--bg) 420px),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  box-shadow: 0 1px 14px rgba(20, 29, 21, 0.05);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
  text-decoration: none;
}

.brand::before {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  content: "";
}

.nav,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover {
  color: var(--text);
}

.nav form {
  margin: 0;
}

.nav-logout {
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.nav-logout:hover {
  color: var(--text);
}

.shell {
  width: min(1500px, calc(100vw - 40px));
  margin: 34px auto 56px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 16px;
}

.page-head p,
.muted,
.hint,
small {
  color: var(--muted);
}

.hint {
  max-width: 760px;
  margin-bottom: 16px;
}

.button,
button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(47, 111, 78, 0.18);
}

.button.primary:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.button.danger {
  border-color: #e4b7b2;
  color: var(--danger);
}

.button:hover,
button.button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.panel,
.stat,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.panel {
  max-width: 100%;
  padding: 22px;
  margin-bottom: 18px;
}

.panel > h2:first-child {
  display: flex;
  align-items: center;
  gap: 9px;
}

.panel > h2:first-child::before {
  width: 8px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
}

.notice.error {
  border-color: #ecc7c3;
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.row-link {
  display: block;
  max-width: 620px;
  overflow-wrap: anywhere;
  font-weight: 650;
  text-decoration: none;
}

.row-link:hover {
  text-decoration: underline;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef1ea;
  color: var(--muted);
  white-space: nowrap;
}

.status.ready_to_crawl,
.status.crawled,
.status.completed {
  background: #e5f2e9;
  color: var(--accent-strong);
}

.status.completed_with_warnings {
  background: #f6eedf;
  color: var(--warning);
}

.status.pending,
.status.discovering,
.status.crawling {
  background: #edf3f8;
  color: var(--info);
}

.status.failed {
  background: #f7e8e6;
  color: var(--danger);
}

.status.paused,
.status.skipped {
  background: #f6eedf;
  color: var(--warning);
}

.empty {
  color: var(--muted);
  text-align: center;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  min-width: 0;
}

.form-grid label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.compact-form {
  margin-top: 10px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.run-form {
  display: grid;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.run-form.panel > h2:first-child::before {
  content: none;
}

.form-section {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 24px;
  min-width: 0;
  padding: 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--surface-green) 0, var(--surface-green) 260px, #ffffff 260px);
}

.form-section:nth-of-type(2) {
  background: linear-gradient(90deg, var(--surface-blue) 0, var(--surface-blue) 260px, #ffffff 260px);
}

.form-section:nth-of-type(3) {
  background: linear-gradient(90deg, var(--surface-amber) 0, var(--surface-amber) 260px, #ffffff 260px);
}

.form-section:nth-of-type(4) {
  background: linear-gradient(90deg, var(--surface-violet) 0, var(--surface-violet) 260px, #ffffff 260px);
}

.form-section:last-of-type {
  border-bottom: 0;
}

.section-head {
  min-width: 0;
  padding-top: 2px;
}

.section-head h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
}

.section-head h2::before {
  width: 8px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.form-section:nth-of-type(2) .section-head h2::before {
  background: var(--blue);
}

.form-section:nth-of-type(3) .section-head h2::before {
  background: var(--warning);
}

.form-section:nth-of-type(4) .section-head h2::before {
  background: var(--violet);
}

.section-head p {
  max-width: 100%;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 24px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0, #fbfcfa 100%);
}

.new-run-layout,
.export-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 380px);
  gap: 20px;
  align-items: stretch;
}

.new-run-layout > .panel,
.export-layout > .panel {
  min-width: 0;
}

.guide-panel {
  align-self: start;
  border-color: #d4dfd2;
  background:
    linear-gradient(180deg, rgba(231, 242, 235, 0.72) 0, #ffffff 34%, var(--panel-warm) 100%);
  box-shadow: var(--shadow-raised);
}

.guide-panel h2:not(:first-child) {
  margin-top: 20px;
}

.guide-list {
  counter-reset: guide-step;
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  list-style: none;
}

.guide-list li {
  counter-increment: guide-step;
  position: relative;
  min-height: 28px;
  padding-left: 38px;
}

.guide-list li::before {
  position: absolute;
  left: 0;
  top: -2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid #cfe0d3;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  content: counter(guide-step);
}

.guide-defs {
  display: grid;
  gap: 10px;
  margin: 0;
}

.guide-defs dt {
  display: inline-flex;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.guide-defs dd {
  margin: -6px 0 4px;
  color: var(--muted);
}

label span {
  color: var(--muted);
  font-weight: 650;
}

small {
  display: block;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

input,
select {
  min-width: 0;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 78, 0.14);
  outline: none;
}

.has-error input,
.has-error select,
input[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff8f7;
}

.has-error input:focus,
.has-error select:focus,
input[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(179, 59, 51, 0.14);
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

input::placeholder {
  color: #8c9489;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 18%, rgba(47, 111, 78, 0.12), transparent 28%),
    linear-gradient(135deg, #f9fbf7 0, #edf4ef 48%, #e7f0ec 100%);
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 42px;
  align-items: center;
  width: min(1080px, calc(100vw - 40px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 48px 0;
}

.login-hero {
  max-width: 620px;
}

.login-brand {
  margin-bottom: 44px;
}

.login-hero h1 {
  max-width: 12ch;
  font-size: 52px;
  line-height: 1.02;
}

.login-hero p {
  max-width: 520px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
}

.login-card {
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid #d6e0d6;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0, rgba(251, 253, 250, 0.96) 100%);
  box-shadow: 0 24px 60px rgba(22, 31, 22, 0.14);
}

.login-card h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

.login-card label {
  display: grid;
  gap: 8px;
}

.login-card .notice {
  margin-bottom: 0;
}

.login-submit {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

.check {
  align-content: end;
  column-gap: 8px;
  grid-template-columns: 18px minmax(0, 1fr);
}

.check input {
  width: 18px;
  min-height: 18px;
}

.check span {
  grid-column: 2;
  grid-row: 1;
}

.check small {
  grid-column: 2;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.stat::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent);
  content: "";
}

.stat span {
  display: block;
  color: var(--muted);
  font-weight: 650;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.progress-panel {
  display: grid;
  gap: 14px;
}

.progress-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.progress-head h2 {
  margin-bottom: 4px;
}

.progress-head > strong {
  color: var(--accent-strong);
  font-size: 24px;
  line-height: 1;
}

.progress-track {
  overflow: hidden;
  height: 12px;
  border: 1px solid #cfe0d3;
  border-radius: 999px;
  background: #edf3ee;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0, #4f8d6c 100%);
  transition: width 280ms ease;
}

.progress-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.progress-breakdown span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--muted);
}

.progress-breakdown strong {
  color: var(--accent-strong);
}

.progress-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.progress-steps article {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0, #fbfdfb 100%);
}

.progress-steps article > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.progress-steps article span {
  color: var(--muted);
  font-weight: 650;
}

.progress-steps article strong {
  color: var(--text);
}

.mini-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #edf1ec;
}

.mini-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 280ms ease;
}

.yield-line {
  min-height: 8px;
  color: var(--accent-strong);
  font-weight: 700;
}

.progress-note {
  color: var(--muted);
  font-size: 12px;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.details {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.2fr);
  gap: 8px 14px;
  margin: 0;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.events {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.events li {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.events li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.events span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.events p {
  color: var(--muted);
}

.leads-head {
  align-items: center;
}

.lead-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(170px, 240px)) minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.summary-card {
  display: grid;
  gap: 5px;
  align-content: center;
  min-width: 0;
  padding: 18px;
  border: 1px solid #d4dfd2;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(231, 242, 235, 0.9) 0, rgba(255, 255, 255, 0.94) 60%),
    var(--panel);
  box-shadow: var(--shadow-soft);
}

.summary-card strong {
  font-size: 16px;
}

.summary-card span {
  color: var(--muted);
}

.lead-filters {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0, rgba(251, 253, 250, 0.98) 100%);
}

.leads-panel {
  padding: 0;
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 12px;
}

.table-head h2 {
  margin-bottom: 4px;
}

.lead-filter-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px 24px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(248, 251, 247, 0.98) 0, rgba(255, 255, 255, 0.98) 100%);
}

.filter-search {
  grid-column: span 2;
}

.lead-filter-bar label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.lead-filter-bar label span {
  color: #566052;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.lead-filter-bar input,
.lead-filter-bar select {
  min-height: 36px;
}

.filter-check {
  align-self: center;
  padding-top: 16px;
}

.filter-check span {
  text-transform: none;
}

.lead-filter-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  grid-column: span 2;
}

.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: #fcfdfa;
}

.table-meta strong {
  color: var(--accent-strong);
}

.lead-table-wrap {
  max-height: min(68vh, 780px);
}

.lead-table {
  min-width: 1520px;
  table-layout: fixed;
}

.lead-col-email {
  width: 330px;
}

.lead-col-name {
  width: 280px;
}

.lead-col-location {
  width: 190px;
}

.lead-col-contact {
  width: 180px;
}

.lead-col-source {
  width: 360px;
}

.lead-col-quality {
  width: 150px;
}

.lead-col-created {
  width: 130px;
}

.lead-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-top: 1px solid var(--line);
  background: #f8faf6;
  color: #566052;
}

.lead-table td {
  background: rgba(255, 255, 255, 0.86);
  overflow-wrap: anywhere;
}

.lead-table tbody tr:hover td {
  background: #f8fbf7;
}

.lead-table td > span,
.lead-table td > strong,
.lead-table td > a {
  display: block;
}

.email-link {
  display: block;
  max-width: 100%;
  color: #17231a;
  font-size: 15px;
  font-weight: 760;
  line-height: 1.3;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.email-link:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.table-url {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--accent-strong);
  text-decoration: none;
}

.table-url:hover {
  text-decoration: underline;
}

.quality-stack {
  display: grid;
  gap: 7px;
  justify-items: start;
}

.score-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.table-detail {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.pagination span {
  color: var(--muted);
}

.button.disabled {
  pointer-events: none;
  opacity: 0.48;
}

@media (max-width: 860px) {
  .topbar,
  .page-head,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
  }

  .topbar {
    gap: 8px;
    min-height: auto;
    padding: 12px 16px;
  }

  .form-grid,
  .stats-grid,
  .split,
  .lead-summary,
  .new-run-layout,
  .export-layout {
    grid-template-columns: 1fr;
  }

  .form-section {
    grid-template-columns: 1fr;
    gap: 14px;
    width: 100%;
    max-width: 100%;
    padding: 18px 28px 18px 18px;
  }

  .form-section .form-grid {
    width: calc(100% - 10px);
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column-reverse;
    padding: 16px 18px;
  }

  .guide-panel {
    position: static;
  }

  .shell {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    margin-top: 18px;
    overflow-x: hidden;
  }

  .panel {
    padding: 18px;
  }

  .progress-head {
    flex-direction: column;
  }

  .progress-steps {
    grid-template-columns: 1fr;
  }

  .table-head,
  .leads-head {
    flex-direction: column;
  }

  .lead-filter-bar {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .lead-filter-actions,
  .pagination,
  .table-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .lead-filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .run-form.panel {
    padding: 0;
  }

  .new-run-layout,
  .export-layout,
  .run-form,
  .form-section,
  .form-grid,
  .form-grid label,
  input,
  select {
    max-width: 100%;
  }

  .section-head p {
    max-width: 30ch;
  }

  .form-section {
    background: var(--surface-green);
  }

  .form-section:nth-of-type(2) {
    background: var(--surface-blue);
  }

  .form-section:nth-of-type(3) {
    background: var(--surface-amber);
  }

  .form-section:nth-of-type(4) {
    background: var(--surface-violet);
  }

  .login-shell {
    grid-template-columns: 1fr;
    gap: 22px;
    align-content: center;
    width: calc(100vw - 32px);
    padding: 28px 0;
  }

  .login-brand {
    margin-bottom: 28px;
  }

  .login-hero h1 {
    font-size: 38px;
  }

  .login-card {
    padding: 22px;
  }
}
