/* Dark is the default. [data-theme="light"] on <html> swaps the palette;
   every colour below is a token so the two themes stay in step. */
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d2129;
  --panel-3: #242935;
  --line: #272c37;
  --text: #e6e9ef;
  --muted: #8b93a3;

  --accent: #5b9cff;
  --accent-hover: #74acff;
  --accent-dim: #23375d;
  --accent-on: #08101f;

  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;

  --danger-line: #4a2220;
  --danger-bg: #2a1614;

  --dot-off: #454b59;

  --tag-fg: #8fd0ff;
  --tag-bg: #14202e;
  --tag-line: #21384f;

  --kw-fg: #ffc9a3;
  --kw-bg: #2a1d12;
  --kw-line: #4b3320;

  --person-fg: #c8a6ff;
  --person-bg: #221a33;
  --company-fg: #7fd8b0;
  --company-bg: #14291f;

  --note-warn-bg: #241d0c;  --note-warn-line: #4a3a14;  --note-warn-fg: #f0c674;
  --note-bad-bg: #2a1614;   --note-bad-line: #4a2220;   --note-bad-fg: #ff9d95;
  --note-good-bg: #10240f;  --note-good-line: #1f4a1c;  --note-good-fg: #86e08b;
  --note-info-bg: #101b2b;  --note-info-line: #1e3350;  --note-info-fg: #9dc3ff;

  --badge-hit-bg: #14311a;  --badge-hit-fg: #7ee787;
  --badge-sent-bg: #23375d; --badge-sent-fg: #9dc3ff;

  --shadow: none;
  --radius: 8px;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --panel-3: #e4e8ee;
  --line: #dde1e8;
  --text: #1a1e26;
  --muted: #616b7c;

  --accent: #1f6feb;
  --accent-hover: #175bc4;
  --accent-dim: #dbe8ff;
  --accent-on: #ffffff;

  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;

  --danger-line: #f0c2c2;
  --danger-bg: #fdeceb;

  --dot-off: #c2c8d2;

  --tag-fg: #0b5aa8;
  --tag-bg: #e5f0fd;
  --tag-line: #bcd8f7;

  --kw-fg: #9a4f0d;
  --kw-bg: #fdefe2;
  --kw-line: #f2d3b3;

  --person-fg: #6b3fbf;
  --person-bg: #f0e9fd;
  --company-fg: #14764f;
  --company-bg: #e2f5ec;

  --note-warn-bg: #fff8e5;  --note-warn-line: #f0dfae;  --note-warn-fg: #7a5300;
  --note-bad-bg: #fdeceb;   --note-bad-line: #f5c2c0;   --note-bad-fg: #a91b25;
  --note-good-bg: #e8f7ec;  --note-good-line: #b9e2c3;  --note-good-fg: #146c2e;
  --note-info-bg: #e9f2fe;  --note-info-line: #c3ddfb;  --note-info-fg: #0a4fa8;

  --badge-hit-bg: #dcf5e2;  --badge-hit-fg: #10682b;
  --badge-sent-bg: #dbe8ff; --badge-sent-fg: #0a4fa8;

  --shadow: 0 1px 2px rgba(18, 24, 36, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

code, .mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12px;
}

/* ---------- layout ---------- */

header.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 600; letter-spacing: -0.2px; }
.brand span { color: var(--muted); font-weight: 400; }
.brand .ver { margin-left: 6px; font-size: 12px; opacity: .8; }

nav.topnav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
nav.topnav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
}
nav.topnav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
nav.topnav a.on { background: var(--accent-dim); color: var(--text); }

#theme-toggle {
  margin-left: 8px;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
#theme-toggle:hover { background: var(--panel-2); color: var(--text); }

main { max-width: 1220px; margin: 0 auto; padding: 24px; }

