/* ==========================================================================
   MintRSS components (shared by every page)
   Load order: bootstrap.min.css, fonts.css, tokens.css, components.css, hub.css
   Plain HTML + CSS. The only script is the Light/Auto/Dark control (static/js/theme.js).

   Content-Security-Policy: this file and hub.css must stay free of anything that needs
   'unsafe-inline'. No inline style="" attributes anywhere in the templates: a bar that needs
   a data-driven width is an inline SVG whose <rect> width is an attribute (see .mr-meter).
   ========================================================================== */

/* ---------- Base --------------------------------------------------------- */
html { -webkit-text-size-adjust: 100%; }
body {
  font-feature-settings: "kern" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: var(--mr-lh-tight);
  letter-spacing: -0.01em;
  color: var(--mr-text-strong);
  text-wrap: balance;
}
p { margin: 0; }
a { color: var(--mr-accent-text); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { color: var(--mr-accent-hover); }
:focus-visible { outline: 2px solid var(--mr-focus); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--mr-accent-mark) 35%, transparent); }
code, .mr-mono { font-family: var(--mr-font-mono); font-size: 0.92em; letter-spacing: 0; }
code { color: inherit; }
.mr-num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.mr-meta { font-size: var(--mr-fs-meta); color: var(--mr-text-2); }
.mr-muted { color: var(--mr-text-muted); }
.mr-label {
  font-family: var(--mr-font-mono);
  font-size: var(--mr-fs-label);
  font-weight: 500;
  letter-spacing: var(--mr-tracking-label);
  text-transform: uppercase;
  color: var(--mr-text-2);
  line-height: 1.2;
}
h2.mr-label, h3.mr-label { font-weight: 500; letter-spacing: var(--mr-tracking-label); }
.visually-hidden-focusable:focus { background: var(--mr-surface); padding: .5rem .75rem; z-index: 2000; }

/* ---------- Icons ---------------------------------------------------------
   <svg class="bi"><use href=".../sprite.svg#name"/></svg>, drawn from the vendored Bootstrap
   Icons sprite. Sized in em, coloured by the surrounding text. */
.bi { width: 1em; height: 1em; fill: currentColor; flex: none; vertical-align: -0.125em; }

/* ---------- Status language --------------------------------------------- */
/* Any element with data-state gets --st-* so chips, notices and rows share one source. */
[data-state] {
  --st-solid: var(--mr-offline-solid); --st-fg: var(--mr-offline-fg);
  --st-bg: var(--mr-offline-bg);       --st-bd: var(--mr-offline-bd);
}
[data-state="up"]       { --st-solid: var(--mr-up-solid);       --st-fg: var(--mr-up-fg);       --st-bg: var(--mr-up-bg);       --st-bd: var(--mr-up-bd); }
[data-state="degraded"],
[data-state="warn"]     { --st-solid: var(--mr-degraded-solid); --st-fg: var(--mr-degraded-fg); --st-bg: var(--mr-degraded-bg); --st-bd: var(--mr-degraded-bd); }
[data-state="down"]     { --st-solid: var(--mr-down-solid);     --st-fg: var(--mr-down-fg);     --st-bg: var(--mr-down-bg);     --st-bd: var(--mr-down-bd); }
[data-state="stale"]    { --st-solid: var(--mr-stale-solid);    --st-fg: var(--mr-stale-fg);    --st-bg: var(--mr-stale-bg);    --st-bd: var(--mr-stale-bd); }
[data-state="offline"]  { --st-solid: var(--mr-offline-solid);  --st-fg: var(--mr-offline-fg);  --st-bg: var(--mr-offline-bg);  --st-bd: var(--mr-offline-bd); }
[data-state="unknown"]  { --st-solid: var(--mr-offline-solid);  --st-fg: var(--mr-offline-fg);  --st-bg: transparent;            --st-bd: var(--mr-control-border); }
[data-state="unreach"]  { --st-solid: var(--mr-down-solid);     --st-fg: var(--mr-unreach-fg);  --st-bg: var(--mr-unreach-bg);  --st-bd: var(--mr-unreach-bg); }

