:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --border:    #dfe3e8;
  --text:      #16191d;
  --muted:     #6b7280;
  --accent:    #2563eb;
  --accent-bg: #e8efff;
  --good:      #15803d;
  --bad:       #b91c1c;
  --dead:      #6b7280;
  --shadow:    0 1px 2px rgba(16,19,29,.06), 0 4px 12px rgba(16,19,29,.05);
  --radius:    10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1115;
    --surface:   #171a20;
    --surface-2: #1e222a;
    --border:    #2a2f39;
    --text:      #e7e9ee;
    --muted:     #9aa2b1;
    --accent:    #6f9bff;
    --accent-bg: #1c2740;
    --good:      #4ade80;
    --bad:       #f87171;
    --dead:      #9aa2b1;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px 64px; }
/* the mailing list is a table and wants the extra room */
.wrap.wide { max-width: 1320px; }

header.top {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
header.top .wrap {
  padding-top: 14px; padding-bottom: 14px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { flex: 0 0 auto; font-weight: 650; letter-spacing: -.01em; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.spacer { flex: 1 1 auto; }

.who { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.who input { width: 92px; flex: 0 0 auto; }

input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=tel], select, textarea {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

/* one pill holding the field picker and the query, so the two can never
   drift out of alignment with each other */
.searchrow {
  display: flex; align-items: center; height: 54px; margin: 28px 0 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.searchrow:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

select.fieldsel {
  appearance: none; -webkit-appearance: none;
  flex: 0 0 auto; width: auto; height: 100%; margin: 0;
  padding: 0 32px 0 16px;
  border: 0; border-radius: 14px 0 0 14px; background-color: transparent; box-shadow: none;
  font-size: 14px; color: var(--muted); cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%238b93a1' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
select.fieldsel:focus, select.fieldsel:focus-visible { border: 0; box-shadow: none; outline: none; }

.searchrow .divider { flex: 0 0 1px; height: 24px; background: var(--border); }
.searchrow .icon {
  flex: 0 0 auto; display: flex; align-items: center;
  padding: 0 8px 0 12px; color: var(--muted); font-size: 15px; line-height: 1;
}
.searchrow input {
  flex: 1 1 auto; min-width: 0;          /* without this the input overflows the page */
  height: 100%; padding: 0 16px 0 0;
  border: 0; border-radius: 0 14px 14px 0; background: transparent; box-shadow: none;
  font-size: 16px;
}
.searchrow input:focus { border: 0; box-shadow: none; outline: none; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.results { display: flex; flex-direction: column; gap: 8px; }
.result {
  display: block; padding: 13px 15px; color: inherit;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); transition: border-color .12s, transform .12s;
}
.result:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.result .line1 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.result .addr { font-weight: 600; letter-spacing: -.01em; }
.result .name { color: var(--muted); }
.result .line2 { color: var(--muted); font-size: 13px; margin-top: 3px; }
.result .chips { margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 11.5px; padding: 2.5px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.chip.tel { background: var(--accent-bg); border-color: transparent; color: var(--accent); font-variant-numeric: tabular-nums; }
.chip.on  { background: var(--accent-bg); border-color: transparent; color: var(--accent); }

.empty { color: var(--muted); padding: 40px 4px; text-align: center; }
.err {
  background: #fff4f4; border: 1px solid #f3c2c2; color: #96201f;
  padding: 12px 14px; border-radius: var(--radius); margin: 16px 0; font-size: 14px;
}
@media (prefers-color-scheme: dark) { .err { background: #2a1618; border-color: #5a2a2c; color: #ffb4b4; } }
.err code { background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 4px; }

h1.addr { font-size: 26px; letter-spacing: -.02em; margin: 26px 0 2px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(228px, 1fr)); gap: 14px; }
.panel { padding: 16px 18px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
dl.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.section { margin-top: 26px; }
.section > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

.phones { overflow: hidden; }
.phone-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.phone-row:first-child { border-top: 0; }
.phone-row .num { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 132px; letter-spacing: .01em; }
.phone-row .num.struck { text-decoration: line-through; opacity: .5; }
.phone-row .label { color: var(--muted); font-size: 13px; min-width: 62px; }
.phone-row .note { flex: 1 1 140px; min-width: 120px; }
.phone-row .note input { border-color: transparent; background: transparent; padding: 5px 7px; }
.phone-row .note input:hover { border-color: var(--border); }
.phone-row .meta { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.phone-row.busy { opacity: .55; pointer-events: none; }

.statusgroup { display: flex; gap: 4px; }
.sbtn {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 8px; padding: 4px 9px; cursor: pointer; line-height: 1.2;
  font-size: 15px; transition: transform .1s, border-color .1s;
}
.sbtn:hover { transform: translateY(-1px); border-color: var(--muted); }
.sbtn[aria-pressed="true"] { border-color: currentColor; }
.sbtn[data-s="correct"][aria-pressed="true"] { background: rgba(34,197,94,.14); color: var(--good); }
.sbtn[data-s="wrong"][aria-pressed="true"]   { background: rgba(239,68,68,.14); color: var(--bad); }
.sbtn[data-s="dead"][aria-pressed="true"]    { background: rgba(120,120,120,.18); color: var(--dead); }

.iconbtn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  cursor: pointer; border-radius: 8px; padding: 4px 8px; font-size: 14px;
}
.iconbtn:hover { color: var(--bad); border-color: var(--border); }

.addform { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.addform input.tel { max-width: 190px; }
.addform input.lbl { max-width: 130px; }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 16px; cursor: pointer; font-weight: 550;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.badge.yes { background: rgba(34,197,94,.14); color: var(--good); }
.badge.no  { background: var(--surface-2); color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.bad { background: var(--bad); color: #fff; }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 14px; }
@keyframes sk { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

@media (max-width: 560px) {
  .phone-row .num { min-width: 118px; }
  .phone-row .meta { display: none; }
  .wrap { padding-left: 16px; padding-right: 16px; }
  select.fieldsel { padding: 0 28px 0 12px; font-size: 13px; }
  .searchrow input { font-size: 15px; }
  .searchrow .icon { padding: 0 6px 0 10px; }
  .who { font-size: 12px; }
  .who input { width: 72px; }
}

.phone-row select.typesel,
.addform select.typesel {
  width: auto; min-width: 118px; padding: 5px 7px; font-size: 13px;
  border-color: transparent; background: transparent; color: var(--muted);
}
.phone-row select.typesel:hover, .addform select.typesel { border-color: var(--border); }
.addform select.typesel { background: var(--surface); color: var(--text); }

/* ---- distress filter panel ---- */
.filters { padding: 14px 16px 16px; margin-bottom: 20px; }
.filters-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.filters-head h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0; font-weight: 600;
}
.filters-count { font-size: 13px; color: var(--accent); font-weight: 550; }
.filters-head .btn { padding: 6px 14px; font-size: 13px; }

.chips.toggles { gap: 6px; }
.chip-toggle {
  font: inherit; font-size: 12.5px; line-height: 1.4;
  padding: 4px 11px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s, color .12s;
}
.chip-toggle:hover { border-color: var(--muted); }
.chip-toggle .n { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chip-toggle[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.chip-toggle[aria-pressed="true"] .n { color: rgba(255,255,255,.75); }

/* ---- result summary + pagination ---- */
.summary { color: var(--muted); font-size: 13px; margin: 0 2px 10px; }
.summary b { color: var(--text); font-weight: 600; }

.pager { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; margin: 22px 0 8px; }
.pager button {
  min-width: 36px; padding: 7px 11px; font-size: 13px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button[aria-current="page"] {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.pager button:disabled { opacity: .4; cursor: default; }
.pager .gap { color: var(--muted); padding: 0 2px; }

.chip.stack { background: var(--accent-bg); border-color: transparent; color: var(--accent); font-weight: 600; }

/* ---- settings: removal bar + confirmation ---- */
.removebar {
  display: flex; align-items: center; height: 50px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.removebar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.removebar select.fieldsel { height: 100%; border-radius: 12px 0 0 12px; min-width: 140px; }
.removebar input {
  flex: 1 1 auto; min-width: 0; height: 100%; padding: 0 14px;
  border: 0; background: transparent; box-shadow: none; font-size: 15px;
}
.removebar input:focus { border: 0; box-shadow: none; outline: none; }
.removebar .btn { height: 100%; border-radius: 0 12px 12px 0; padding: 0 20px; white-space: nowrap; }

.btn.danger { background: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }

.modal-back {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 14, .62); padding: 16px;
}
/* display:flex above beats the browser's [hidden] rule, so say it explicitly */
.modal-back[hidden] { display: none; }
.modal { max-width: 460px; width: 100%; padding: 22px 24px; }
.modal h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.01em; }
.modal p { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
/* after `.modal p`, and more specific than it: the count is the whole point
   of the dialog and must not be styled as body text */
.modal p.modal-count {
  font-size: 34px; font-weight: 680; letter-spacing: -.02em;
  color: var(--bad); margin: 12px 0 8px; line-height: 1.1;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.removal-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 15px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.removal-row:first-child { border-top: 0; }
.removal-row .what { font-weight: 600; }
.removal-row .meta { color: var(--muted); font-size: 12.5px; }
.removal-row .grow { flex: 1 1 auto; }

/* ---- left sidebar shell ---- */
.shell { display: flex; align-items: flex-start; gap: 26px; }
.content { flex: 1 1 auto; min-width: 0; }

.sidebar {
  flex: 0 0 216px; position: sticky; top: 78px;
  padding-top: 28px; display: flex; flex-direction: column; gap: 22px;
}
.navtabs { display: flex; flex-direction: column; gap: 2px; }
.navtab {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; border-radius: 9px; color: var(--text);
  font-size: 14.5px; font-weight: 500; text-decoration: none;
}
.navtab .lbl { white-space: nowrap; }
.navtab:hover { background: var(--surface-2); text-decoration: none; }
.navtab.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }

.side-block {
  border-top: 1px solid var(--border); padding-top: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.side-block h2 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0 0 4px; font-weight: 600;
}
.side-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.side-field input { flex: 1 1 auto; min-width: 0; padding: 6px 8px; font-size: 13px; }
.side-clear { align-self: flex-start; padding: 5px 12px; font-size: 12.5px; }
.sidebar .hint { margin: 2px 0 0; font-size: 12px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; gap: 0; }
  .sidebar { position: static; flex: 1 1 auto; width: 100%; padding-top: 18px; }
  .navtabs { flex-direction: row; }
  .navtab { flex: 1 1 auto; justify-content: center; }
}

/* ---- retractable sidebar ---- */
.sidebar { transition: flex-basis .16s ease; }
.sidetoggle {
  align-self: flex-end; margin-bottom: 2px;
  width: 26px; height: 26px; line-height: 1; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 7px; font-size: 13px;
}
.sidetoggle:hover { color: var(--accent); border-color: var(--accent); }
.navtab .ico { font-size: 15px; width: 18px; text-align: center; flex: 0 0 auto; }

body.sidebar-collapsed .sidebar { flex-basis: 52px; }
body.sidebar-collapsed .navtab .lbl { display: none; }
body.sidebar-collapsed .navtab { justify-content: center; padding: 9px 0; }
body.sidebar-collapsed .sidetoggle { align-self: center; }

@media (max-width: 860px) {
  body.sidebar-collapsed .sidebar { flex-basis: auto; }
  body.sidebar-collapsed .navtab .lbl { display: inline; }
}

/* ---- mailing filters ---- */
.filter-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.ffield {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; flex: 0 0 auto;
}
.ffield.grow { flex: 1 1 220px; }
.ffield select, .ffield input {
  width: auto; min-width: 150px; font-size: 14px; text-transform: none;
  letter-spacing: 0; color: var(--text); font-weight: 400;
}
.ffield.grow input { width: 100%; min-width: 0; }

/* Fixed columns rather than a flex scramble: the address is the column that
   matters, so it gets the room and the free text beside it ellipsises. */
.mail-row {
  display: grid; align-items: center; gap: 12px;
  /* the minimums must fit the narrowest container this row appears in,
     or the grid spills past the card it sits in */
  grid-template-columns:
    minmax(130px, 1.5fr)   /* property address */
    minmax(95px,  1.1fr)   /* owner */
    minmax(90px,  1fr)     /* city, state zip */
    minmax(170px, auto)    /* vendor + distress chips, together */
    minmax(105px, 1.1fr)   /* check */
    96px;                  /* date */
  padding: 11px 15px; border-top: 1px solid var(--border);
}
.mail-row:first-child { border-top: 0; }
.mail-row > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row .addr { font-weight: 600; letter-spacing: -.01em; }
.mail-row .who { color: var(--muted); }
.mail-row .meta { color: var(--muted); font-size: 12.5px; }
.mail-row .when { font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; }
.mail-row .when.none { color: var(--muted); font-style: italic; }
/* the cold calling list ends in a phone number, which needs more room than
   the mailing list's date */
.mail-row.calls { grid-template-columns:
    minmax(150px, 1.4fr) minmax(110px, 1fr) minmax(110px, 1fr)
    minmax(110px, auto) minmax(110px, 1fr) 128px; }
.mail-row.calls .when { font-weight: 600; }

.mail-row .tags { display: flex; gap: 6px; align-items: center; }
.mail-row .tags .chip { flex: 0 0 auto; }

@media (max-width: 1000px) {
  .mail-row { grid-template-columns: 1fr auto; row-gap: 4px; }
  .mail-row > * { white-space: normal; overflow: visible; }
  .mail-row .meta, .mail-row .who, .mail-row .tags { grid-column: 1 / -1; }
  .mail-row .tags { flex-wrap: wrap; }
  .mail-row .when { text-align: left; }
}

.chip.vendor { background: rgba(111,155,255,.16); border-color: transparent; color: var(--accent); }

.phone-row .grow { flex: 1 1 auto; }

/* a cold-call chip carries its source the way a distress chip carries its count */
.chip.tel .n { color: var(--muted); font-size: 10.5px; font-weight: 600; }
a.chip.tel { text-decoration: none; }
a.chip.tel:hover { filter: brightness(1.15); text-decoration: none; }