h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.3px; }
h2 { font-size: 15px; margin: 28px 0 10px; color: var(--muted); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.6px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head .grow { flex: 1; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 24px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 22px; font-weight: 600; letter-spacing: -0.5px; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat.alert .n { color: var(--bad); }

/* ---------- controls ---------- */

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
/* One height for every toolbar control — inputs, selects and buttons all
   render slightly differently from the same padding. */
.toolbar input[type=text], .toolbar select, .toolbar .btn {
  height: 34px; box-sizing: border-box; padding-top: 0; padding-bottom: 0;
}

input[type=text], input[type=url], input[type=password], input[type=number], textarea, select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font: inherit;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; font-family: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.boost { background: var(--good); border-color: var(--good); color: #fff; font-weight: 600; }
.btn.boost:hover { background: var(--good); border-color: var(--good); filter: brightness(1.12); }

/* hx-confirm modal (replaces window.confirm) */
#confirm-modal { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 20px; max-width: 420px; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
#confirm-modal::backdrop { background: rgba(0,0,0,.45); }
#confirm-modal .confirm-msg { margin: 0 0 16px; font-size: 14px; line-height: 1.5; }
#confirm-modal .confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 0; }
.btn.danger { color: var(--bad); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg a { padding: 6px 11px; color: var(--muted); }
.seg a + a { border-left: 1px solid var(--line); }
.seg a.on { background: var(--accent-dim); color: var(--text); }
.seg a:hover { text-decoration: none; color: var(--text); }

/* ---------- table ---------- */

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--panel); }
tbody tr.off { opacity: 0.55; }

.who { display: flex; align-items: center; gap: 10px; }
.who .name { font-weight: 500; }
.who .url { color: var(--muted); font-size: 12px; }

.chip {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1px 9px;
  font-size: 12px;
  margin: 1px 3px 1px 0;
}
.chip.tag { color: var(--tag-fg); border-color: var(--tag-line); background: var(--tag-bg); }
.chip.kw  { color: var(--kw-fg);  border-color: var(--kw-line);  background: var(--kw-bg); }
/* Auto-boost. Borrows the boosted badge's colours so the flag on a profile and
   the badge on a post it boosted read as the same thing. */
.chip.auto { color: var(--badge-hit-fg); background: var(--badge-hit-bg);
             border-color: transparent; font-weight: 600; }

.pill { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
        padding: 2px 7px; border-radius: 4px; background: var(--panel-2); color: var(--muted); }
.pill.person { color: var(--person-fg); background: var(--person-bg); }
.pill.company { color: var(--company-fg); background: var(--company-bg); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--good); }
.dot.off { background: var(--dot-off); }
.dot.warn { background: #ff9800; }
.dot.cold { background: var(--bad); }

.fails { color: var(--bad); font-weight: 600; }
.stale { color: var(--bad); font-weight: 600; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.note {
  border-radius: 6px;
  padding: 10px 13px;
  margin-bottom: 12px;
  border: 1px solid;
  font-size: 13px;
}
.note.warn { background: var(--note-warn-bg); border-color: var(--note-warn-line); color: var(--note-warn-fg); }
.note.bad  { background: var(--note-bad-bg);  border-color: var(--note-bad-line);  color: var(--note-bad-fg); }
.note.good { background: var(--note-good-bg); border-color: var(--note-good-line); color: var(--note-good-fg); }
.note.info { background: var(--note-info-bg); border-color: var(--note-info-line); color: var(--note-info-fg); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- forms ---------- */

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 5px; font-weight: 500; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.field input[type=text], .field input[type=url],
.field input[type=password], .field select { width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check { display: flex; align-items: center; gap: 8px; }

.avatar { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--panel-2); flex: none; }
.avatar.sm { width: 28px; height: 28px; }

/* ---------- posts ---------- */

.post { border-bottom: 1px solid var(--line); padding: 14px 0; }
.post:last-child { border-bottom: 0; }
.post .meta { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.post .meta .client { font-size: 15px; color: var(--text); }
.post .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.post .body.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.badge { font-size: 11px; padding: 2px 7px; border-radius: 4px; font-weight: 600; letter-spacing: 0.3px; }
.badge.hit { background: var(--badge-hit-bg); color: var(--badge-hit-fg); }
.badge.miss { background: var(--panel-2); color: var(--muted); }
.badge.sent { background: var(--badge-sent-bg); color: var(--badge-sent-fg); }

.htmx-indicator { opacity: 0; transition: opacity 150ms; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spinner { color: var(--muted); font-size: 12px; }

/* ---------- LinkBoost boosts ---------- */
.credits { font-size: 12px; color: var(--muted); white-space: nowrap; }
.credits strong { color: var(--text); }
.credits .out, .credits .out strong { color: var(--bad); }

.boost { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; }
.boost .note, .boost .boost-results:not(:empty) { flex-basis: 100%; margin: 0; }
.boost .boost-results .note { margin: 0; }
.badge.boost { background: var(--badge-hit-bg); color: var(--badge-hit-fg); }
.badge.ignored { background: var(--panel-2); color: var(--muted); }
.chip.hit { background: var(--badge-hit-bg); color: var(--badge-hit-fg); border-color: transparent; font-weight: 600; }

.boost-comments summary { cursor: pointer; color: var(--muted); list-style: none; }
.boost-comments summary::-webkit-details-marker { display: none; }
.boost-comments summary:hover { color: var(--text); }
.boost-comments[open] { flex-basis: 100%; }
.boost-comments form { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 0; max-width: 520px; }
.boost-comments textarea { font: inherit; font-size: 13px; width: 100%; }

/* 7d column: boosted/qualified/total for the last week */
/* Deliberately the table's own font size, not the smaller one it used to
   have: these three numbers are the point of the row, not a footnote. */
.w7 { font-variant-numeric: tabular-nums; color: var(--muted); }
.w7 .b-on { color: var(--good); font-weight: 600; }
.w7 .q-gap { color: var(--note-warn-fg); font-weight: 600; }

/* avatars + company */
.pav { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; background: var(--panel-2); }
.pav.sm { width: 18px; height: 18px; }
.pav-i { display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); }
.pav-i.sq { border-radius: 6px; }
.who { display: flex; align-items: center; gap: 10px; }
.name .co, .post .meta .co { color: var(--muted); font-size: 11px; font-weight: 400; }
.co-opt { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.co-opt img { width: 18px; height: 18px; border-radius: 3px; object-fit: cover; }

.who .url a { color: inherit; text-decoration: none; }
.who .url a:hover { text-decoration: none; color: inherit; }

.btn:disabled { opacity: .5; cursor: default; pointer-events: none; }
.page-head .sub { margin-bottom: 0; }

/* posts page: one card per post, avatar column */
.cards { display: flex; flex-direction: column; gap: 12px; }
.cards .post { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.cards .post, .cards .post:last-child { border-bottom: 1px solid var(--line); }
.prow { display: flex; gap: 12px; align-items: flex-start; }
.pav.lg { width: 40px; height: 40px; font-size: 16px; }
.pbody { flex: 1; min-width: 0; }

.boosts-left { font-size: 12px; font-weight: 600; color: var(--good); border: 1px solid var(--line); border-radius: 12px; padding: 3px 10px; white-space: nowrap; }
.boosts-left:hover { text-decoration: none; background: var(--panel-2); }
.boosts-left.out { color: var(--bad); }

/* --- Boost a link (own page) ------------------------------------------- */
.boost-page form { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.boost-page label { font-size: 12px; color: var(--muted); }
.boost-page label input, .boost-page label textarea { width: 100%; margin-top: 4px; }
.boost-page .actions { display: flex; align-items: center; gap: 10px; }
.boost-link-preview label input { display: block; }
.boost-link-preview .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.boost-link-preview .note { margin: 6px 0 0; }
.bad-text { color: var(--bad); }
.like-limit { width: 86px; font: inherit; font-size: 12px; padding: 3px 6px; }
#boost-link-result:not(:empty) { margin-top: 18px; max-width: 560px; }
#boost-link-result .post.link-result { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
#boost-link-result .meta a { overflow-wrap: anywhere; }
.badge.manual { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- run toasts ---------- */

/* "Check now" on the profiles table swaps a single row, so this is the only
   place a run there can say what it did. Appended by htmx, removed by the
   fade-out; under reduced motion there is no fade, so the × is the way out. */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  position: relative;
  border: 1px solid;
  border-radius: 6px;
  padding: 10px 30px 10px 13px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out, toast-out .5s ease-in 8s forwards;
}
.toast.good { background: var(--note-good-bg); border-color: var(--note-good-line); color: var(--note-good-fg); }
.toast.info { background: var(--note-info-bg); border-color: var(--note-info-line); color: var(--note-info-fg); }
.toast.bad  { background: var(--note-bad-bg);  border-color: var(--note-bad-line);  color: var(--note-bad-fg); }
.toast .t-head { font-weight: 600; }
.toast .t-sub { margin-top: 3px; }
.toast .x {
  position: absolute;
  top: 3px;
  right: 6px;
  padding: 2px 4px;
  background: none;
  border: 0;
  color: inherit;
  opacity: .55;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.toast .x:hover { opacity: 1; }

/* Where the posts came from: replay, cache, or a credit actually spent. */
.toast .t-src,
.note .src { margin-top: 6px; font-size: 12px; opacity: .75; }
.toast .t-src.warn,
.note .src.warn { opacity: 1; font-weight: 500; color: var(--note-warn-fg); }

@keyframes toast-in  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ---------- dashboard ---------- */

.dash-head { display: flex; align-items: center; gap: 14px; margin: 4px 0 14px; }
.dash-head h2 { margin: 0; font-size: 18px; }
.daynav { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sub .failing { color: var(--bad); font-weight: 600; }

table.act tbody td { vertical-align: top; }
table.act .when { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; width: 1%; }
table.act .who-cell { white-space: nowrap; width: 1%; }
table.act .who-link { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 500; }
table.act .who-cell .co { color: var(--muted); font-size: 12px; margin: 2px 0 0 26px; }
table.act .txt .clamp2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere;
}
table.act .txt .meta { display: flex; gap: 10px; margin-top: 4px; font-size: 12px; color: var(--muted); }
table.act .term { white-space: nowrap; }
table.act .status { white-space: nowrap; }
table.act .status .why { margin-top: 4px; font-size: 12px; color: var(--muted); white-space: normal; max-width: 240px; }
table.act .status .why.warn { color: var(--note-warn-fg); }
table.act .status .why.bad { color: var(--bad); }
.badge.alerted { background: var(--badge-sent-bg); color: var(--badge-sent-fg); }
.badge.nomatch { background: var(--panel-2); color: var(--muted); }
.dash .empty { padding: 28px 0; text-align: center; }
.stats.filters a.stat { color: inherit; text-decoration: none; display: block; }
.stats.filters a.stat:hover { border-color: var(--accent); }
.stats.filters a.stat.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stats.filters a.stat.on .k { color: var(--accent); }
