/* Alerts page (js/views/alerts.js, js/alerts/**) and the key-races strip (js/alerts/keyraces.js). Owner: the alerts module agent.
   Loaded after app.css on every page (the strip is embedded on the board). Every class carries the .al- prefix; shared
   components (.card, .btn, .seg-toggle, .chip, .badge, .tag, .meter, .field, .toolbar) and variables come from app.css.
   Colours that depend on a margin or probability come from js/core/colors.js, not from here. */

/* ---- badges for the alert kinds app.css does not know (pace, market, system, watch) ---------------------------------------- */
.badge-pace {
  color: var(--orgs);
  border-color: var(--orgs);
}
.badge-market {
  color: var(--spend);
  border-color: var(--spend);
}
.badge-system,
.badge-custom {
  color: var(--muted);
}

/* ---- star (watch) button, used in the strip tiles and the alert rows ---------------------------------------------------------- */
.al-star {
  position: relative;
  z-index: 1;
  min-width: 28px;
  min-height: 28px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.al-star:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 6%, transparent);
}
.al-star[aria-pressed='true'] {
  color: var(--accent);
}

/* ---- key races strip --------------------------------------------------------------------------------------------------------------- */
.al-kr-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 10px;
}
.al-kr-note {
  flex: 1 1 220px;
  font-size: 13px;
}
.al-kr-ctl {
  align-self: center;
}
.al-kr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(232px, 100%), 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.al-kr-tile {
  position: relative;
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  padding: 9px 12px 10px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--mid);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.al-kr-tile:hover {
  background: var(--surface-3);
}
.al-kr-tile.al-kr-D {
  border-top-color: var(--d-fill);
}
.al-kr-tile.al-kr-R {
  border-top-color: var(--r-fill);
}
.al-kr-tile.is-settled {
  opacity: 0.8;
}
.al-kr-top {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin-left: -6px;
}
.al-kr-label {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.al-kr-label::after {
  /* the whole tile is the link; the star and chips above it stay clickable through z-index */
  content: '';
  position: absolute;
  inset: 0;
}
.al-kr-label:hover {
  text-decoration: none;
}
.al-kr-chip {
  margin-left: auto;
  position: relative;
}
.al-kr-name {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.al-kr-num {
  font-size: 22px;
  font-weight: 750;
  line-height: 1.15;
}
.al-kr-kind {
  display: inline;
  margin-left: 4px;
  font-size: 11px;
  font-weight: 400;
}
.al-kr-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.al-kr-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 20px;
  margin-top: 2px;
}
.al-kr-foot .tag {
  margin: 0;
}
.al-kr-tip {
  color: var(--accent);
  border-color: var(--accent);
}
.al-kr-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-top: 10px;
  font-size: 13px;
}
.al-kr-all {
  margin-left: auto;
}

/* ---- the Alerts page ------------------------------------------------------------------------------------------------------------------ */
.al-strip {
  margin-bottom: 14px;
}
.al-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}
.al-side {
  display: grid;
  gap: 14px;
}
.al-fine {
  font-size: 12.5px;
}
.al-feed {
  padding-inline: 0;
}
.al-feed > .card-head,
.al-feed > .toolbar,
.al-feed > .empty,
.al-feed > .al-more {
  padding-inline: 16px;
}
.al-toolbar .field select {
  min-width: 7em;
}
.al-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.al-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-fill);
}
.al-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.al-row {
  display: grid;
  grid-template-columns: 8.2em 11.5em minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 12px;
  padding: 9px 12px 9px 16px;
  border-top: 1px solid var(--line-soft);
  font-size: 13.5px;
  box-shadow: inset 3px 0 0 transparent;
}
.al-row.al-p-D {
  box-shadow: inset 3px 0 0 var(--d-fill);
}
.al-row.al-p-R {
  box-shadow: inset 3px 0 0 var(--r-fill);
}
.al-row.al-lv-critical {
  background: color-mix(in srgb, var(--accent-fill) 5%, transparent);
}
.al-row.is-unread .al-title::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent-fill);
  vertical-align: 1px;
}
.al-new {
  animation: flash 2.4s ease-out;
}
.al-time {
  display: grid;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  white-space: nowrap;
}
.al-clock {
  color: var(--faint);
}
.al-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}
.al-sev {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.al-sev-critical {
  color: var(--accent);
}
.al-sev-notice {
  color: var(--text);
}
.al-sev-info {
  color: var(--faint);
}
.al-sev-warn {
  color: var(--warn);
}
.al-body {
  min-width: 0;
  line-height: 1.4;
}
.al-title {
  color: var(--text);
  font-weight: 650;
}
a.al-title:hover {
  text-decoration: underline;
}
.al-lv-critical .al-title {
  font-weight: 750;
}
.al-text {
  color: var(--muted);
}
.al-state {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 16px;
  vertical-align: 1px;
}
.al-more {
  display: flex;
  justify-content: center;
  padding-top: 12px;
}

/* settings and watchlist */
.al-switch {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
}
.al-switch > input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent-fill);
}
.al-switch > span {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.al-switch small {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}
.al-level {
  margin: 4px 0 8px;
}
.al-tests {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.al-msg {
  min-height: 1.4em;
  margin-top: 6px;
  font-size: 12.5px;
}
.al-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 10px;
  padding: 0;
  list-style: none;
}
.al-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 2px 4px 2px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-fill) 8%, transparent);
  font-size: 12.5px;
}
.al-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.al-chip button {
  min-width: 24px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 20px;
  cursor: pointer;
}
.al-chip button:hover {
  color: var(--text);
}

@media (max-width: 1100px) {
  .al-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .al-side {
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  }
}
@media (max-width: 760px) {
  .al-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'tags time' 'body body';
    padding-inline: 12px;
  }
  .al-tags {
    grid-area: tags;
  }
  .al-time {
    grid-area: time;
    grid-auto-flow: column;
    gap: 8px;
    text-align: right;
  }
  .al-body {
    grid-area: body;
  }
  .al-row > .al-star {
    position: absolute;
    right: 6px;
    bottom: 4px;
  }
  .al-row {
    position: relative;
    padding-bottom: 14px;
  }
  .al-body {
    padding-right: 26px;
  }
  .al-kr-grid {
    grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
    gap: 8px;
  }
  .al-kr-tile {
    padding: 8px 9px 9px;
  }
  .al-kr-num {
    font-size: 20px;
  }
  .al-kr-chip .chip {
    padding: 1px 7px;
    font-size: 11px;
  }
  .al-kr-label {
    font-size: 14px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .al-new {
    animation: none;
  }
}

/* a 2-column grid of key-race tiles truncated the label to "KS ..." on a phone: one column below 420px */
@media (max-width: 420px) {
  .al-kr-grid {
    grid-template-columns: 1fr;
  }
}
