/* ─────────────────────────────────────────────────────────────────────
   novifex-leadgen — internal lead console

   Token structure deliberately mirrors WorkOrdinate (ink/surface ramps,
   one radius, semantic status colors) so moving between the two apps
   doesn't mean relearning anything. The accent does NOT: WorkOrdinate is
   forest green on warm cream, this is burnt amber on pure white. When
   both are open in adjacent tabs they must be distinguishable at a
   glance, and a shared accent would defeat that.

   Surface is pure white on purpose. The warmth lives in the primary and
   nowhere else; tinting both primary and background is the tell.
   ───────────────────────────────────────────────────────────────────── */

:root {
  --bg:            oklch(1 0 0);
  --surface:       oklch(0.978 0.003 50);
  --surface-2:     oklch(0.958 0.005 50);
  --surface-3:     oklch(0.935 0.006 50);
  --border:        oklch(0.902 0.006 50);
  --border-strong: oklch(0.820 0.008 50);

  --ink:           oklch(0.22 0.012 50);
  --ink-2:         oklch(0.40 0.010 50);
  --muted:         oklch(0.52 0.010 50);

  --primary:       oklch(0.40 0.103 50);
  --primary-hover: oklch(0.33 0.100 50);
  --primary-soft:  oklch(0.955 0.024 50);
  --primary-edge:  oklch(0.86 0.045 50);

  /* Status vocabulary. 'contacted' reuses primary rather than adding an
     amber, which would sit ~20deg from it and read as a near-miss. */
  --info:          oklch(0.48 0.108 245);
  --info-soft:     oklch(0.955 0.022 245);
  --success:       oklch(0.46 0.105 150);
  --success-soft:  oklch(0.950 0.028 150);
  --danger:        oklch(0.50 0.150 27);
  --danger-soft:   oklch(0.958 0.028 27);

  --r:    8px;
  --r-sm: 5px;
  --topbar-h: 56px;

  --shadow-panel: 0 1px 2px oklch(0.22 0.012 50 / 0.05),
                  0 8px 24px oklch(0.22 0.012 50 / 0.07);

  /* dropdown → sticky → backdrop → modal → toast */
  --z-sticky: 10;
  --z-backdrop: 20;
  --z-modal: 30;
  --z-toast: 40;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only a UA rule (display: none), so ANY author
   rule setting display beats it — `.auth-fields { display: grid }` was
   enough to leave the reset form's password fields on screen before the
   token had been checked. Every progressive-disclosure step in the auth
   pages is driven by `hidden`, so this has to win everywhere. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

button, input, select, textarea { font: inherit; color: inherit; }

:where(a) { color: var(--info); text-underline-offset: 2px; }

/* Visible focus everywhere, not just where it was remembered. */
:where(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Topbar ────────────────────────────────────────────────────────── */

.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
}
.brand-mark {
  width: 9px; height: 9px;
  border-radius: 2px;
  background: var(--primary);
  transform: rotate(45deg);
}
.brand-sub {
  color: var(--muted);
  font-weight: 400;
}

.topbar-stats {
  display: flex;
  gap: 18px;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}
.topbar-stats b {
  color: var(--ink);
  font-weight: 600;
}
@media (max-width: 820px) {
  .topbar-stats { display: none; }
}

/* Sits after .topbar-stats, which carries margin-left:auto — so both are
   pushed right together and the account block stays last. */
.account {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.whoami {
  font-size: 13px;
  color: var(--muted);
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* The address is a convenience, not a control. On a narrow viewport the
   Sign out button is what has to survive. */
@media (max-width: 620px) {
  .whoami { display: none; }
}

/* ── Buttons ───────────────────────────────────────────────────────── */

.btn {
  --btn-bg: var(--bg);
  --btn-ink: var(--ink);
  --btn-border: var(--border-strong);
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--ease),
              border-color 160ms var(--ease),
              opacity 160ms var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* White text on the amber fill, not dark: at this saturation dark text
   reads muddy regardless of what the contrast number says. */
.btn-primary {
  --btn-bg: var(--primary);
  --btn-ink: oklch(1 0 0);
  --btn-border: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-hover); }

.btn-danger { --btn-ink: var(--danger); --btn-border: var(--border-strong); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 5px 9px; font-size: 12px; }

.btn[data-loading="true"] { position: relative; color: transparent; pointer-events: none; }
.btn[data-loading="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--btn-ink);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Shell ─────────────────────────────────────────────────────────── */

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  min-height: 0;
}
@media (max-width: 1100px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
}

.list-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
}

/* ── Filters ───────────────────────────────────────────────────────── */

.filters {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search {
  flex: 1 1 200px;
  min-width: 150px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  transition: border-color 160ms var(--ease);
}
.search::placeholder { color: var(--muted); }
.search:hover { border-color: var(--ink-2); }

select.filter {
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  cursor: pointer;
  max-width: 190px;
}

.seg {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.seg button {
  appearance: none;
  border: 0;
  background: var(--bg);
  padding: 7px 11px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-2);
  border-right: 1px solid var(--border);
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button[aria-pressed="true"] {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* ── Table ─────────────────────────────────────────────────────────── */

.table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

table.leads {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.leads thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 9px 12px;
  white-space: nowrap;
}

.leads tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 120ms var(--ease);
}
.leads tbody tr:hover { background: var(--surface-2); }
.leads tbody tr[aria-selected="true"] { background: var(--primary-soft); }
.leads tbody tr:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.leads td {
  padding: 9px 12px;
  vertical-align: middle;
}

.cell-name {
  font-weight: 500;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-sub {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.channels { display: flex; gap: 5px; }
.chan {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--surface-3);
  color: var(--muted);
}
.chan[data-on="true"] { background: var(--info-soft); color: var(--info); }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge[data-status="new"]       { background: var(--surface-2); color: var(--ink-2); border-color: var(--border-strong); }
.badge[data-status="contacted"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-edge); }
.badge[data-status="replied"]   { background: var(--info-soft); color: var(--info); }
.badge[data-status="won"]       { background: var(--success-soft); color: var(--success); }
.badge[data-status="dead"]      { background: var(--surface-2); color: var(--muted); }

.activity { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ── Skeletons: content-shaped, not a spinner in the middle ───────── */

.skel {
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Pagination ────────────────────────────────────────────────────── */

.pager {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pager .spacer { margin-left: auto; }

/* ── Detail pane ───────────────────────────────────────────────────── */

.detail-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
}

@media (max-width: 1100px) {
  .detail-pane {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 220ms var(--ease);
  }
  .detail-pane[data-open="true"] { transform: none; }
  .detail-close { display: inline-flex !important; }
}
.detail-close { display: none; }

.detail-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.detail-head h2 { font-size: 17px; line-height: 1.3; }

.detail-meta {
  margin: 8px 0 0;
  display: grid;
  gap: 3px;
  font-size: 13px;
  color: var(--ink-2);
}
.detail-meta a { color: var(--info); }

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 13px;
}

.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 11px;
}
.section-head h3 { font-size: 13px; color: var(--muted); font-weight: 600; }
.section-head .spacer { margin-left: auto; }

.msg {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 10px;
}
.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.msg-head .spacer { margin-left: auto; }
.msg-step { font-weight: 600; color: var(--ink-2); }

.msg input.subject,
.msg textarea {
  width: 100%;
  border: 0;
  padding: 9px 11px;
  background: transparent;
  resize: vertical;
  display: block;
}
.msg input.subject {
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.msg textarea { min-height: 108px; line-height: 1.55; }
.msg input.subject:focus, .msg textarea:focus { outline: none; background: var(--primary-soft); }
.msg[data-sent="true"] input, .msg[data-sent="true"] textarea { color: var(--muted); }

.call {
  display: grid;
  gap: 3px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.call:last-child { border-bottom: 0; }
.call-top { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.call-when { margin-left: auto; color: var(--muted); font-size: 12px; }
.call-notes { color: var(--ink-2); font-size: 13px; white-space: pre-wrap; }

.call-form { display: grid; gap: 8px; }
.call-form select, .call-form textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
}
.call-form textarea { min-height: 60px; resize: vertical; }

/* ── Empty states teach, they don't just say "nothing here" ───────── */

.empty {
  margin: auto;
  padding: 40px 28px;
  max-width: 40ch;
  text-align: center;
  color: var(--muted);
}
.empty h3 { color: var(--ink); font-size: 15px; margin-bottom: 6px; }
.empty p { margin: 0 0 14px; }

.placeholder {
  margin: auto;
  padding: 40px 28px;
  max-width: 34ch;
  text-align: center;
  color: var(--muted);
}

/* ── Discovery dialog ──────────────────────────────────────────────── */

dialog.sheet {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  box-shadow: var(--shadow-panel);
  color: var(--ink);
  background: var(--bg);
}
dialog.sheet::backdrop { background: oklch(0.22 0.012 50 / 0.35); }
.sheet-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.sheet-body { padding: 16px; display: grid; gap: 12px; }
.sheet-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: var(--surface);
}
.field { display: grid; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; }
.field .optional {
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
}
.field select:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
.field .hint { font-size: 12px; color: var(--muted); }
.field select, .field input {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
}

.job-status {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 13px;
}
.job-status[data-state="error"] { background: var(--danger-soft); color: var(--danger); }
.job-status[data-state="done"] { background: var(--success-soft); color: var(--success); }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s var(--ease) infinite;
  flex: none;
}
@keyframes pulse { 50% { opacity: 0.25; } }

/* ── Toasts ────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: grid;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
}
.toast {
  padding: 10px 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--ink);
  color: oklch(0.98 0 0);
  font-size: 13px;
  box-shadow: var(--shadow-panel);
  animation: rise 220ms var(--ease);
}
.toast[data-kind="error"] { background: var(--danger); border-color: var(--danger); }
.toast[data-kind="success"] { background: var(--success); border-color: var(--success); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ── Sign-in ───────────────────────────────────────────────────────── */

/* Deliberately plain. This page exists to be got through, so it borrows
   the console's tokens and adds no ornament of its own. */

.auth-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--surface);
}

.auth-shell { width: 100%; max-width: 380px; }

.auth-card {
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-panel);
}

