/* Alerting — sits inside .recon.jira and reuses the Jira page's rows and
 * fields. The per-check rule editor and the group member chips are new. */

/* Alerts take the left half; groups and recipients stack in the right. */
.alerting-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}

/* --- Alerts list: a titled section per band, a bordered card per check ---- */

.alerting-band { margin-bottom: 1.25rem; }
.alerting-band:last-child { margin-bottom: 0; }

/* Scrolls with its checks. It was pinned (position: sticky), but cards showed
 * through a gap above it in the browser this is used in; not worth the risk. */
.alerting-band__title {
  margin: 0;
  padding: 0.6rem 0.25rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.alerting-check {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.alerting-check.is-open { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.alerting-check__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
}

/* The whole name-and-count strip is the expander; "Add alert" sits beside it. */
.alerting-check__toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.alerting-check__toggle .jira-report-row__main { flex: 1; }

.alerting-check__chevron {
  color: var(--text-muted);
  transition: transform 0.12s ease;
}

.alerting-check.is-open .alerting-check__chevron { transform: rotate(90deg); }

.alerting-count {
  min-width: 1.6rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  text-align: center;
}

.alerting-count.is-zero {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text-muted);
}

/* A check with a rule alerting now (red) or just recovered (green). */
.alerting-count.is-bad { background: var(--bad); color: #fff; }
.alerting-count.is-good { background: var(--good); color: #fff; }

.alerting-check__body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: color-mix(in srgb, var(--text) 3%, transparent);
}

.alerting-check__empty {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.alerting-rule,
.alerting-rule__form {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.6rem 0.75rem;
  margin: 0;
}

/* Each saved alert is one line, divided from the next. */
.alerting-rule + .alerting-rule,
.alerting-rule + .alerting-rule--new {
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.alerting-rule.is-off .alerting-rule__form { opacity: 0.6; }

/* The rule's live state: a dot plus the word, so colour is never the only cue. */
.alerting-rule__state { padding-bottom: 0.55rem; }
.alerting-rule__state::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: currentColor;
}
.alerting-rule .jira-toggle { padding-bottom: 0.45rem; }
.alerting-rule__form input[type="number"] { width: 100%; min-width: 9rem; }

/* A hold-off field: its label and the Instant tick-box share the top line. */
.alerting-minutes__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.alerting-instant {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text);
  cursor: pointer;
}
.alerting-instant input { margin: 0; }
/* Instant is on: the minutes are fixed at 0. */
.alerting-minutes input[readonly] { opacity: 0.45; cursor: not-allowed; }

.alerting-emails { flex: 1; min-width: 16rem; }

/* In a half-width column the row's three-across grid is too tight. */
.alerting-split .jira-report-row { grid-template-columns: minmax(0, 1fr) auto; }
.alerting-split .jira-report-row > .jira-report-row__sub,
.alerting-members { grid-column: 1 / -1; grid-row: 2; }

/* A group's members: one wrapping line of green chips, each removable. */
.alerting-members {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.alerting-member {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid color-mix(in srgb, var(--good) 35%, var(--border));
  border-radius: 999px;
  background: var(--good-soft);
  color: var(--good);
  font-size: 0.78rem;
  cursor: pointer;
}

/* The checkbox is the posted value; the × is what's clicked. Kept focusable. */
.alerting-member > input { position: absolute; opacity: 0; pointer-events: none; }
.alerting-member:focus-within { outline: 2px solid var(--good); outline-offset: 1px; }

.alerting-members > select {
  padding: 0.15rem 0.4rem;
  border: 1px dashed var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

/* Side by side, the page fills the viewport (main--fill) and never scrolls
 * itself: each card's list (.alerting-scroll) scrolls inside its card, with the
 * right-hand add forms pinned below their lists. Each flex/grid level needs
 * min-height: 0 or it grows to its content and the page scrolls instead. */
@media (min-width: 1101px) {
  .alerting,
  #alerting-body,
  .alerting-split > div,
  .alerting-split .recon-group,
  .alerting-split > div:last-child .recon-group__body {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .alerting,
  #alerting-body,
  .alerting-split { flex: 1; }

  .alerting-split {
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }

  .alerting-scroll { overflow-y: auto; min-height: 0; }

  /* The list takes the card's spare height, so the add form sits at the bottom. */
  .alerting-split > div:last-child .recon-group__body,
  .alerting-split > div:last-child .alerting-scroll { flex: 1; }

  /* Groups take what they need, up to half the column; recipients fill the
   * rest, down to the bottom of the alerts card. */
  .alerting-split > div:last-child > .recon-group:first-child { flex: 0 1 auto; max-height: 50%; }
  .alerting-split > div:last-child > .recon-group:last-child { flex: 1; min-height: 12rem; }
}

@media (max-width: 1100px) {
  .alerting-split { grid-template-columns: 1fr; }
}

/* --- History --------------------------------------------------------------- */

/* The filters sit on the page, not in a card: flush with the card below. */
.alerting-history-filters { padding: 0 0 1rem; }

/* The page fills the viewport (main--fill) and never scrolls itself: the
 * records scroll inside their card, under a pinned header, with the pager
 * always in view below. Each flex level needs min-height: 0, as on /alerting. */
.alerting-history-page,
#alert-history-rows,
#alert-history-rows > .recon-group,
#alert-history-rows .recon-group__body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#alert-history-rows { flex: 1; }

.alerting-history { overflow: auto; min-height: 0; padding: 0 0.5rem; }

.alerting-history__table { font-size: 0.85rem; }
.alerting-history__table th,
.alerting-history__table td { padding: 0.5rem 0.75rem; white-space: nowrap; }
.alerting-history__table thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }

.alerting-history__num,
.alerting-history__table th.alerting-history__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Alert / Resolved, as a soft badge: the column you scan for. */
.alerting-pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}
.alerting-pill.is-bad { background: var(--bad-soft); color: var(--bad); }
.alerting-pill.is-good { background: var(--good-soft); color: var(--good); }

.alerting-history + .pagination { margin-top: 0.5rem; padding: 0.75rem 0.75rem 0.25rem; }

/* The check name opens its alerts on /alerting. */
.alerting-history__table a { color: var(--accent); text-decoration: none; font-weight: 600; }
.alerting-history__table a:hover { text-decoration: underline; }
