/* ==========================================================================
   mail.jarin.dev — spam filtering (spam list, reader banner, settings dialog)
   Owns only the .spam-* surfaces, the spam row / banner / thread stamps and
   the .list-actions strip. Every colour is a token from styles.css, so all six
   themes — including midnight, whose color-scheme flips to dark — repaint with
   no second rule set here.
   ========================================================================== */

/* ---------- List header actions ------------------------------------------
   Sits at the right end of the .list-header baseline row; the title and count
   keep their natural place, so the strip can only ever meet them after it has
   wrapped. Only the buttons' size is set here — .btn-danger and .btn-quiet
   keep their own stock, border and shadow untouched. */
.list-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
  align-self: center;
}
.list-actions .btn {
  padding: 6px 14px;
  font-size: 13px;
}

/* ---------- Spam rows -----------------------------------------------------
   Set aside, not shouted at: a whisper of red stock and a muted voice, so the
   row still scans as a normal mail row — and still bolds when unread. The tint
   is stated at .spam-row (one class) so .mail-row.active, which is equally
   specific but comes earlier, still wins while the row is the open one. */
.spam-row { background: color-mix(in srgb, var(--red) 4%, var(--card)); }
.spam-row:hover { background: color-mix(in srgb, var(--red) 9%, var(--card)); }
.spam-row .row-from,
.spam-row .row-subject { color: var(--grey); }

/* Score stamp in the row meta. A compact red-keyed pill: it is a grade the
   scanner gave the message, never one of the status colours used elsewhere. */
.spam-chip {
  padding: 0 6px;
  border: var(--b) solid var(--red);
  border-radius: 999px;
  background: color-mix(in srgb, var(--red) 12%, var(--card));
  color: var(--red);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.5;
}

/* ---------- Reader banner -------------------------------------------------
   A warning strip, not an error page: red-keyed stock and rule, but flat like
   the .msg cards it sits above (no offset shadow in the thread).
   Wide: two rows of the same strip. Badge, score line and actions fill the
   first, the actions holding the right edge; the reasons take the whole width
   underneath them, so one reason is one line instead of a narrow column. The
   .spam-banner-main wrapper is dissolved with display:contents so its two
   children are laid out at banner level — which is also what the <=680px block
   below already assumes, leaving that stacking order untouched. */
.spam-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--red) 7%, var(--card));
  border: var(--b) solid var(--red);
  border-radius: var(--r);
}

.spam-banner-badge {
  flex: none;
  padding: 2px 8px;
  border: var(--b) solid var(--red);
  border-radius: 999px;
  background: var(--red);
  color: var(--on-blue);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.6;
  text-transform: uppercase;
}

/* No box of its own: the score line and the reasons become banner flex items. */
.spam-banner-main { display: contents; }

.spam-banner-text {
  /* Zero basis so the first row always breaks as badge | score | actions
     however long the message is — the score line takes the slack and the
     actions keep the right edge. The 20ch floor is the one thing that may
     move them: below it the strip gives the actions their own (right-aligned)
     row rather than squeeze this line into a column a few characters wide. */
  flex: 1 1 0;
  min-width: 20ch;
  font-size: 13px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.spam-banner-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
/* Compact stamps: the strip is an aside, it should not out-shout the thread. */
.spam-banner-actions .btn {
  padding: 6px 14px;
  font-size: 13px;
}

/* ---------- Score reasons -------------------------------------------------
   One line per reason; the weight is a fixed column so the texts align. */
.spam-reasons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.spam-reason {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  line-height: 1.45;
  color: var(--grey);
}

.spam-reason-count {
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-align: right;
}

.spam-reason-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* In the banner the list is supporting detail under the score line, so it is
   never given a height of its own: no cap, no scrollbar, no reason cut
   mid-line. A 100% basis lifts it onto a full-width row of its own (the row
   gap alone spaces it from the score line), app.js slices it to three items,
   and the strip grows to fit them; the reader pane is the only thing that
   scrolls. */
.spam-banner .spam-reasons {
  flex: 1 1 100%;
  gap: 2px;
  margin-top: 0;
  overflow: visible;
}

/* Denser than the dialog copy so three wrapped reasons stay a footnote under
   the banner's primary line (the score). */
.spam-banner .spam-reason {
  font-size: 12px;
  line-height: 1.4;
}

/* ---------- Thread auth stamp ---------------------------------------------
   A micro-label beside .msg-date, in the card's muted grey: it reports what
   the receiving server saw, it is not an alarm. .msg-date already carries the
   auto margin, so nothing here pushes on the head layout. */
.msg-auth {
  flex: none;
  color: var(--grey);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---------- Settings dialog ----------------------------------------------- */
.spam-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}
.spam-dialog::backdrop { background: var(--backdrop); }

.spam-shell {
  display: flex;
  flex-direction: column;
  max-height: inherit;   /* the dialog's dvh cap has to reach the scroller */
  overflow: hidden;
  background: var(--card);
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
}

.spam-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 12px 16px;
  border-bottom: var(--b) solid var(--ink);
}
.spam-title {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.01em;
}
.spam-sub {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--grey);
}
.spam-head .icon-btn { margin-left: auto; }