/* Annunciator chip: rectangular, mono caps, icon + label. */
.mr-chip {
  display: inline-flex; align-items: center; gap: .375rem;
  padding: .1875rem .5rem .1875rem .375rem;
  border: 1px solid var(--st-bd);
  border-radius: var(--mr-radius-sm);
  background: var(--st-bg);
  color: var(--st-fg);
  font-family: var(--mr-font-mono);
  font-size: var(--mr-fs-label);
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  line-height: 1.25;
  white-space: nowrap;
}
.mr-chip .bi { font-size: 1.05em; }
[data-state="unknown"].mr-chip { border-style: dashed; }

/* Quiet inline state: icon + sentence-case label. For rows that are fine. */
.mr-st {
  display: inline-flex; align-items: center; gap: .375rem;
  color: var(--st-fg); font-size: var(--mr-fs-dense); font-weight: 500; white-space: nowrap;
}

/* Neutral tag: kinds, access scopes, software tags. Outline only, no state colour. */
.mr-tag {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .0625rem .375rem;
  border: 1px solid var(--mr-border-strong);
  border-radius: var(--mr-radius-sm);
  color: var(--mr-text-2);
  font-family: var(--mr-font-mono);
  font-size: var(--mr-fs-label);
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  line-height: 1.35;
  white-space: nowrap;
  text-decoration: none;
}
a.mr-tag:hover { background: var(--mr-surface-3); color: var(--mr-text-strong); border-color: var(--mr-text-2); }

/* ---------- Buttons and the theme control ------------------------------- */
.btn-mr {
  --bs-btn-padding-x: .625rem; --bs-btn-padding-y: .1875rem;
  --bs-btn-font-family: var(--mr-font-sans);
  --bs-btn-font-size: var(--mr-fs-dense); --bs-btn-font-weight: 500; --bs-btn-line-height: 1.4;
  --bs-btn-border-radius: var(--mr-radius); --bs-btn-border-width: 1px;
  --bs-btn-color: var(--mr-text); --bs-btn-bg: transparent; --bs-btn-border-color: var(--mr-control-border);
  --bs-btn-hover-color: var(--mr-text-strong); --bs-btn-hover-bg: var(--mr-surface-3); --bs-btn-hover-border-color: var(--mr-text-2);
  --bs-btn-active-color: var(--mr-text-strong); --bs-btn-active-bg: var(--mr-surface-3); --bs-btn-active-border-color: var(--mr-text-2);
  display: inline-flex; align-items: center; gap: .375rem; white-space: nowrap;
}
.btn-mr .bi { font-size: .95em; }
.btn-mr-primary {
  --bs-btn-color: var(--mr-accent-btn-text); --bs-btn-bg: var(--mr-accent-btn); --bs-btn-border-color: var(--mr-accent-btn);
  --bs-btn-hover-color: var(--mr-accent-btn-text); --bs-btn-hover-bg: var(--mr-accent-hover); --bs-btn-hover-border-color: var(--mr-accent-hover);
  --bs-btn-active-color: var(--mr-accent-btn-text); --bs-btn-active-bg: var(--mr-accent-hover); --bs-btn-active-border-color: var(--mr-accent-hover);
}
.btn:focus-visible { outline: 2px solid var(--mr-focus); outline-offset: 2px; box-shadow: none; }

/* Three-way theme control: Light / Auto (follow OS) / Dark. Plain buttons + static/js/theme.js.
   Without script the buttons could do nothing, so they are not shown. */
.mr-theme { display: inline-flex; border: 1px solid var(--mr-control-border); border-radius: var(--mr-radius); overflow: hidden; background: var(--mr-surface); }
@media (scripting: none) { .mr-theme { display: none; } }
.mr-theme button {
  display: grid; place-items: center; width: 2rem; height: 1.875rem; padding: 0; border: 0; border-radius: 0;
  background: transparent; color: var(--mr-text-2); font-size: .9375rem; line-height: 1;
}
.mr-theme button + button { border-left: 1px solid var(--mr-border-strong); }
.mr-theme button:hover { background: var(--mr-surface-2); color: var(--mr-text-strong); }
.mr-theme button[aria-pressed="true"] { background: var(--mr-surface-3); color: var(--mr-accent-text); box-shadow: inset 0 -2px 0 var(--mr-accent-mark); }
.mr-theme button:focus-visible { outline-offset: -2px; }