.auth-brand { justify-content: center; }

.auth-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-align: center;
}

.auth-error {
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.auth-submit { width: 100%; justify-content: center; }

.auth-ok {
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: var(--success-soft);
  color: var(--success);
  font-size: 13px;
}

.auth-status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.auth-lede {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-2);
}

.auth-fields { display: grid; gap: 14px; }

.auth-alt {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}
.auth-alt a { color: var(--primary); }

.auth-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--danger);
}

/* ── Account panel ─────────────────────────────────────────────────── */

.account-section {
  display: grid;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.account-section:last-child { border-bottom: 0; padding-bottom: 0; }
.account-section h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}
.account-section .btn { justify-self: start; }

.team-list { display: grid; gap: 6px; }

.team-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  background: var(--bg);
}
/* An unaccepted invitation is not a member yet — muted so the list reads
   as "who is here" first and "who was asked" second. */
.team-row[data-pending="true"] { background: var(--surface-2); color: var(--muted); }

.team-email {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team-role { color: var(--muted); font-size: 12px; }

.team-state {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.team-state[data-state="active"] { background: var(--success-soft); color: var(--success); }
.team-state[data-state="pending"],
.team-state[data-state="invited"] { background: var(--primary-soft); color: var(--primary); }
.team-state[data-state="disabled"] { background: var(--danger-soft); color: var(--danger); }

/* ── Reduced motion ────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .detail-pane { transition: none; }
  .skel { animation: none; background: var(--surface-2); }
}