/* The one scroll container of the dialog: the head stays put, this moves. */
.spam-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

/* ---------- Section cards ------------------------------------------------- */
.spam-section {
  padding: 14px 16px;
  /* Paper inside the card shell: the inset reads on every theme, and in
     bright (where paper and card are both white) the ink border carries it. */
  background: var(--paper);
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
}

.spam-section-title {
  padding-bottom: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line2);
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
}

/* ---------- Fields -------------------------------------------------------- */
.spam-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}

.spam-field { display: block; min-width: 0; }

/* Used full-width on its own, and as the grid's spanning row. */
.spam-field-wide {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 12px;
}

/* Dense form: the quiet mono micro-label, same voice as .nav-heading. */
.spam-field .field-label {
  display: block;
  margin-bottom: 2px;
  color: var(--grey);
  font-family: var(--font-mono);
  font-size: 11px;
}
.spam-field:focus-within .field-label { color: var(--blue); }

.spam-field input,
.spam-field select,
.spam-field textarea {
  width: 100%;
  background: none;
  color: var(--ink);
}

/* House control: a single ink rule, blue on focus — no material boxes. */
.spam-field input {
  padding: 6px 0 4px;
  border: 0;
  border-bottom: var(--b) solid var(--line);
}
.spam-field input:focus { border-bottom-color: var(--blue); }

/* The one control that keeps a box, as on the compose sending address. */
.spam-field select {
  padding: 6px 32px 6px 12px;
  border: var(--b) solid var(--line);
  border-radius: 999px;
  background-color: var(--card);
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  appearance: none;
  -webkit-appearance: none;
}
.spam-field select:focus { border-color: var(--blue); }

/* Multi-line instructions follow the reply box: a boxed ink control. */
.spam-field textarea {
  min-height: 92px;
  padding: 8px 10px;
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
  background: var(--card);
  line-height: 1.5;
}
.spam-field textarea:focus { border-color: var(--blue); }

.spam-hint {
  display: block;
  margin-top: 4px;
  color: var(--grey);
  font-size: 12px;
  line-height: 1.4;
}

/* Checkbox + its explanation: the whole row is the target, so it stays
   comfortably tappable even when only the box looks like the control. */
.spam-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 10px;
  padding: 6px 0;
  font-size: 13px;
  line-height: 1.45;
  cursor: pointer;
}
.spam-check input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--blue);
}

/* A model name inside prose: a small mono chip, not a control. */
.spam-inline-code {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line2);
  color: var(--ink);
  font-size: 11px;
  letter-spacing: .02em;
  white-space: nowrap;
}

/* ---------- Save / action rows and status --------------------------------- */
.spam-save-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line2);
}
.spam-save-row .btn { flex: none; }
.spam-save-row .spam-status { flex: 1 1 auto; }

.spam-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.spam-status {
  min-width: 0;
  color: var(--grey);
}
.spam-status[data-state="error"] { color: var(--red); }
/* Standing alone under a section, a status line takes its own row. */
.spam-section > .spam-status {
  display: block;
  margin-top: 8px;
}

/* ---------- Rules ---------------------------------------------------------
   A row wraps rather than overflows: badge and text first, the hit count and
   the two actions fall to a second line on a phone. */
