:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7685;
  --line: #e2e6ec;
  --accent: #2b5dd1;
  --accent-soft: #eaf0fc;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  text-decoration: none;
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
}
.topbar nav a:hover { background: var(--accent-soft); }
.topbar nav a.on { background: var(--accent); color: #fff; }
.privacy-note {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  padding: 4px 10px;
  border-radius: 20px;
}

main { max-width: 1100px; margin: 0 auto; padding: 24px; }
h1 { margin: 0 0 4px; font-size: 22px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin: 16px 0;
}

.cards { display: flex; gap: 16px; margin-top: 16px; }
.stat { flex: 1; text-align: center; }
.stat .num { font-size: 30px; font-weight: 700; color: var(--accent); }
.stat .lbl { color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 .card { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.r, th.r { text-align: right; }
code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: #eef0f3;
  color: #333;
}
.sev-high { background: #fde2e1; color: #a3261d; }
.sev-med  { background: #fff1d6; color: #8a5a00; }
.sev-low  { background: #e3f0e6; color: #2f6b3d; }
.st-open        { background: #fde2e1; color: #a3261d; }
.st-in-progress { background: #fff1d6; color: #8a5a00; }
.st-resolved    { background: #e3f0e6; color: #2f6b3d; }
.cat   { background: #e7ecf6; color: #2b4a86; }
.trig  { background: #ece4fb; color: #5b3aa6; }
.warn  { background: #fde2e1; color: #a3261d; }
.warn-text { color: #a3261d; }
.brand-adj     { background: #e3eefe; color: #1d50b3; }
.brand-elation { background: #e7f3ec; color: #2f6b3d; }
.brand-acclaim { background: #f5e9da; color: #8a5a00; }

.defs.dl, .defs { margin: 0; }
dl.defs { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; }
dl.defs dt { margin: 0; }
dl.defs dd { margin: 0; }

/* explorer */
.tabs { display: flex; gap: 6px; margin: 16px 0; }
.tabs a {
  text-decoration: none; color: var(--ink); padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-weight: 500;
}
.tabs a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.picker label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; max-width: 480px; }
select, input[type=text], textarea {
  font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff;
}
.results-head { margin-top: 20px; }
table.rules td.rate { font-weight: 600; white-space: nowrap; }
table.rules td.scope { max-width: 360px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { background: #eef0f3; border-radius: 4px; padding: 1px 6px; font-size: 11.5px; white-space: nowrap; }
.chip.acct { background: var(--accent-soft); color: var(--accent); }

/* issues */
.filters { display: flex; gap: 16px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filters .clear { margin-left: auto; color: var(--accent); text-decoration: none; }
.issue header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.issue header h3 { margin: 0; flex-basis: 100%; font-size: 15px; }
.issue .id { font-weight: 700; color: var(--muted); }
.notes { margin: 8px 0; padding-left: 18px; }
.notes li { margin: 2px 0; }
.issue-actions { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.issue-actions form { display: flex; gap: 6px; }
.note-form input { min-width: 220px; }
button {
  font: inherit; font-weight: 600; padding: 7px 14px; border: 0; border-radius: 7px;
  background: var(--accent); color: #fff; cursor: pointer;
}
button:hover { background: #2450b8; }
.add-form { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.add-form .row { display: flex; gap: 12px; flex-wrap: wrap; }
.add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

/* rep details ------------------------------------------------------------- */
/* Full viewport width on desktop — the grid is wide and viewed on big screens. */
main:has(#rd-grid) { max-width: none; width: 100%; padding-left: 20px; padding-right: 20px; }
kbd {
  font: 11px/1 ui-monospace, Menlo, monospace; background: #eef0f3;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px;
}
.rd-banner b { color: #8a5a00; }
.rd-banner ul { margin: 8px 0 0; padding-left: 18px; }
.rd-banner li { margin: 3px 0; }

.rd-toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.rd-toolbar #rd-search { flex: 1; max-width: 520px; }
#rd-count { margin-left: auto; }

.rd-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; align-items: center; }
.rd-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid #cfe0fb;
  border-radius: 16px; padding: 3px 6px 3px 10px;
}
.rd-pill-x, .rd-panel-close, .rd-pill-x { border: 0; background: none; cursor: pointer; color: inherit; }
.rd-pill-x { font-size: 15px; line-height: 1; padding: 0 2px; }
.rd-pill-x:hover { color: #a3261d; background: none; }
.rd-clear-all { font-size: 12px; padding: 4px 10px; }

.rd-layout { display: flex; gap: 16px; align-items: flex-start; }
.rd-grid-wrap { flex: 1; overflow-x: auto; max-height: 78vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }

table.rd-grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
table.rd-grid th, table.rd-grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
table.rd-grid thead th {
  position: sticky; top: 0; z-index: 5; background: #f0f2f5;
  border-bottom: 2px solid var(--line); text-align: left;
}
/* sticky first column: solid opaque bg + a subtle right edge so scrolling
   content never shows through or smears underneath it */
table.rd-grid td.sticky-col, table.rd-grid th.sticky-col {
  position: sticky; left: 0;
  box-shadow: 1px 0 0 var(--line), 3px 0 6px -3px rgba(0, 0, 0, .18);
}
table.rd-grid td.sticky-col { z-index: 4; background: var(--panel); }
table.rd-grid thead th.sticky-col { z-index: 6; background: #f0f2f5; }
table.rd-grid tbody tr:hover td.sticky-col { background: #f7f9fc; }

.rd-th-head { display: flex; align-items: center; }
/* small info "ⓘ" next to a header label; long note lives in its title tooltip */
.rd-info {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 5px; flex: 0 0 14px; width: 14px; height: 14px;
  border: 1px solid var(--line); border-radius: 50%;
  font-size: 9px; line-height: 1; color: var(--muted); cursor: help;
  font-weight: 400; text-transform: none; letter-spacing: 0;
}
.rd-info:hover { color: var(--accent); border-color: var(--accent); }
.rd-sort { background: none; border: 0; padding: 0; color: var(--ink); font: inherit; font-weight: 700;
  text-transform: uppercase; font-size: 11px; letter-spacing: .03em; cursor: pointer; }
.rd-sort:hover { color: var(--accent); background: none; }
.rd-sort-ind { color: var(--accent); }
.rd-filter { margin-top: 4px; }
/* uniform filter affordance: text inputs and multi-select summaries share the
   same box size / border / placement so the header row reads consistently */
.col-text, details.col-multi summary {
  width: 100%; max-width: 150px; padding: 3px 6px; font-size: 11.5px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink);
}
details.col-multi { font-size: 11.5px; position: relative; }
details.col-multi summary {
  cursor: pointer; list-style: none; font-weight: 400;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
details.col-multi summary::after { content: "▾"; color: var(--muted); font-size: 10px; }
details.col-multi summary::-webkit-details-marker { display: none; }
details.col-multi[open] summary { border-color: var(--accent); color: var(--accent); }
.col-multi-box {
  position: absolute; z-index: 6; margin-top: 4px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 240px;
  overflow: auto; box-shadow: 0 4px 14px rgba(0,0,0,.12); min-width: 150px;
  left: 0;
}
/* When a dropdown would overflow the right viewport edge, anchor it to the
   right of its summary so it opens leftward and never clips (full-width grid). */
details.col-multi.flip-right .col-multi-box { left: auto; right: 0; }
.col-opt { display: flex; gap: 6px; align-items: center; font-weight: 400; padding: 2px 0; text-transform: none; letter-spacing: 0; color: var(--ink); }

.rd-grid .chips { gap: 4px; }
.rd-grid .chips.expanded .chip-extra { display: inline-block; }

/* column sizing: overrides are mostly empty (em-dash) so let them shrink to
   content, and hand the freed width to the dense item-class / customer columns */
.rd-grid th.col-overrides_received, .rd-grid td.col-overrides_received,
.rd-grid th.col-overrides_given, .rd-grid td.col-overrides_given {
  width: 1%; white-space: nowrap;
}
.rd-grid th.col-item_classes, .rd-grid td.col-item_classes,
.rd-grid th.col-accounts, .rd-grid td.col-accounts { min-width: 168px; }
.rd-grid td.col-item_classes .chips, .rd-grid td.col-accounts .chips { max-width: 280px; }

/* empty-cell em-dashes recede into a lighter gray than regular muted text */
.rd-grid td .muted { color: #b3bac4; }
/* base-rate values are often free text ("2 on own customers + 0.2 on all USA")
   — show them as a normal wrapped text cell, not pill-styled chips */
.rd-grid .chips-rates { display: block; max-width: 220px; }
.rd-grid .chips-rates .chip {
  display: block; background: none; padding: 0; margin: 1px 0;
  white-space: normal; color: var(--ink);
}
.chip-extra { display: none; }
.chip-drill { cursor: pointer; }
.chip-drill:hover { background: var(--accent-soft); color: var(--accent); outline: 1px solid #cfe0fb; }
.rd-more { font-size: 11px; padding: 1px 6px; margin-top: 4px; background: #eef0f3; color: var(--accent); font-weight: 600; }
.rd-more:hover { background: var(--accent-soft); }
.rd-rep-link { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
/* rep codes are primary keys, not tags — plain bold dark monospace, no pill bg */
.rd-grid .rd-rep-link code {
  background: none; padding: 0; font-weight: 700; color: var(--ink);
  font-size: 12.5px; letter-spacing: .01em;
}
.rd-rep-link:hover code { background: none; color: var(--accent); text-decoration: underline; }
.rd-badge {
  background: #fde2e1; color: #a3261d; font-weight: 700; border-radius: 12px;
  padding: 1px 9px; cursor: pointer; min-width: 22px;
}
.rd-badge:hover { background: #f7c7c4; }

.rd-panel { width: 320px; flex: 0 0 320px; position: relative; align-self: flex-start; max-height: 78vh; overflow: auto; }
.rd-panel-close { position: absolute; top: 8px; right: 10px; font-size: 20px; line-height: 1; color: var(--muted); }
.rd-panel-close:hover { color: var(--ink); }
.rd-panel-kind { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.rd-panel-title { font-size: 17px; margin: 2px 0 6px; }
.rd-panel-summary { color: var(--muted); margin: 0 0 10px; }
.rd-panel-list { list-style: none; margin: 0 0 10px; padding: 0; }
.rd-panel-list li { margin: 3px 0; }
.rd-pivot { background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-weight: 600; text-align: left; width: 100%; }
.rd-pivot:hover { background: #dbe7fb; }
.rd-panel-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 4px; }
.rd-issue { padding: 6px 0; border-bottom: 1px solid var(--line); }
.rd-issue-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rd-issue-all { display: inline-block; margin-top: 8px; color: var(--accent); text-decoration: none; font-weight: 600; }

/* recommendations */
.intro { max-width: 760px; color: var(--muted); }
.rec-section { margin-top: 24px; }
.rec h3 { margin: 0 0 10px; font-size: 15px; color: var(--accent); }
dl.rec-points { display: grid; grid-template-columns: 90px 1fr; gap: 4px 14px; margin: 0; }
dl.rec-points dt { font-weight: 700; font-size: 12.5px; }
dl.rec-points dd { margin: 0; }
dl.rec-points dd.plain { grid-column: 1 / -1; }
.lbl-today { color: var(--muted); }
.lbl-win   { color: #2f6b3d; }
.rec-notes { line-height: 1.7; }

/* ---------------------------------------------------------------------- */
/* Cloudflare Pages additions                                               */
/* ---------------------------------------------------------------------- */

/* Logout link in topbar */
.logout-link {
  margin-left: auto;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
}
.logout-link:hover { background: var(--accent-soft); color: var(--accent); }

/* Missing-field chips in rep details */
.chip.warn { background: #fde2e1; color: #a3261d; }

/* Countries column */
.rd-grid th.col-countries, .rd-grid td.col-countries { min-width: 100px; }

/* Inline edit affordances */
.rd-edit-btn {
  font-size: 10px; padding: 1px 5px; margin-left: 4px; margin-top: 2px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid #cfe0fb;
  border-radius: 4px; font-weight: 600; cursor: pointer; vertical-align: middle;
  opacity: 0.7;
}
.rd-edit-btn:hover { opacity: 1; background: #dbe7fb; }
td:hover .rd-edit-btn { opacity: 1; }

.rd-edit-wrap {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}
.rd-edit-save, .rd-edit-cancel {
  padding: 2px 7px; font-size: 13px; font-weight: 700; border-radius: 4px;
}
.rd-edit-save { background: #2f6b3d; color: #fff; }
.rd-edit-save:hover { background: #256030; }
.rd-edit-cancel { background: #eef0f3; color: var(--ink); }
.rd-edit-cancel:hover { background: #e2e4e8; }

/* Countries column in filter options */
.col-countries .col-multi { font-size: 11.5px; }

/* ---------------------------------------------------------------------- */
/* Login page                                                               */
/* ---------------------------------------------------------------------- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 40px 36px; width: 100%; max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-brand { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-brand span { color: var(--muted); font-weight: 500; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 28px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; margin-bottom: 16px; }
.login-card input[type=password] { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.login-btn { width: 100%; padding: 10px; font-size: 15px; }
.login-error { color: #a3261d; font-size: 13px; margin-top: 12px; display: none; }
.login-error.show { display: block; }
.privacy-badge {
  margin-top: 20px; text-align: center; font-size: 12px;
  color: var(--muted); border: 1px dashed var(--line);
  padding: 6px 12px; border-radius: 20px;
}