/* Tap targets: 44px on phones and touch screens. */
@media (pointer: coarse), (max-width: 575.98px) {
  .mr-fold > summary { min-height: 2.75rem; }
  .btn-mr { --bs-btn-padding-y: .5rem; --bs-btn-padding-x: .875rem; min-height: 2.75rem; }
  .mr-theme button { width: 2.75rem; height: 2.75rem; }  /* hub has 2.5rem (40px): below 44px, fix there too */
  .mr-brand { min-height: 2.75rem; }
}

/* ---------- Brand -------------------------------------------------------- */
.mr-brand { display: inline-flex; align-items: center; gap: .625rem; color: var(--mr-text-strong); text-decoration: none; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.mr-brand:hover { color: var(--mr-text-strong); }
/* Mark: a 2x2 annunciator panel with one lamp lit. Inline SVG, inherits colour. */
.mr-brand__mark {
  display: grid; place-items: center; width: 1.625rem; height: 1.625rem;
  background: var(--mr-accent-mark); color: #fff; border-radius: var(--mr-radius-sm);
}
.mr-brand__svg { width: 1rem; height: 1rem; display: block; }

/* ---------- Form controls ------------------------------------------------ */
.mr-field { display: grid; gap: .25rem; min-width: 0; }
.mr-field > label { font-size: var(--mr-fs-meta); color: var(--mr-text-2); font-weight: 500; }
.mr-input, .mr-select {
  display: block; width: 100%; height: 2.25rem; padding: 0 .75rem;
  background-color: var(--mr-surface-2); color: var(--mr-text);
  border: 1px solid var(--mr-control-border); border-radius: var(--mr-radius);
  font: inherit; font-size: var(--mr-fs-body);
}
.mr-input::placeholder { color: var(--mr-text-muted); opacity: 1; }
.mr-input:focus, .mr-select:focus {
  outline: none; border-color: var(--mr-focus); background-color: var(--mr-surface);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mr-focus) 35%, transparent);
}
/* The chevron is two gradients so it follows the text colour in light and dark;
   Bootstrap's own is a fixed-colour data: image that disappears on a dark surface. */
.mr-select {
  appearance: none; -webkit-appearance: none; padding-right: 2rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--mr-text-2) 50%), linear-gradient(135deg, var(--mr-text-2) 50%, transparent 50%);
  background-position: calc(100% - 1.0625rem) 50%, calc(100% - .75rem) 50%;
  background-size: .3125rem .3125rem, .3125rem .3125rem;
  background-repeat: no-repeat;
}
@media (pointer: coarse), (max-width: 575.98px) { .mr-input, .mr-select { height: 2.75rem; font-size: 1rem; } }

.mr-search { position: relative; min-width: 0; }
.mr-search__ico { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--mr-text-muted); pointer-events: none; font-size: .875rem; }
.mr-search .mr-input { padding-left: 2.25rem; }

/* ---------- Panels ------------------------------------------------------- */
.mr-panel { background: var(--mr-surface); border: 1px solid var(--mr-border); border-radius: var(--mr-radius-lg); min-width: 0; }
.mr-panel__bar { display: flex; align-items: center; gap: .625rem; padding: .5rem .75rem; border-bottom: 1px solid var(--mr-border); background: var(--mr-surface-2); border-radius: var(--mr-radius-lg) var(--mr-radius-lg) 0 0; }
.mr-panel__bar h2, .mr-panel__bar h3 { display: inline-flex; align-items: center; gap: .5rem; }
.mr-panel__bar a { display: inline-flex; align-items: center; min-height: 1.5rem; }
.mr-panel__body { padding: .875rem .75rem; display: grid; gap: .75rem; }
.mr-count {
  display: inline-grid; place-items: center; min-width: 1.375rem; padding: 0 .375rem; height: 1.25rem;
  border-radius: var(--mr-radius-sm); background: var(--mr-surface-3); color: var(--mr-text-strong);
  font-family: var(--mr-font-mono); font-size: var(--mr-fs-label); font-weight: 600;
}

