:root {
  --bg: #0c0f0e;
  --panel: #141916;
  --panel-2: #1a211e;
  --line: #2a342f;
  --text: #eef3ef;
  --muted: #8b9a91;
  --accent: #c6f05a;
  --accent-ink: #12200a;
  --warn: #e8a24a;
  --danger: #ef6b6b;
  --ok: #4fd6a0;
  --radius: 16px;
  --font: "Archivo", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(1000px 520px at 8% -8%, #1a2920 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #1f2a16 0%, transparent 48%),
    var(--bg);
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 22px 56px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(42, 52, 47, 0.85);
}

.top-brand { min-width: 0; }

.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.btn-stop-nav {
  border: 1px solid #6b3d3d;
  background: transparent;
  color: var(--danger);
  padding: 8px 14px;
  border-radius: 999px;
  font: 700 0.78rem var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn-stop-nav:hover:not(:disabled) {
  background: rgba(107, 61, 61, 0.25);
  border-color: var(--danger);
}

.btn-stop-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-stop-nav.is-active {
  background: var(--danger);
  color: #1a0a0a;
  border-color: var(--danger);
  opacity: 1;
}

.brand {
  margin: 0;
  font-size: clamp(1.55rem, 3.2vw, 2.15rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.tag {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.status-pill {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  max-width: min(420px, 48vw);
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.status-pill.running {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.status-pill.wait {
  color: #3a2200;
  background: var(--warn);
  border-color: var(--warn);
}

.grid {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  grid-template-areas: "control leads";
  gap: 18px;
  align-items: start;
}

.control { grid-area: control; }

.results-stack {
  grid-area: leads;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.results-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.results-toolbar h2 {
  margin: 0;
  font-size: 1.12rem;
}

.search-tabs-wrap {
  margin-bottom: 12px;
}

.search-tabs-label {
  margin: 0 0 8px;
}

.search-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-tab {
  border: 1px solid var(--line);
  background: #0d1210;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font: 700 0.8rem var(--font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: capitalize;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.search-tab:hover {
  color: var(--text);
  border-color: #3d4d44;
}

.search-tab.active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.search-tab .tab-count {
  font-family: var(--mono);
  font-size: 0.72rem;
  opacity: 0.85;
}

.result-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  padding: 4px;
  border-radius: 12px;
  background: #0d1210;
  border: 1px solid var(--line);
}

.tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.btn-csv {
  white-space: nowrap;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

.btn-csv:hover {
  background: rgba(198, 240, 90, 0.1);
}

.result-tab.pulse {
  animation: tabPulse 0.8s ease;
}

@keyframes tabPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); box-shadow: 0 0 0 2px rgba(198, 240, 90, 0.35); }
}

.toast-host {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #151b18;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0,0,0,0.35);
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-ok { border-color: #3d6b52; color: var(--ok); }
.toast-err { border-color: #6b3d3d; color: var(--danger); }
.toast-info { border-color: #3d4d44; }

.progress-bar {
  position: relative;
  height: 0;
  margin: 0;
  border-radius: 999px;
  border: 1px solid transparent;
  background: #0d1210;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: height 0.2s ease, margin 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
}

.progress-bar.active {
  height: 28px;
  margin: 0 0 16px;
  border-color: var(--line);
  opacity: 1;
  pointer-events: auto;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5a8a3a, var(--accent));
  transition: width 0.35s ease;
}

.progress-bar.indeterminate .progress-bar-fill {
  width: 40% !important;
  animation: progress-pulse 1.4s ease-in-out infinite;
}

@keyframes progress-pulse {
  0% { transform: translateX(-40%); }
  50% { transform: translateX(160%); }
  100% { transform: translateX(-40%); }
}

.progress-bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 12px;
}

.nav-user {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  padding: 0 4px;
}

.nav-btn {
  cursor: pointer;
  font: inherit;
}

.login-app {
  max-width: 420px;
  min-height: 100vh;
  display: flex;
  align-items: center;
}

.login-card {
  width: 100%;
}

.login-card .brand {
  margin-bottom: 4px;
}

#loginError {
  color: var(--danger);
  min-height: 1.2em;
  margin: 10px 0 0;
}

.auth-ok {
  color: var(--accent);
  font: 600 0.88rem var(--font);
  margin: 8px 0 0;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 18px 0 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.auth-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  padding: 10px 12px;
  font: 700 0.85rem var(--font);
  cursor: pointer;
}

.auth-tab:hover {
  color: var(--text);
}

.auth-tab.active {
  color: var(--accent-ink);
  background: var(--accent);
}

.result-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  padding: 9px 14px;
  font: 700 0.82rem var(--font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.result-tab:hover {
  color: var(--text);
  border-color: var(--line);
}

.result-tab.active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.tab-count {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  opacity: 0.85;
  min-width: 1.2em;
}

.result-tab.active .tab-count {
  opacity: 1;
}

.leads { min-height: 0; }

.table-wrap-compact {
  max-height: 320px;
}

.panel {
  background: linear-gradient(180deg, rgba(20, 25, 22, 0.98) 0%, rgba(26, 33, 30, 0.98) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.section-block h2 {
  margin: 0 0 16px;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-eyebrow {
  margin: 0 0 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.9;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.12rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 13px;
}

.field span {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #0d1210;
  color: var(--text);
  border-radius: 11px;
  padding: 11px 13px;
  font: 500 0.95rem var(--font);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
  font-family: var(--font);
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  line-height: 1.4;
}

.hint code {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.72rem;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #5f7a64;
  box-shadow: 0 0 0 3px rgba(198, 240, 90, 0.08);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 20px 0;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 78px;
}

.row-actions .btn.tiny { white-space: nowrap; }

.badge.DISCOVERED { background: rgba(198, 240, 90, 0.12); color: var(--accent); }
.badge.EMAILED { background: rgba(79, 214, 160, 0.15); color: var(--ok); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.actions-ai { margin-bottom: 14px; }

.actions-search {
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
}

.actions-search .btn.primary {
  grid-column: auto;
}

.actions-search-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 6px;
}

.actions-search-stack .btn.primary {
  grid-column: auto;
  width: 100%;
}

.actions-search-stack .btn-enrich {
  width: 100%;
}

.btn-enrich {
  border-color: #ffffff !important;
  color: #c6f05a !important;
  background: transparent;
}

.btn-enrich:hover {
  border-color: #ffffff !important;
  color: #c6f05a !important;
  background: rgba(198, 240, 90, 0.08);
}

.actions-send {
  grid-template-columns: 1fr 1fr;
}

.actions-send .btn.primary {
  grid-column: 1 / -1;
}

.btn {
  border: 1px solid var(--line);
  background: #121816;
  color: var(--text);
  border-radius: 11px;
  padding: 11px 14px;
  font: 700 0.88rem var(--font);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:hover { transform: translateY(-1px); border-color: #3d4d44; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  grid-column: 1 / -1;
}

.btn.primary:hover { filter: brightness(1.04); }

.btn.ghost { color: var(--muted); }

.btn.accent {
  background: var(--warn);
  color: #241500;
  border-color: var(--warn);
}

.btn.danger-outline {
  border-color: rgba(239, 107, 107, 0.55);
  color: var(--danger);
  background: transparent;
}

.btn.tiny {
  padding: 6px 10px;
  font-size: 0.74rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.meta {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.55;
}

#logView {
  margin: 0;
  height: 340px;
  overflow: auto;
  background: #0b0f0d;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font: 400 0.78rem/1.55 var(--mono);
  color: #c5d4cb;
  white-space: pre-wrap;
  word-break: break-word;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d1210;
  max-height: calc(100vh - 220px);
  min-height: 360px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }

th {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  background: rgba(20, 25, 22, 0.95);
  position: sticky;
  top: 0;
  z-index: 1;
}

td a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

td a:hover { text-decoration: underline; }

td a.web-social {
  color: #8ab4f8;
  text-transform: lowercase;
}

td a.web-site {
  color: var(--accent);
}

.empty-row {
  text-align: center;
  padding: 36px 12px !important;
}

.muted { color: var(--muted); }
.small { font-size: 0.82rem; font-weight: 500; }

.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #24302a;
  color: #cfe0d5;
}

.badge.INTERESTED,
.badge.EXPORTED { background: rgba(79, 214, 160, 0.15); color: var(--ok); }
.badge.MESSAGED { background: rgba(198, 240, 90, 0.12); color: var(--accent); }
.badge.NOT_INTERESTED { background: rgba(239, 107, 107, 0.12); color: var(--danger); }

.has-email { color: var(--ok); font-weight: 600; }
.no-email { color: var(--muted); }

@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "control"
      "leads";
  }
  .leads { min-height: 0; }
  .table-wrap { max-height: none; }
  .results-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .top {
    flex-direction: column;
    align-items: flex-start;
  }
  .top-right {
    width: 100%;
    justify-content: space-between;
  }
}

/* Settings page */
.top-nav { display: flex; align-items: center; gap: 8px; }
.nav-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  transition: border-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover { border-color: var(--accent); color: var(--accent); }

.settings-page { max-width: 960px; }
.settings-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}
.settings-actions { grid-template-columns: 1fr 1fr 1fr; }
.intro { color: var(--muted); line-height: 1.5; margin: 0 0 16px; }
.status-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f1412;
  margin-bottom: 16px;
}
.status-card.ok { border-color: #3d6b52; }
.status-card.err { border-color: #6b3d3d; }
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  background: var(--muted);
  flex-shrink: 0;
}
.status-dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status-dot.off { background: var(--warn); }
.log-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b0f0d;
  font-family: var(--mono);
  font-size: 0.8rem;
  min-height: 44px;
  white-space: pre-wrap;
}
.log-box.ok { border-color: #3d6b52; color: var(--ok); }
.log-box.err { border-color: #6b3d3d; color: var(--danger); }
.steps { margin: 0; padding-left: 20px; line-height: 1.7; color: var(--muted); }
.steps a { color: var(--accent); }
.compare { width: 100%; font-size: 0.85rem; }
.compare td, .compare th { padding: 8px; }

@media (max-width: 800px) {
  .settings-grid { grid-template-columns: 1fr; }
  .settings-actions { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
  .row-2 { grid-template-columns: 1fr; }
}

/* AI Send modal — screen-center overlay */
#aiSendModal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 9999 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 16px;
  margin: 0;
}
#aiSendModal.hidden,
#aiSendModal[aria-hidden="true"] {
  display: none !important;
}
#aiSendModal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}
#aiSendModal .modal-card {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
#aiSendModal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
#aiSendModal .modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
#aiSendModal .modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
#aiSendSubject { margin-bottom: 8px; }
body.modal-open { overflow: hidden; }
