:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e4e7ec;
  --primary: #2f5bea;
  --primary-ink: #ffffff;
  --danger: #c2372b;
  --ok: #18794e;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.5 Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 22px; margin: 0 0 6px; }
a { color: var(--primary); }
code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap; justify-content: center;
}
.btn:hover { border-color: #c9ced8; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }

input, select, textarea {
  font: inherit; color: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d4fb; border-color: var(--primary); }
select[multiple] { height: 110px; padding: 4px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label small { color: var(--muted); font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.inline input { width: 80px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }

/* Top bar */
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--primary); }
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
#nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
#nav a.active { background: #eef2fe; color: var(--primary); }
.user-menu { display: flex; align-items: center; gap: 8px; }
.pill { background: #eef1f6; border-radius: 99px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.banner { background: #fff7e0; border-bottom: 1px solid #f1df9e; padding: 8px 24px; font-size: 13px; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.view { display: none; }
.view.active { display: block; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* Find leads */
.filters {
  margin-top: 16px; padding: 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px;
}
.filters .checks, .filters .actions, #pull-result { grid-column: 1 / -1; }
.checks { display: flex; gap: 24px; flex-wrap: wrap; }
.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 16px; }
.spacer { flex: 1; }
#pull-result { margin: 0; font-weight: 500; }
#pull-result.ok { color: var(--ok); }
#pull-result.err { color: var(--danger); }

/* Leads table */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 340px; }
.toolbar select { width: auto; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 4px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.tab .n { opacity: .6; margin-left: 4px; }

.table-card { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tbody tr:hover { background: #fafbfd; }
td .sub { color: var(--muted); font-size: 13px; }
td select { width: auto; padding: 4px 8px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.due { color: var(--danger); font-weight: 600; }

.status { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f6; }
.s-New { background: #eef2fe; color: #2f5bea; }
.s-Contacted { background: #f0ecfd; color: #6741d9; }
.s-Replied { background: #e6f6fb; color: #0b7593; }
.s-Meeting-Booked { background: #fff4e0; color: #a35b00; }
.s-Qualified { background: #fdf0e8; color: #b54708; }
.s-Won { background: #e5f5ec; color: var(--ok); }
.s-Lost { background: #fbeaea; color: var(--danger); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.kpi { padding: 16px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 13px; }

/* Drawer */
.drawer { position: fixed; inset: 0; background: rgba(15, 20, 30, .35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer-panel { width: min(480px, 100%); background: var(--surface); height: 100%; overflow-y: auto; padding: 24px; position: relative; }
.close { position: absolute; top: 12px; right: 16px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.drawer h2 { margin: 0 0 2px; font-size: 20px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 16px 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.drawer form { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline .when { color: var(--muted); font-size: 12px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(15, 20, 30, .35); }
#dialog-form { display: flex; flex-direction: column; gap: 12px; }
#dialog-form h2 { margin: 0; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50;
}

@media (max-width: 700px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
}

/* Help / user guide */
.guide { max-width: 820px; }
.guide-toc { display: flex; flex-direction: column; gap: 4px; padding: 16px 20px; margin: 16px 0; }
.guide-toc a { text-decoration: none; }
.guide-section { padding: 20px 24px; margin-bottom: 16px; scroll-margin-top: 80px; }
.guide-section h2 { font-size: 18px; margin: 0 0 10px; }
.guide-section h3 { font-size: 15px; margin: 18px 0 6px; }
.guide-section li { margin: 4px 0; }
.guide-section ol, .guide-section ul { padding-left: 22px; }
.callout { background: #eef2fe; border-radius: 8px; padding: 12px 16px; margin-top: 14px; }
.callout ul { margin: 6px 0 0; }
.guide-table td { border-bottom: 1px solid var(--border); padding: 8px 10px; }
.guide-table td:first-child { white-space: nowrap; width: 1%; }
.faq dt { font-weight: 600; margin-top: 12px; }
.faq dd { margin: 2px 0 0; color: #3b4150; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; background: #fff; }

/* Settings */
.settings-card { max-width: 640px; padding: 20px 24px; margin-top: 16px; }
.settings-card h2 { font-size: 17px; margin: 0 0 4px; }
.settings-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.key-status { margin-top: 14px; padding: 12px 14px; border-radius: 8px; background: #f3f4f7; }
.key-status.ok { background: #e5f5ec; }
.key-status.warn { background: #fff7e0; }
.btn.danger { color: var(--danger); }

/* Search page */
.search-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.filter-panel { padding: 16px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; }
.filter-head { display: flex; justify-content: space-between; align-items: center; }
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.filter-group-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.filter { display: flex; flex-direction: column; gap: 4px; }
.filter > label { font-size: 13px; font-weight: 500; flex-direction: row; justify-content: space-between; }
.filter .hint { font-weight: 400; color: var(--muted); font-size: 11px; }
.chips {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: #fff; cursor: text; min-height: 38px;
}
.chips:focus-within { outline: 2px solid #c7d4fb; border-color: var(--primary); }
.chips input { border: 0; outline: 0; padding: 4px 6px; flex: 1; min-width: 90px; width: auto; }
.chips input:focus { outline: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #eef2fe; color: #2343b8; border-radius: 6px; padding: 2px 4px 2px 8px; font-size: 13px; }
.chip button { border: 0; background: none; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; padding: 0 2px; }
input.plain { padding: 8px 10px; }
.btn.block { width: 100%; justify-content: center; margin-top: 6px; }
.small { font-size: 12px; }

.results { min-width: 0; }
.results-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 12px; flex-wrap: wrap; }
.results-bar select { width: auto; padding: 4px 8px; }
.pager { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.search-msg { margin: 0 0 12px; padding: 10px 14px; border-radius: 8px; }
.search-msg.err { background: #fbeaea; color: var(--danger); }
.search-msg.info { background: #eef2fe; color: #2343b8; }

.results-list { overflow: hidden; }
.result-row {
  display: grid; grid-template-columns: 20px 40px minmax(160px, 1.3fr) minmax(140px, 1.2fr) minmax(180px, 1.3fr) 150px;
  gap: 14px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: 0; }
.result-row:hover { background: #fafbfd; }
.result-row input[type=checkbox] { width: 16px; height: 16px; }
.avatar { width: 36px; height: 36px; border-radius: 8px; background: #e8ecf4; color: #4a5568; display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.person .sub, .company .sub { color: var(--muted); font-size: 13px; }
.li { display: inline-block; margin-top: 4px; background: #0a66c2; color: #fff; font-weight: 700; font-size: 10px; border-radius: 3px; padding: 0 4px; text-decoration: none; }
.contact { font-size: 13px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.contact .ci { color: var(--muted); margin-right: 6px; }
.masked { color: #9aa1ad; letter-spacing: .02em; }
.verified { color: var(--ok); margin-left: 4px; font-weight: 700; }
.claimed { color: var(--muted); font-style: italic; }
.row-action { text-align: right; }

@media (max-width: 1000px) {
  .search-layout { grid-template-columns: 1fr; }
  .filter-panel { position: static; max-height: none; }
  .result-row { grid-template-columns: 20px 40px 1fr; }
  .result-row .company, .result-row .contact, .result-row .row-action { grid-column: 3; text-align: left; }
}

/* Search loading state */
.loading-status { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; color: #3b4150; background: #fafbfd; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #c7d4fb; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton .avatar { background: #eef0f4; }
.skeleton .bar { display: block; height: 10px; border-radius: 4px; margin: 5px 0; background: linear-gradient(90deg, #eef0f4 25%, #e2e6ee 50%, #eef0f4 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.bar.w30 { width: 30%; } .bar.w40 { width: 40%; } .bar.w50 { width: 50%; } .bar.w60 { width: 60%; } .bar.w70 { width: 70%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* AI Smart Search */
.smart-search { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; margin-bottom: 12px; border-color: #c9d6fb; background: linear-gradient(90deg, #f5f8ff, #fff); }
.smart-search .sparkle { color: var(--primary); font-size: 16px; }
.smart-label { font-weight: 600; font-size: 13px; white-space: nowrap; flex-direction: row; }
.smart-search input { border: 0; background: transparent; flex: 1; min-width: 0; }
.smart-search input:focus { outline: 0; }
.settings-card + .settings-card { margin-top: 16px; }
@media (max-width: 700px) { .smart-label { display: none; } }

/* Save all matches */
.bulk-banner { padding: 12px 16px; margin-bottom: 12px; font-size: 14px; border-color: #c9d6fb; background: #f5f8ff; }
.bulk-banner.ok { background: #e5f5ec; border-color: #b7e2c8; }
.bulk-banner.err { background: #fbeaea; border-color: #f1c4c0; }
.callout.small { font-size: 13px; margin: 0; }

/* Person name filters */
.name-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.name-row > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.name-row label { font-size: 13px; font-weight: 500; }
.name-hint { margin-top: -4px; }

/* Suggestion dropdown for tag boxes */
.suggest {
  position: fixed; z-index: 100; margin: 0; padding: 4px; list-style: none; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 20, 30, .14); font-size: 13px;
}
.suggest li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.suggest li:hover, .suggest li.active { background: #eef2fe; color: #2343b8; }
.suggest mark { background: none; color: inherit; font-weight: 700; }

/* ---------- UI polish ---------- */
:focus-visible { outline: 2px solid #9db4f7; outline-offset: 2px; }
.chips input:focus-visible, input.plain:focus-visible { outline: none; }

/* One-line emails and phones: cut off with "…", full value on hover. */
.line { display: flex; align-items: center; gap: 4px; min-width: 0; white-space: nowrap; }
.line > a, .line > span:not(.ci):not(.verified) { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.leads-table .c-contact { max-width: 260px; }
.verified { color: var(--ok); font-weight: 600; font-size: 12px; margin-left: 4px; white-space: nowrap; }
.catch-all { color: #a35b00; font-size: 12px; margin-left: 4px; white-space: nowrap; }

/* Status dropdowns tinted by status. */
.status-select { border-radius: 99px; font-weight: 600; font-size: 13px; }
.status-select.s-New { background: #eef2fe; color: #2f5bea; border-color: #d7e1fd; }
.status-select.s-Contacted { background: #f0ecfd; color: #6741d9; border-color: #e0d7fb; }
.status-select.s-Replied { background: #e6f6fb; color: #0b7593; border-color: #c9ebf5; }
.status-select.s-Meeting-Booked { background: #fff4e0; color: #a35b00; border-color: #fbe2b5; }
.status-select.s-Qualified { background: #fdf0e8; color: #b54708; border-color: #f8d9c4; }
.status-select.s-Won { background: #e5f5ec; color: var(--ok); border-color: #c3e8d3; }
.status-select.s-Lost { background: #fbeaea; color: var(--danger); border-color: #f3cfcc; }
.status-select option { background: #fff; color: var(--text); }

.cell-label { display: none; }
.filter-head-actions { display: flex; gap: 12px; }
.phone-only { display: none; }

@media (max-width: 1000px) {
  .phone-only { display: inline; }
  .filter-panel.collapsed > :not(.filter-head) { display: none; }
}

@media (max-width: 900px) {
  /* Compact top bar: logo + account on one row, page links on a swipeable row below. */
  .topbar { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; padding: 10px 12px 6px; }
  .topbar .brand { grid-column: 1; grid-row: 1; }
  .user-menu { grid-column: 2; grid-row: 1; gap: 4px; }
  .user-menu .pill { font-size: 11px; padding: 2px 8px; }
  #nav { grid-column: 1 / -1; grid-row: 2; flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 0 12px 4px; scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
  #nav a { white-space: nowrap; padding: 6px 10px; }
}

/* Tablets: filters in two columns. */
@media (min-width: 701px) and (max-width: 1000px) {
  .filter-panel:not(.collapsed) { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; align-items: start; }
  .filter-panel > .filter-head, .filter-panel > .filter-group-label, .filter-panel > .name-hint,
  .filter-panel > .btn.block, .filter-panel > p { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .banner { padding: 8px 12px; }
  h1 { font-size: 20px; }
  .row-head { flex-wrap: wrap; }

  /* My leads as cards. */
  .leads-table thead { display: none; }
  .leads-table, .leads-table tbody { display: block; }
  .leads-table tr {
    display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    grid-template-areas: "name status" "company company" "contact contact" "owner owner" "follow open";
  }
  .leads-table td { display: block; padding: 0; border: 0; min-width: 0; }
  .leads-table .c-name { grid-area: name; }
  .leads-table .c-status { grid-area: status; }
  .leads-table .c-company { grid-area: company; font-size: 13px; }
  .leads-table .c-contact { grid-area: contact; max-width: none; font-size: 13px; }
  .leads-table .c-owner { grid-area: owner; font-size: 13px; }
  .leads-table .c-follow { grid-area: follow; font-size: 13px; align-self: center; }
  .leads-table .c-open { grid-area: open; }
  .leads-table .c-owner:empty, .leads-table .c-follow:empty { display: none; }
  .cell-label { display: inline; color: var(--muted); margin-right: 6px; font-weight: 400; }
  .toolbar input[type=search] { max-width: none; }

  .results-bar { gap: 8px; }
  .results-bar .spacer { display: none; }
  .result-row { grid-template-columns: 20px 36px 1fr; padding: 12px; gap: 6px 10px; }
  .result-row .row-action .btn { width: 100%; }
  .drawer-panel { padding: 20px 16px; }
  .kv { grid-template-columns: 96px 1fr; }
}
@media (max-width: 700px) {
  .skeleton > :nth-child(n+5) { display: none; }
}
.kpi .v.v-text { font-size: 18px; line-height: 1.3; padding-top: 6px; }

/* Email: sign-in extras and settings */
.link-btn.center { align-self: center; }
.login-title { margin: 0; font-size: 18px; }
.ok-msg { margin: 0; padding: 10px 12px; border-radius: 8px; background: #e5f5ec; color: var(--ok); font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.link-actions { display: flex; gap: 16px; flex-wrap: wrap; }
.log-title { font-size: 14px; margin: 20px 0 6px; }
.email-log { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.email-log table td { padding: 6px 10px; font-size: 12px; vertical-align: top; }
.email-log p { padding: 10px; margin: 0; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