.spam-rules {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.spam-rule {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 5px 8px;
  background: var(--card);
  border: var(--b) solid var(--line);
  border-radius: var(--r);
}
/* Switched off, not gone: kept legible enough to switch back on. */
.spam-rule.disabled { opacity: .55; }

.spam-rule-kind {
  flex: none;
  padding: 1px 7px;
  border: var(--b) solid var(--line);
  border-radius: 999px;
  color: var(--grey);
  font-size: 9px;
  line-height: 1.6;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* The stamp takes the action's colour — same palette as .ai-auto-status.
   `.block` / `.allow` mirror the values the add form submits. */
.spam-rule-kind.block {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 12%, var(--card));
  color: var(--red);
}
.spam-rule-kind.allow {
  border-color: var(--blue-d);
  background: var(--blue-t);
  color: var(--blue-d);
}

.spam-rule-text {
  flex: 1 1 160px;
  min-width: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.spam-rule-hits {
  flex: none;
  color: var(--grey);
}

.spam-rule-toggle,
.spam-rule-delete { flex: none; }

/* The toggle leads the action pair, so on a wrapped row it takes the slack
   and the pair stays right-aligned; with no slack it is a no-op. */
.spam-rule-toggle {
  margin-left: auto;
  color: var(--grey);
}
/* Quiet, unfilled, red — the destructive one should not advertise itself. */
.spam-rule-delete { color: var(--red); }
.spam-rule-delete:hover { background: color-mix(in srgb, var(--red) 10%, var(--card)); }

/* ---------- Add-rule form ------------------------------------------------- */
.spam-add {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line2);
}
.spam-add .spam-field { flex: 1 1 130px; }
.spam-add .spam-field-grow { flex: 2 1 200px; }
.spam-add .btn { flex: none; }

/* ---------- Empty line --------------------------------------------------- */
.spam-empty {
  padding: 6px 0;
  color: var(--grey);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* ---------- <=680px: one pane, bottom sheet ------------------------------ */
@media (max-width: 680px) {
  /* Header actions drop under the title and share the row between them. */
  .list-actions { width: 100%; }
  .list-actions .btn { flex: 1 1 auto; }

  /* The banner's three buttons take their own line and split it. */
  .spam-banner-actions { width: 100%; }
  .spam-banner-actions .btn { flex: 1 1 auto; }

  /* The auth stamp gives ground to the from-address, never the other way. */
  .msg-auth { font-size: 9px; letter-spacing: .06em; }

  /* Same inset as the compose sheet. The dvh cap leaves room for the mobile
     browser chrome, and .spam-scroll absorbs whatever is left over. */
  .spam-dialog {
    width: calc(100vw - 16px);
    inset: auto 8px 8px;
    margin: 0;
    max-height: calc(100dvh - 24px - env(safe-area-inset-bottom));
  }

  .spam-scroll { gap: 12px; padding: 12px; }
  .spam-section { padding: 12px; }
  .spam-grid { grid-template-columns: minmax(0, 1fr); }

  /* A whole check row as the touch target, not the 16px box. */
  .spam-check {
    min-height: 44px;
    padding: 8px 0;
  }

  /* The add row stacks: two selects, then the pattern, then the button.
     The fields drop their row basis — in a column those would be heights. */
  .spam-add {
    flex-direction: column;
    align-items: stretch;
  }
  .spam-add .spam-field { flex: none; }
  .spam-add .btn { width: 100%; }

  .spam-actions .btn { flex: 1 1 auto; }
}

/* ---------- >=681px: the first row carries the actions --------------------
   The reasons are last in the DOM, so their 100% basis breaks the line before
   the actions are ever reached and they land on a row of their own. order
   re-sequences the layout (badge | score | actions, then the reasons) without
   moving a node. The auto margin is a no-op while the actions share that row —
   the score line's grow fills it first — and it right-aligns them if they ever
   do wrap alone at a narrower reader width, instead of leaving dead space.
   Under 681px none of this applies: the block above keeps the approved
   stacking (score line, then reasons, then the three full-width buttons). */
@media (min-width: 681px) {
  .spam-banner-actions {
    order: 1;
    margin-left: auto;
  }
  .spam-banner .spam-reasons { order: 2; }
}

/* ---------- Print: the dialog is a screen surface, never a document ------- */
@media print {
  .spam-dialog { display: none !important; }
  .spam-banner-actions { display: none !important; }
}

/* No transition, animation or smooth scroll is declared here, so there is
   nothing to switch off: the global prefers-reduced-motion block in
   styles.css already collapses the .btn / .icon-btn hovers this file reuses. */
