:root {
  --bg: #ffffff;
  --panel: #f7f8fa;
  --line: #e0e4ea;
  --line-strong: #c7cdd6;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #1a56db;
  --accent-weak: #e8effc;
  --ok: #0f7b3f;
  --warn: #92400e;
  --warn-bg: #fef6e7;
  --err: #b42318;
  --err-bg: #fdeceb;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* beats .inline etc. on hidden elements */

html { font-size: 15px; }

body {
  margin: 0;
  padding: 0 1rem 12rem;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

h1 { font-size: 1.05rem; font-weight: 600; margin: 0; letter-spacing: .01em; }
h2 { font-size: 1rem; margin: 0 0 .5rem; }
code, .mono { font-family: var(--mono); font-size: .85em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 3.2rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}
.stick {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.account { font-family: var(--mono); font-size: .8rem; color: var(--muted); }

/* ---------- controls ---------- */
.btn {
  font: inherit;
  font-size: .85rem;
  padding: .32rem .7rem;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--panel); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1547b8; }
.btn.danger { color: var(--err); border-color: #e8b4b0; }
.btn.danger:hover:not(:disabled) { background: var(--err-bg); }
/* A confirm dialog's main button that does something destructive: solid red,
 * white text — not the red-on-blue that stacking .primary and .danger gives. */
.btn.primary.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.primary.danger:hover:not(:disabled) { background: #9a1c12; border-color: #9a1c12; }
.btn.small { font-size: .78rem; padding: .18rem .5rem; }

select, input[type="text"], input[type="search"] {
  font: inherit;
  font-size: .85rem;
  padding: .28rem .4rem;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
}

label { font-size: .85rem; }
.inline { display: inline-flex; align-items: center; gap: .35rem; }
.muted { color: var(--muted); font-size: .8rem; }
.spacer { flex: 1; }
.pill {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 .35em;
  border-radius: 999px;
  background: var(--line);
  font-size: .72rem;
  text-align: center;
  color: var(--text);
}

.banner {
  margin: .6rem 0 0;
  padding: .5rem .7rem;
  border-radius: 5px;
  font-size: .85rem;
}
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--err-bg); color: var(--err); }

/* ---------- job queue banner ---------- */
.queue {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem 1rem;
  padding: .45rem .7rem;
  background: #0f1115;
  color: #d5dae3;
  font-size: .82rem;
  border-radius: 0 0 6px 6px;
}
.queue-now { display: flex; align-items: center; gap: .5rem; min-width: 0; flex-wrap: wrap; }
.queue-label { color: #8b93a3; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.queue-elapsed, .queue-detail { color: #8b93a3; font-size: .78rem; }
.queue-detail:empty, .queue-elapsed:empty { display: none; }
.queue-spinner {
  width: .7rem;
  height: .7rem;
  border: 2px solid #4b9bff;
  border-right-color: transparent;
  border-radius: 50%;
  animation: queue-spin .8s linear infinite;
  flex: none;
}
@keyframes queue-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .queue-spinner { animation: none; border-right-color: #4b9bff; } }
.queue-list { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; min-width: 0; }
.queue-list:empty { display: none; }
.queue-item {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .05rem .2rem .05rem .5rem;
  border: 1px solid #2a2f38;
  border-radius: 999px;
  background: #181b21;
  max-width: 24rem;
}
.queue-item > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-x, .queue-clear {
  font: inherit;
  font-size: .85rem;
  line-height: 1;
  padding: .05rem .35rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #8b93a3;
  cursor: pointer;
}
.queue-x:hover, .queue-clear:hover { color: #fff; background: #2a2f38; }
.queue-clear { font-size: .75rem; text-decoration: underline; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .25rem; margin: .8rem 0 0; border-bottom: 1px solid var(--line); }
.tab {
  font: inherit;
  font-size: .85rem;
  padding: .4rem .8rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

main { padding-top: .8rem; }

.toolbar, .tablebar, .bulkbar {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .6rem;
}
.tablebar #search { min-width: 16rem; flex: 0 1 22rem; }
.bulkbar {
  padding: .5rem .7rem;
  background: var(--accent-weak);
  border: 1px solid #c9dbfa;
  border-radius: 5px;
  font-size: .85rem;
}

.options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0 0 .8rem;
  padding: .5rem .7rem;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.options legend { font-size: .75rem; color: var(--muted); padding: 0 .3rem; }
#label-read-filter { width: 12rem; }
#label-read-pick { max-width: 18rem; }

/* ---------- progress ---------- */
.progress {
  margin: 0 0 .8rem;
  padding: .5rem .7rem;
  background: #0f1115;
  border-radius: 5px;
  color: #d5dae3;
  font-family: var(--mono);
  font-size: .78rem;
}
.progress-line { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .4rem; }
.bar { height: 6px; background: #262a33; border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: #4b9bff; transition: width .15s linear; }

/* ---------- tables ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  text-align: left;
  font-weight: 500;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: .35rem .5rem;
  white-space: nowrap;
  position: sticky;
  top: var(--stick-h, 3.2rem);   /* the top bar, plus the queue banner when it is showing */
  z-index: 2;
}

/* Too narrow to lay the table out comfortably: scroll it sideways rather than
   letting auto-layout crush the columns into two-line wraps. */
@media (max-width: 900px) {
  .table-wrap { overflow-x: auto; }
  thead th { position: static; }
  table { min-width: 62rem; }
}
tbody td { padding: .3rem .5rem; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
tbody td:nth-child(5), tbody td:last-child { white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
tbody tr.selected { background: var(--accent-weak); }
.num { text-align: right; }
td.num { font-variant-numeric: tabular-nums; }
.col-check { width: 1.8rem; }
.sort {
  font: inherit;
  font-size: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.sort:hover { color: var(--text); }
.sort[data-dir]::after { content: " ▲"; font-size: .7em; }
.sort[data-dir="desc"]::after { content: " ▼"; }

.name-cell { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addr-cell { font-family: var(--mono); font-size: .8rem; color: #33383f; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-input { width: 9rem; }
.label-cell { white-space: nowrap; }
.filter-pick { width: 9rem; margin-right: .25rem; }
#bulk-filter { width: 13rem; }

/* ---------- searchable drop-down ---------- */
.combo { display: inline-block; position: relative; vertical-align: middle; }
.combo-input { width: 100%; padding-right: 1.5rem; text-overflow: ellipsis; }
.combo::after {
  content: "";
  position: absolute;
  right: .6rem;
  top: 50%;
  width: .38rem;
  height: .38rem;
  border: solid var(--muted);
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.combo-list {
  position: fixed;
  z-index: 20;
  padding: .2rem 0;
  max-width: min(28rem, calc(100vw - .5rem));
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
  font-size: .85rem;
  text-align: left;
}
.combo-option {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  padding: .3rem .6rem;
  cursor: pointer;
  white-space: nowrap;
}
.combo-option.active { background: var(--accent-weak); }
.combo-option[aria-selected="true"] .combo-text { font-weight: 500; }
.combo-text { overflow: hidden; text-overflow: ellipsis; }
.combo-hint {
  margin-left: auto;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .75rem;
}
.combo-empty { padding: .3rem .6rem; color: var(--muted); }
.action-cell { white-space: nowrap; }
.query-list { margin: .4rem 0 .6rem; padding-left: 1.2rem; max-height: 12rem; overflow: auto; font-size: .85rem; }
.query-list li { margin: .15rem 0; overflow-wrap: anywhere; }
.action-cell > * { margin-right: .25rem; }
.unsub { text-decoration: none; display: inline-block; }
td.unread-yes { color: var(--accent); font-weight: 500; }
.status-none { color: var(--muted); }
.status-has { color: var(--ok); }
.status-busy { color: var(--accent); }
.status-err { color: var(--err); }
.row-note { font-size: .75rem; color: var(--muted); }

/* ---------- similar filters ---------- */
.suggest {
  margin: 0 0 .8rem;
  padding: .5rem .7rem;
  background: var(--warn-bg);
  border: 1px solid #f1d9a8;
  border-radius: 5px;
  font-size: .85rem;
}
.suggest-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.suggest-list { list-style: none; margin: .4rem 0 0; padding: 0; }
.suggest-list li {
  display: flex;
  gap: .5rem;
  align-items: center;
  padding: .15rem .3rem;
  border-radius: 4px;
}
.suggest-list li:hover { background: #fbecc9; }
.suggest-what { flex: none; color: var(--warn); }
.suggest-list .mono { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-list .btn { flex: none; }
.suggest.undo { background: var(--accent-weak); border-color: #c5d4f5; }
.suggest.undo .suggest-list li:hover { background: #dbe6fa; }
.suggest.undo .suggest-what { color: var(--accent); }
.similar-pill { background: #fbe4b5; color: var(--warn); margin-right: .4rem; vertical-align: 1px; }
tbody tr.similar > td:first-child { box-shadow: inset 3px 0 0 #e6b04e; }
tbody tr.hilite { background: var(--warn-bg); }

.empty { padding: 1.2rem .7rem; color: var(--muted); font-size: .85rem; margin: 0; }
.more { text-align: center; }                 /* no empty strip when the button is hidden */
.more button { margin: .5rem; }

/* ---------- activity log ---------- */
.log {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: #0f1115;
  color: #d5dae3;
  border-top: 1px solid #2a2f38;
  font-family: var(--mono);
  font-size: .76rem;
  z-index: 6;
}
.log summary {
  padding: .4rem .8rem;
  cursor: pointer;
  color: #9aa4b2;
  font-family: system-ui, sans-serif;
  font-size: .8rem;
  list-style: none;
}
.log summary::-webkit-details-marker { display: none; }
.log summary::before { content: "▸ "; }
.log[open] summary::before { content: "▾ "; }
.log .pill { background: #2a2f38; color: #d5dae3; }
.log-body { max-height: 9rem; overflow-y: auto; padding: 0 .8rem .3rem; }
.log-line { display: flex; gap: .6rem; padding: .07rem 0; white-space: pre-wrap; word-break: break-word; }
.log-time { color: #5f6875; flex: none; }
.log-line.err .log-msg { color: #ff8f85; }
.log-line.ok .log-msg { color: #7fd39b; }
.log-actions { padding: .3rem .8rem .5rem; }
.log-actions .btn { background: #1b1f27; color: #d5dae3; border-color: #2a2f38; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 1rem;
  max-width: min(30rem, 92vw);
  font-size: .9rem;
  color: var(--text);
}
dialog::backdrop { background: rgba(15, 17, 21, .4); }
dialog menu { display: flex; gap: .5rem; justify-content: flex-end; margin: 1rem 0 0; padding: 0; }
dialog p { margin: .4rem 0; }
dialog .mono { word-break: break-all; }
dialog .unsub-plan { margin: .4rem 0; padding-left: 1.2rem; }
dialog .unsub-plan li { margin: .25rem 0; }
dialog .merge-list,
dialog .unsub-list {
  list-style: none;
  margin: .5rem 0;
  padding: .3rem .5rem;
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: .82rem;
}
dialog .merge-list li,
dialog .unsub-list li { display: flex; gap: .5rem; align-items: baseline; padding: .12rem 0; }
dialog .merge-list .mono,
dialog .unsub-list .mono { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; word-break: normal; }
dialog .unsub-list a { flex: none; color: var(--accent); }

/* ---------- phone: table becomes cards ---------- */
@media (max-width: 760px) {
  html { font-size: 16px; }
  .topbar { flex-wrap: wrap; }
  table { min-width: 0; }
  thead { position: absolute; left: -9999px; }
  .table-wrap { border: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: .5rem;
    padding: .3rem 0;
  }
  tbody td { border: none; display: flex; gap: .6rem; padding: .18rem .6rem; }
  tbody td::before {
    content: attr(data-label);
    flex: none;
    width: 5.5rem;
    color: var(--muted);
    font-size: .78rem;
  }
  .name-cell, .addr-cell { max-width: none; white-space: normal; }
  tbody td.num { text-align: left; }
  tbody td.col-check { width: auto; }
  .label-input { flex: 1; min-width: 0; }
  .label-cell, .action-cell { white-space: normal; flex-wrap: wrap; }
  .filter-pick, #bulk-filter { width: auto; flex: 1; min-width: 8rem; }
  tbody tr.similar { border-left: 3px solid #e6b04e; }
  tbody tr.similar > td:first-child { box-shadow: none; }
  .suggest-list li { flex-wrap: wrap; }
  .suggest-list .mono { flex-basis: 100%; white-space: normal; }
  .tablebar #search { flex: 1 1 100%; min-width: 0; }
}
