:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #eef1f6;
  --text-dim: #9aa3b2;
  --brand: #7ed321;
  --brand-dim: #5aa617;
  --brand-text: #0f1508;
  --ok: #35c97a;
  --warn: #f0a93b;
  --err: #f26262;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0) + 16px);
  padding-top: max(16px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
}

header.topbar h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.2px;
}

header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

header.topbar .brand img.logo {
  height: 28px;
  width: auto;
  display: block;
}

button.linklike {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 8px;
}

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
label:first-of-type { margin-top: 0; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px; /* prevents iOS auto-zoom */
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
}

.row {
  display: flex;
  gap: 12px;
}
.row > * { flex: 1; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.toggle-row:first-of-type { border-top: none; }
.toggle-row span.label { font-size: 14px; }
.toggle-row span.hint { display: block; font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--brand-dim); border-color: var(--brand); }
.switch input:checked + .track .thumb { transform: translateX(18px); background: white; }

details.advanced {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
details.advanced summary {
  cursor: pointer;
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
}
details.advanced summary::-webkit-details-marker { display: none; }

button.primary {
  width: 100%;
  background: var(--brand);
  color: var(--brand-text);
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  margin-top: 18px;
  box-shadow: 0 4px 14px -4px rgba(126, 211, 33, 0.45);
}
button.primary:active { background: var(--brand-dim); box-shadow: none; }
button.primary:disabled { opacity: 0.5; box-shadow: none; }

button.secondary {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px;
  font-size: 14px;
  margin-top: 10px;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-dim);
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status.error { color: var(--err); }
.status.done { color: var(--ok); }

.result-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.result-summary .count { font-size: 22px; font-weight: 700; }
.result-summary .count small { font-size: 13px; font-weight: 400; color: var(--text-dim); }

.leads {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lead-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.lead-card .title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.lead-card .meta { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.lead-card .meta a { color: var(--brand); text-decoration: none; }
.lead-card .badges { margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.lead-card .badge {
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--text-dim);
}

.history-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
}
.history-item .h-main { min-width: 0; }
.history-item .h-title { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.history-item .h-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.h-badge.working { background: rgba(240, 169, 59, 0.15); color: var(--warn); }
.h-badge.done { background: rgba(53, 201, 122, 0.15); color: var(--ok); }
.h-badge.failed { background: rgba(242, 98, 98, 0.15); color: var(--err); }

.hidden { display: none !important; }

footer.legal {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 20px 16px 32px;
  line-height: 1.6;
}

.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 24px calc(24px + var(--safe-bottom));
  padding-top: calc(24px + var(--safe-top));
}
.login-card {
  width: 100%;
  max-width: 340px;
}
.login-card .logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}
.login-card .logo-wrap img {
  height: 72px;
  width: auto;
}
.login-card h1 {
  font-size: 20px;
  text-align: center;
  margin-bottom: 4px;
}
.login-card p.sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 20px;
}

@media (min-width: 640px) {
  main { padding-top: 24px; }
}

/* Larger screens: give the form room to breathe instead of stretching edge to edge */
@media (min-width: 480px) {
  .leads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (min-width: 860px) {
  .leads { grid-template-columns: 1fr 1fr 1fr; }
}
