/* Manual review UI. Self-contained: no fonts, icons or scripts are fetched
   from the network -- the page must work on a machine with no internet. */

:root {
  color-scheme: light dark;

  --bg:        #f6f7f9;
  --panel:     #ffffff;
  --panel-2:   #fbfbfd;
  --line:      #e3e6ec;
  --line-soft: #eef0f4;
  --text:      #16181d;
  --muted:     #6b7280;
  --accent:    #2f6df6;
  --accent-sf: #e8efff;
  --good:      #12805c;
  --good-sf:   #e2f5ee;
  --warn:      #b45309;
  --warn-sf:   #fdf1de;
  --danger:    #c02b2b;
  --danger-sf: #fdeaea;
  --shadow:    0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius:    12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1115;
    --panel:     #171a20;
    --panel-2:   #1c2027;
    --line:      #2a2f39;
    --line-soft: #232830;
    --text:      #e7eaf0;
    --muted:     #98a1b0;
    --accent:    #6f9bff;
    --accent-sf: #1d2740;
    --good:      #4ad3a4;
    --good-sf:   #14302a;
    --warn:      #f0b354;
    --warn-sf:   #33280f;
    --danger:    #ff7b7b;
    --danger-sf: #3a1c1e;
    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 620; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 0 1 280px; }
.brand h1 { font-size: 15px; letter-spacing: -.01em; }
.brand p { margin: 1px 0 0; font-size: 12px; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 4px var(--good-sf);
}

/* min-width:0 or the input collapses to nothing when the bar gets tight. */
.search { flex: 1 1 160px; min-width: 0; display: flex; justify-content: center; }

.search input {
  width: 100%;
  max-width: 560px;
  min-width: 0;
  padding: 9px 14px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-sf);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.totals { font-size: 12px; color: var(--muted); white-space: nowrap; }
.window-select {
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.window-select:disabled { opacity: .5; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 560;
  color: var(--text);
  text-decoration: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--line-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.close { font-size: 20px; line-height: 1; padding: 2px 10px 5px; }
.danger-text { color: var(--danger); }

.btn.primary {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .18);
}
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.primary:disabled { filter: none; }

/* -------------------------------------------------------------------- layout */
.layout { flex: 1; display: flex; min-height: 0; }

.rail {
  /* A quarter of the page: the search parameters are edited far more often than
     they are glanced at, and the keyword list needs the room. Capped so an
     ultrawide screen does not hand it a strip it cannot fill. */
  width: 25%;
  min-width: 248px;
  max-width: 520px;
  flex: none;
  padding: 16px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.presets { display: flex; flex-direction: column; gap: 2px; }

.presets button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  font: inherit;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.presets button:hover { background: var(--line-soft); color: var(--text); }
.presets button.active {
  color: var(--accent);
  background: var(--accent-sf);
  font-weight: 600;
}

.rail-group {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}
.rail-group h2 {
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.rail-group .big { margin: 0 0 10px; font-size: 30px; font-weight: 650; letter-spacing: -.02em; }

.switch { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; font-size: 13px; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ------------------------------------------------------- the auto-mode panel */
.auto-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.auto-badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--line-soft);
}
.auto-badge.is-on { color: var(--good); background: var(--good-sf); }
.auto-head .btn { margin-left: auto; }
.auto-last { margin-bottom: 0; }

/* ------------------------------------------------- the Keywords facet panel */
.rail-hint {
  margin: 0 0 10px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.kw-modes { display: flex; flex-direction: column; gap: 1px; margin-bottom: 6px; }
.kw-modes label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
}
.kw-modes input { accent-color: var(--accent); width: 14px; height: 14px; }
.kw-mode-help { min-height: 2.6em; font-style: italic; }

.kw-list { list-style: none; margin: 0 0 8px; padding: 0; }
.kw-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 9px;
  margin-bottom: 3px;
  font-size: 12.5px;
  background: var(--accent-sf);
  border-radius: 7px;
  word-break: break-word;
}
.kw-list li span { flex: 1; min-width: 0; }
.kw-list li button {
  flex: none;
  width: 18px;
  height: 18px;
  padding: 0;
  font: inherit;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}
.kw-list li button:hover { color: var(--danger); background: var(--danger-sf); }

.kw-add { display: flex; gap: 5px; margin-bottom: 9px; }
.kw-add input {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.kw-add input:focus { outline: 2px solid var(--accent-sf); border-color: var(--accent); }

.kw-actions { display: flex; gap: 6px; }
.kw-status { margin: 8px 0 0; min-height: 1.4em; }
.kw-status.saved { color: var(--good); }
.kw-status.bad { color: var(--danger); }

/* A published read-only instance shows the facet but cannot change it. */
body.read-only #kw-form,
body.read-only .kw-actions { display: none; }
body.read-only .kw-list li button { display: none; }
body.read-only .kw-modes input { pointer-events: none; }

.notice {
  margin-top: 18px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--warn);
  background: var(--warn-sf);
  border-radius: 9px;
}
.notice code { font-size: 11px; }

/* --------------------------------------------------------------- the listing */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 14px 18px 0; }

