/* onbrbr — compact, modern UI. Light/dark via [data-theme] on <html>. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --border: #e2e5ea;
  --border-strong: #d2d7de;
  --text: #18202b;
  --muted: #6a7280;
  --faint: #9aa1ab;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-weak: #eef0ff;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
  --row-h: 38px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1b212b;
  --surface-3: #232a35;
  --border: #2a313c;
  --border-strong: #39414e;
  --text: #e6e9ee;
  --muted: #9aa4b2;
  --faint: #6e7884;
  --accent: #6d6af7;
  --accent-hover: #837fff;
  --accent-weak: #1d2030;
  --accent-fg: #ffffff;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 34px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.nowrap { white-space: nowrap; }

/* --- Top bar ----------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 48px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
  color: var(--text);
}
.brand span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 12px; }

.content { padding: 14px 16px 60px; max-width: 1500px; margin: 0 auto; }

/* --- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s, box-shadow .12s;
  user-select: none;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn-icon { height: 30px; width: 30px; padding: 0; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn[aria-busy="true"], .btn.htmx-request { pointer-events: none; opacity: .7; }
.btn .spin { display: none; }
.btn.htmx-request .spin {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .6s linear infinite;
}
.btn.htmx-request .label { opacity: .6; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Inputs ------------------------------------------------------------ */
input[type=text], input[type=url], input[type=email], input[type=password],
input[type=search], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  height: 30px;
  width: 100%;
}
textarea { height: auto; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }

/* --- Toolbar / tabs ---------------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .search { width: 230px; }
.toolbar select { width: auto; min-width: 130px; }
.toolbar .spacer { flex: 1; }

.tabs { display: flex; gap: 2px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  border: 1px solid transparent; cursor: pointer;
}
.tab:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.tab.active { background: var(--accent-weak); color: var(--accent); border-color: var(--accent); }
.tab .count { font-size: 11px; color: var(--faint); }
.tab.active .count { color: var(--accent); }

/* --- Table ------------------------------------------------------------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; max-height: calc(100vh - 150px); box-shadow: var(--shadow);
}
table.listings { width: 100%; border-collapse: collapse; }
table.listings thead th {
  position: sticky; top: 0;  /* sticks to the top of the scrolling card */
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
  padding: 8px 12px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); z-index: 5;
}
table.listings tbody.listing { border-bottom: 1px solid var(--border); }
table.listings tbody.listing:last-child { border-bottom: none; }
table.listings td { padding: 7px 12px; vertical-align: middle; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--surface-2); }
tbody.listing.open tr.row td { background: var(--surface-2); }

.expander { color: var(--faint); transition: transform .15s; display: inline-block; width: 14px; }
tbody.listing.open .expander { transform: rotate(90deg); color: var(--muted); }

.addr { font-weight: 600; }
.addr-sub { color: var(--faint); font-size: 11.5px; }
.gone-flag { color: var(--danger); font-weight: 600; font-size: 11px; }

.contact-name { font-weight: 500; }
.contact-line { color: var(--muted); font-size: 12px; }
.contact-more { color: var(--accent); font-size: 11px; }
.notescell { color: var(--muted); }
.notescell .snip { color: var(--faint); }