/* Native collapse: <details class="mr-fold"><summary>..</summary>..</details> */
.mr-fold > summary { list-style: none; cursor: pointer; }
.mr-fold > summary::-webkit-details-marker { display: none; }
.mr-fold > summary .mr-chev { display: inline-block; transition: transform .12s ease; color: var(--mr-text-muted); }
.mr-fold[open] > summary .mr-chev { transform: rotate(90deg); }
.mr-fold > summary:hover { background: var(--mr-surface-2); }
@media (prefers-reduced-motion: reduce) { .mr-fold > summary .mr-chev { transition: none; } }

/* ---------- Notices (Django messages) ------------------------------------ */
.mr-notice {
  display: flex; align-items: flex-start; gap: .625rem; padding: .625rem .75rem;
  border: 1px solid var(--st-bd); border-radius: var(--mr-radius); background: var(--st-bg);
  color: var(--mr-text); font-size: var(--mr-fs-dense);
}
.mr-notice > .bi { color: var(--st-fg); margin-top: .125rem; font-size: 1rem; }

/* ---------- Data tables -------------------------------------------------- */
/* Real <table>s in a container-query wrapper. Secondary columns carry .mr-wide and appear when
   the wrapper is wide enough; below that their content moves under the primary cell as .mr-narrow. */
.mr-tablewrap { container-type: inline-size; container-name: tbl; position: relative; overflow-x: auto; overflow-y: hidden; }
.mr-table { width: 100%; border-collapse: collapse; font-size: var(--mr-fs-dense); }
.mr-table th {
  padding: .375rem .75rem; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--mr-border);
  font-family: var(--mr-font-mono); font-size: var(--mr-fs-label); font-weight: 500;
  letter-spacing: var(--mr-tracking-label); text-transform: uppercase; color: var(--mr-text-muted);
}
.mr-table td { padding: .5rem .75rem; vertical-align: top; border-bottom: 1px solid var(--mr-border); }
.mr-table tbody tr:last-child td { border-bottom: 0; }
.mr-table tbody tr:hover { background: var(--mr-surface-2); }
.mr-table .mr-r { text-align: right; }
.mr-table .mr-wide { display: none; }
.mr-table .mr-sub { display: block; margin-top: .125rem; font-size: var(--mr-fs-meta); color: var(--mr-text-2); }
@container tbl (min-width: 560px) {
  .mr-table .mr-wide { display: table-cell; }
  .mr-table .mr-narrow { display: none; }
}

/* ---------- Single-value meter -------------------------------------------
   <svg class="mr-meter" viewBox="0 0 100 4" preserveAspectRatio="none"><rect width="46.4" .../></svg>
   Built by {% usage_bar %}. The fill width is an SVG attribute, not a style="" attribute, so it
   passes a strict style-src. */
.mr-meter { display: block; width: 100%; height: .375rem; border-radius: var(--mr-mark-radius); background: var(--mr-track); overflow: hidden; }
.mr-meter rect { fill: var(--mr-accent-mark); }
.mr-meter[data-state="warn"] rect { fill: var(--mr-degraded-solid); }

/* ---------- Tally (counts) ----------------------------------------------- */
.mr-tally { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
.mr-tally li { display: inline-flex; align-items: baseline; gap: .375rem; font-size: var(--mr-fs-dense); color: var(--mr-text-2); }
.mr-tally .bi { color: var(--mr-text-muted); align-self: center; }
.mr-tally b { font-family: var(--mr-font-mono); font-size: var(--mr-fs-body); color: var(--mr-text-strong); font-weight: 600; }