.ai-steps { margin-top: 4px; font-size: 12px; }

.table-head,
.row {
  display: grid;
  grid-template-columns: 34px 74px 62px minmax(220px, 1fr) 140px 150px 84px 120px;
  align-items: center;
  gap: 12px;
}

.table-head {
  padding: 0 14px 8px;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.table-head .col {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 4px 0;
  text-align: left;
  cursor: pointer;
  border-radius: 5px;
}
.table-head .col:hover { color: var(--text); }
.table-head .col.sorted::after { content: " \25BE"; }
.table-head .col.sorted.asc::after { content: " \25B4"; }

/* Posted and due, one above the other: both dates matter when triaging, and a
   single column keeps the row height unchanged. */
.dates { font-size: 11.5px; line-height: 1.5; white-space: nowrap; }
.dates .k {
  display: inline-block;
  /* Wide enough for "POSTED" plus a gap: the label and the date must not touch. */
  width: 48px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: .06em;
}
.dates .v { font-variant-numeric: tabular-nums; }
.dates .none { color: var(--muted); }

/* ------------------------------------------------------------ AI shortlist */
/* The trigger for the on-demand sort, sitting above the table on its own view
   so the button is next to the list it rebuilds. */
.ai-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 12px;
  padding: 12px 14px;
  background: var(--accent-sf);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.ai-copy { flex: 1; min-width: 0; }
.ai-copy strong { display: block; font-size: 13px; letter-spacing: -.01em; }
.ai-copy p { margin: 3px 0 0; font-size: 12px; }
.ai-panel .btn { white-space: nowrap; }

/* The place a notice took in the shortlist, in the Rank column above its score. */
.place {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--accent);
}
/* Why the model put it there. Wraps, unlike the meta line above it, because a
   reason cut off mid-sentence is worth nothing. */
.row .why {
  margin-top: 3px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.rows { flex: 1; overflow-y: auto; padding-bottom: 18px; }

.row {
  padding: 11px 14px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .06s;
}
.row:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.row.selected { border-color: var(--accent); background: var(--accent-sf); }
.row.is-sent { opacity: .62; }

.row .title { font-weight: 560; letter-spacing: -.005em; }
.row .sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score { display: flex; flex-direction: column; gap: 4px; }
.score b { font-size: 15px; font-weight: 620; letter-spacing: -.02em; }
.bar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

.days { font-size: 13px; font-weight: 560; }
.days.urgent { color: var(--danger); }
.days.soon { color: var(--warn); }

/* Checkbox that stays visible and clickable inside a clickable row. */
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkbox span {
  width: 18px; height: 18px;
  border: 1.5px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
  display: inline-block;
  position: relative;
  transition: background .12s, border-color .12s;
}
.checkbox input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox input:checked + span::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}
.checkbox input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-sf); }
.big-check em { font-style: normal; font-weight: 560; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  border-radius: 999px;
  background: var(--line-soft);
  color: var(--muted);
  white-space: nowrap;
}
.pill.match  { background: var(--good-sf);   color: var(--good); }
.pill.new    { background: var(--accent-sf); color: var(--accent); }
.pill.no     { background: var(--danger-sf); color: var(--danger); }
.pill.sent   { background: var(--line-soft); color: var(--muted); }
/* Waiting to be collected: a promise, not yet a receipt. */
.pill.queued { background: var(--accent-sf); color: var(--muted); }
.pill.type   { background: transparent; border: 1px solid var(--line); }
.pill.source { background: transparent; border: 1px solid var(--line); }
.pill.source.dsip { background: var(--accent-sf); color: var(--accent); border-color: transparent; }
.pill.source.xtech { background: var(--warn-sf); color: var(--warn); border-color: transparent; }
.pill.source.sofwerx { background: var(--good-sf); color: var(--good); border-color: transparent; }
.pill.att::before { content: "\1F4CE\00a0"; }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- action bar */
.actionbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.actionbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.actionbar-right .muted { font-size: 12px; }