/* --- Status pill (select) --------------------------------------------- */
select.pill {
  appearance: none; -webkit-appearance: none;
  width: auto; height: 24px; padding: 0 22px 0 10px;
  border: none; border-radius: 999px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>");
}
select.pill:focus { box-shadow: 0 0 0 3px var(--accent-weak); }
select.pill[data-status="not-started"]    { background-color: #eceef1; color: #5b636e; }
select.pill[data-status="contacted"]      { background-color: #e3effe; color: #1d6fd6; }
select.pill[data-status="following-up"]   { background-color: #eae6fe; color: #6b46e0; }
select.pill[data-status="in-progress"]    { background-color: #d9f3ee; color: #0f9b82; }
select.pill[data-status="confirmed"]      { background-color: #def3df; color: #2f9e44; }
select.pill[data-status="onboarded"]      { background-color: #c9f0d4; color: #1a8f4a; }
select.pill[data-status="not-interested"] { background-color: #fce0e0; color: #d23a3a; }
[data-theme="dark"] select.pill[data-status="not-started"]    { background-color: #2a313c; color: #aab2bd; }
[data-theme="dark"] select.pill[data-status="contacted"]      { background-color: #16314f; color: #6db1ff; }
[data-theme="dark"] select.pill[data-status="following-up"]   { background-color: #2a2350; color: #b3a2ff; }
[data-theme="dark"] select.pill[data-status="in-progress"]    { background-color: #103a34; color: #4fd6bd; }
[data-theme="dark"] select.pill[data-status="confirmed"]      { background-color: #13361d; color: #69d98a; }
[data-theme="dark"] select.pill[data-status="onboarded"]      { background-color: #0f3d23; color: #54e08a; }
[data-theme="dark"] select.pill[data-status="not-interested"] { background-color: #3d1717; color: #ff8585; }

/* --- Expandable panel -------------------------------------------------- */
tr.panel { display: none; }
tbody.listing.open tr.panel { display: table-row; }
tr.panel > td { padding: 0; background: var(--surface-2); border-top: 1px solid var(--border); }
.panel-body {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 18px; padding: 16px 18px;
}
@media (max-width: 900px) { .panel-body { grid-template-columns: 1fr; } }
.panel h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.panel-col + .panel-col { }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }

/* Activity log */
.note-form { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 12px; }
.note-form textarea { min-height: 34px; }
ol.log { list-style: none; margin: 0; padding: 0; }
ol.log li { padding: 7px 0; border-top: 1px dashed var(--border); }
ol.log li:first-child { border-top: none; }
.log-meta { font-size: 11px; color: var(--faint); margin-bottom: 1px; }
.log-status { font-weight: 500; }
.log-body { white-space: pre-wrap; }

/* Contacts */
.contact-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px dashed var(--border); }
.contact-row:first-child { border-top: none; }
.contact-row .grow { flex: 1; min-width: 0; }
.star { background: none; border: none; cursor: pointer; font-size: 14px; line-height: 1; color: var(--faint); padding: 2px; }
.star.on { color: #f5a623; }
.contact-edit-btn { color: var(--faint); opacity: 0; transition: opacity .12s; }
.contact-row:hover .contact-edit-btn, .contact-edit-btn:focus-visible { opacity: 1; }
.contact-remove-btn:hover { color: var(--danger); }
.contact-meta { font-size: 11.5px; color: var(--muted); }
.add-contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-contact-grid .full { grid-column: 1 / -1; }

/* --- Contact email state (auto-enrich) ------------------------------- */
.contact-email { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 3px; min-height: 18px; }
.contact-email .email-text { font-size: 12px; }
.btn-xs { height: 20px; padding: 0 7px; font-size: 11px; border-radius: var(--radius-sm); }
.email-badge { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
               border-radius: 999px; padding: 1px 7px; }
.email-badge.confirmed { background: #def3df; color: #2f9e44; }
.email-badge.inherited { background: var(--accent-weak); color: var(--accent); }
.email-badge.auto      { background: #fdf0d5; color: #b7791f; }
[data-theme="dark"] .email-badge.confirmed { background: #13361d; color: #69d98a; }
[data-theme="dark"] .email-badge.auto      { background: #3a300f; color: #e6b54f; }
.enrich-badge.searching { font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.enrich-badge.searching .spin { display: inline-block; width: 11px; height: 11px;
  border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; }
.email-warn { background: #fce0e0; color: #d23a3a; border: none; cursor: pointer;
              font-size: 11.5px; font-weight: 500; border-radius: 999px; padding: 2px 9px; }
.email-warn:hover { filter: brightness(0.97); }
[data-theme="dark"] .email-warn { background: #3d1717; color: #ff8585; }

/* --- Find-email candidates ------------------------------------------- */
.email-results { margin-top: 12px; }
.email-note { font-size: 13px; line-height: 1.5; }
.email-queries { margin: 6px 0 0; padding-left: 18px; }
.email-cands { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.email-cand { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--surface-2); }
.email-cand-head { display: flex; align-items: center; gap: 8px; }
.email-addr { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; font-weight: 600; }
.email-cand-head .email-use { margin-left: auto; }
.email-cand-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.email-cand-src { font-size: 12px; margin-top: 3px; }
.email-cand-src a { color: var(--faint); }
.conf { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
        border-radius: 999px; padding: 1px 8px; }
.conf-high     { background: #def3df; color: #2f9e44; }
.conf-medium   { background: #fdf0d5; color: #b7791f; }
.conf-low      { background: #eceef1; color: #5b636e; }
.conf-generic  { background: #fce0e0; color: #d23a3a; }
[data-theme="dark"] .conf-high    { background: #13361d; color: #69d98a; }
[data-theme="dark"] .conf-medium  { background: #3a300f; color: #e6b54f; }
[data-theme="dark"] .conf-low     { background: #2a313c; color: #aab2bd; }
[data-theme="dark"] .conf-generic { background: #3d1717; color: #ff8585; }

/* Rate — quoted supersedes the listed (recalculated) 4-week estimate */
.rate-view { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.rate-amount { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.rate-unit { font-size: 11.5px; color: var(--muted); }
.rate-tag {
  align-self: center; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; padding: 2px 7px; border-radius: 999px;
}
.tag-quoted { background: var(--accent-weak); color: var(--accent); }
.tag-listed { background: var(--surface-3); color: var(--muted); }
.rate-listed { flex-basis: 100%; font-size: 11.5px; color: var(--faint); }
.rate-edit { margin-left: auto; }
.rate-form { display: none; gap: 8px; align-items: center; }
.rate.editing .rate-view { display: none; }
.rate.editing .rate-form { display: flex; }

/* Facts */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* --- Flash feedback on swapped fragments ------------------------------ */
@keyframes flashbg { from { background-color: var(--accent-weak); } to { background-color: transparent; } }
.flash { animation: flashbg .9s ease-out; border-radius: var(--radius-sm); }

/* --- Modal dialog ------------------------------------------------------ */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 0; width: min(480px, 92vw); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(8, 12, 20, .45); backdrop-filter: blur(1px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 14px; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* --- Empty state ------------------------------------------------------- */
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* --- Auth -------------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; }
.auth-card { width: min(360px, 92vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 4px; font-size: 18px; }
.auth-card .sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.error { color: var(--danger); font-size: 12.5px; margin: 0 0 10px; }

/* --- Admin ------------------------------------------------------------- */
table.admin { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.admin th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
table.admin td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
table.admin tr:last-child td { border-bottom: none; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.toast { background: var(--accent-weak); color: var(--accent); padding: 8px 12px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 12px; }
