/* Backends view (#889, story #882): the relayed monitor of every linked backend. Dark theme via base.css tokens;
   the gauge bars reuse .usage-line / .usage-bar / .usage-fill of dashboard.css. LF line endings. */

.backends-view {
  height: 100%;
  overflow-y: auto;
  padding: 16px 20px 32px;
}
/* mounted on #view-root itself, whose `overflow: hidden` (an id rule) would otherwise win */
#view-root.backends-view { overflow-y: auto; }

.backends-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.backends-title { margin: 0; font-size: 15px; font-weight: 600; }
.backends-asof { margin-left: auto; color: var(--muted); font-size: 12px; }
.bk-modes { display: inline-flex; gap: 4px; }
.bk-mode[aria-pressed="true"] { background: var(--panel-2); border-color: var(--muted-2); color: var(--text); }

.bk-group { margin-bottom: 18px; }
.bk-group-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bk-items-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.bk-items-list { display: flex; flex-direction: column; gap: 6px; }

.bk-item {
  position: relative; /* anchors the runner pop-ups */
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.bk-item.current { border-color: var(--muted-2); }
.bk-panel { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; }

.bk-head { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.bk-name { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.bk-title { font-weight: 600; overflow-wrap: anywhere; }
.bk-repo, .bk-here { color: var(--muted); font-size: 11px; }
.bk-here { text-transform: lowercase; }
.bk-state {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.bk-state.tone-ok { color: var(--ok); }
.bk-state.tone-warn { color: var(--warn); }
.bk-state.tone-danger { color: var(--danger); }
.bk-state.tone-muted { color: var(--muted); }

.bk-counts { display: flex; gap: 14px; flex-wrap: wrap; }
.bk-count { display: inline-flex; align-items: baseline; gap: 5px; }
.bk-count-label { color: var(--muted); font-size: 11px; }
.bk-count-value { font-weight: 600; font-variant-numeric: tabular-nums; }

.bk-runners { display: flex; gap: 4px 8px; flex-wrap: wrap; align-items: center; }
/* a runner chip (#907): the badge once, then the mini usage; the full gauges are in its pop-up */
.bk-runner { display: inline-flex; align-items: center; gap: 6px; padding: 1px 4px; border-radius: var(--radius); }
.bk-runner.has-usage { cursor: help; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.bk-runner.has-usage:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.bk-runner.has-usage.open { background: var(--panel-2); }
@media (hover: hover) { .bk-runner.has-usage:hover { background: var(--panel-2); } }
.bk-mini { display: inline-flex; flex-direction: column; gap: 3px; }
.bk-mini-gauge { display: flex; align-items: center; gap: 4px; line-height: 1; }
.bk-mini-bar { --tone: var(--accent); width: 26px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--tone) 22%, transparent); overflow: hidden; }
.bk-mini-bar.tone-warn { --tone: var(--warn); }
.bk-mini-bar.tone-danger { --tone: var(--danger); }
.bk-mini-fill { display: block; height: 100%; background: var(--tone); }
.bk-mini-pct { min-width: 3ch; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.bk-mini-unknown { color: var(--muted-2); font-size: 12px; font-weight: 600; }

/* the pop-up (hover or keyboard focus on desktop, tap or long press on touch): under the backend's panel or row, as wide as it allows */
.bk-pop {
  display: none;
  position: absolute;
  left: 8px;
  top: calc(100% - 4px);
  z-index: 30;
  width: min(380px, calc(100% - 16px));
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  color: var(--text);
  cursor: default;
  user-select: text;
  -webkit-user-select: text;
}
.bk-pop::before { content: ""; position: absolute; left: 0; right: 0; top: -14px; height: 14px; } /* keeps the hover over the gap */
.bk-runner.has-usage:focus-visible .bk-pop, .bk-runner.has-usage.open .bk-pop { display: flex; }
@media (hover: hover) { .bk-runner.has-usage:hover .bk-pop { display: flex; } }
.bk-usage { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bk-usage-account { color: var(--muted); font-size: 11px; font-weight: 600; }
.bk-gauges { display: flex; flex-direction: column; gap: 6px; }
.bk-burn { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 0 8px; }
.bk-burn-unit { font-style: italic; }
.bk-gauge .usage-line { flex-wrap: wrap; }
.bk-gauge .usage-resets { margin-left: 0; }
.bk-muted, .bk-note { color: var(--muted); font-size: 12px; }
.bk-signin { font-size: 12px; }

/* offline: the registry row only, greyed (like the project switcher's offline entries) */
.bk-item.bk-offline { opacity: 0.55; }

/* a click opens the backend (#907): the same switch as the project switcher, so only a backend that can be switched to shows it */
.bk-item.bk-go { cursor: pointer; }
.bk-item.bk-go:hover { border-color: var(--muted-2); }
.bk-item.bk-go:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

/* list view (#907): one or two lines per backend. Line 1: name and state chip, the Human Action badge and the counts;
   the runner chips follow on the same line when they fit, else they take line 2 */
.bk-list { display: flex; align-items: center; gap: 2px 16px; flex-wrap: wrap; padding: 6px 12px; }
.bk-list .bk-head { flex: 1 1 250px; flex-wrap: nowrap; }
.bk-list .bk-name { flex: 0 1 auto; flex-direction: row; align-items: baseline; gap: 8px; overflow: hidden; white-space: nowrap; }
.bk-list .bk-title { overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
.bk-list .bk-counts { flex: 0 0 auto; gap: 12px; flex-wrap: nowrap; }
.bk-list .bk-runners { flex: 0 1 auto; }
.bk-list .bk-note { margin-left: auto; }
@media (max-width: 640px) {
  .bk-list .bk-head { flex-basis: 100%; }
  .bk-list .bk-counts { gap: 10px; }
}

/* Forget (#969) and Log out (#1006): the controls of the view, at the end of the head line; a touch-sized target at a phone's width */
.bk-forget, .bk-logout { flex: 0 0 auto; }
.bk-logout-error { font-size: 12px; color: var(--danger); }
@media (max-width: 600px) {
  .bk-forget, .bk-logout { min-height: 32px; padding-inline: 12px; }
}