/* ------------------------------------------------------------ reading sheet */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
  background: rgba(12, 15, 22, .55);
  backdrop-filter: blur(3px);
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  display: flex;
  flex-direction: column;
  width: min(1500px, 96vw);
  height: 96vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise .14s ease-out;
}
@keyframes rise { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.sheet-title { min-width: 0; }
.sheet-title h2 { font-size: 21px; letter-spacing: -.015em; margin: 6px 0 3px; }
.sheet-title p { margin: 0; font-size: 13px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-head-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.sheet-body { flex: 1; display: flex; min-height: 0; }

.sheet-main { flex: 1; min-width: 0; overflow-y: auto; padding: 24px 30px 40px; }

.description {
  max-width: 108ch;
  margin: 0 auto;
  font-size: 15.5px;
  line-height: 1.68;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.description.placeholder { color: var(--muted); font-style: italic; }

.sheet-side {
  width: 330px;
  flex: none;
  overflow-y: auto;
  padding: 20px 22px 40px;
  background: var(--panel-2);
  border-left: 1px solid var(--line);
}

.meta { margin: 0; font-size: 13px; }
.meta dt {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 13px;
}
.meta dt:first-child { margin-top: 0; }
.meta dd { margin: 2px 0 0; overflow-wrap: anywhere; }

.attachments { margin-top: 22px; }
.attachments h3,
.subject h3 {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 600;
}
.attachments ul { margin: 0; padding-left: 18px; font-size: 13px; }
.attachments li { margin-bottom: 5px; overflow-wrap: anywhere; }

.subject { margin-top: 22px; }
.subject code {
  display: block;
  padding: 9px 11px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.sheet-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 22px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
.spacer { flex: 1; }

/* -------------------------------------------------------------- activity log */
.activity {
  position: fixed;
  right: 20px;
  bottom: 74px;
  z-index: 60;
  width: min(560px, 90vw);
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.activity header {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.activity header strong { font-size: 13px; }
.activity header .btn { margin-left: auto; }
.activity pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  font: 12px/1.6 "Cascadia Mono", Consolas, ui-monospace, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  z-index: 70;
  padding: 11px 18px;
  font-weight: 560;
  color: #fff;
  background: #23262e;
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.toast.bad { background: var(--danger); }

/* --------------------------------------------------------------- narrow view */
/* Raised from 1180px: the rail is wider now, so the full grid runs out of room
   sooner. Status goes first -- it is the one column already shown as a pill in
   the reading sheet. */
@media (max-width: 1360px) {
  .sheet-side { display: none; }
  .table-head, .row {
    grid-template-columns: 34px 68px 56px minmax(170px, 1fr) 132px 110px 76px;
  }
  /* nth-child(8): the dates and source columns shifted Status along. */
  .table-head .col:nth-child(8), .row .status-cell { display: none; }
}
@media (max-width: 900px) {
  .rail { display: none; }
  .brand { min-width: 0; }
}

/* A read-only instance has nothing to select and nothing to configure: the
   controls are hidden rather than left inert for people to click at.
   `visibility`, not `display`: the rows are a grid, and removing an item
   would shift every following cell into the wrong column. */
body.read-only .checkbox { visibility: hidden; }
body.read-only #selection-panel,
body.read-only #config-warning { display: none !important; }
