/* Monitoring pages: overview, servers, players, errors, logs, traces, metrics, games home.
   Tokens only (see docs/FRONTEND.md); shared components (.stat, .player-cell, .tone-*) live in app.css. */

.mspark { display: block; }

.meter { display: grid; gap: 4px; min-width: 76px; }
.meter .bar { height: 4px; }

/* filter bar above tables */
.filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.filters .search { min-width: 200px; flex: 1; max-width: 360px; }
.filters .search input { width: 100%; }
/* saved views and Export close the filter row on the right (tabs → [search][segmented][selects] … [views][Export]) */
.filters > .views-bar, .filters > .views-bar.no-views { flex: 0 1 auto; margin-left: auto; justify-content: flex-end; }
/* chips come from the kit (.chips / .chip / .chip.on); only monitor-specific modifiers live here */
button.chip { appearance: none; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.chip .chip-x { all: unset; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-right: calc(-1 * var(--sp-1)); border-radius: 50%; color: var(--muted); cursor: pointer;
  transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.chip .chip-x svg { width: 12px; height: 12px; }
.chip .chip-x:hover, .chip .chip-x:focus-visible { background: var(--hover); color: var(--text); }

/* page header with identity + stats (server / player / error detail) */
.detail-head { display: flex; gap: var(--gap); align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.detail-head .who { display: flex; gap: var(--sp-3); align-items: center; min-width: 0; }
.detail-head h1 { overflow-wrap: anywhere; }
.detail-head h1.jobid-title { font-size: var(--fs-4); color: var(--text-strong); }
.detail-head .sub { color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); align-items: center; }

.online-pill { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-2); color: var(--ok); }
.online-pill .dot { box-shadow: 0 0 0 3px var(--ok-bg); }

.jobid { font-family: var(--mono); font-size: var(--fs-2); color: var(--text-2); white-space: nowrap; }
/* server detail title: the full job id on wide screens, the tap-to-copy short id on phones */
.jobid-title .short-id { display: none; }
@media (max-width: 760px) {
  .jobid-title .jobid-full, .jobid-row > .btn { display: none; }
  .jobid-title .short-id { display: inline-flex; font-size: var(--fs-4); font-weight: 600; color: var(--text-strong); }
}
/* fleet cards: id + version on the first line is enough; the type/place line is for the wide table */
.srv-cell .srv-sub { white-space: nowrap; }   /* "Public · place 1001" never breaks at 1024 */
@container tcards (max-width: 640px) { .srv-cell .srv-sub { display: none; } }

/* stack traces */
pre.code.stack { white-space: pre-wrap; word-break: break-word; }
pre.code.stack .frame { padding: 1px 0; }
pre.code.stack .path { color: var(--accent-2); }
pre.code.stack .ln { color: var(--warn); }
pre.code.stack .rest { color: var(--muted); }
.err-title { font-family: var(--mono); font-size: var(--fs-4); line-height: 1.5; font-weight: 600; overflow-wrap: anywhere; }

.err-row .msg { font-family: var(--mono); font-size: var(--fs-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 640px; display: block; color: var(--text); }
.err-row .meta { color: var(--muted); font-size: var(--fs-1); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* error samples: list chrome comes from the kit .sample-list */
.sample.expandable { cursor: pointer; }

/* bulk action bar */
.bulkbar { position: sticky; top: calc(var(--topbar) + var(--sp-2)); z-index: var(--z-sticky); display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3);
  background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--radius); box-shadow: var(--shadow); animation: rise var(--dur-2) var(--ease-out); }

/* player timeline */
.timeline { padding: 6px var(--pad) var(--sp-3); }
/* sticks below the topbar (top: 0 slid it under the bar) */
.tl-day { font-size: var(--fs-1); font-weight: 600; color: var(--muted); padding: var(--sp-3) 0 var(--sp-1); position: sticky; top: var(--topbar); z-index: 2; background: var(--panel); }
.tl-row { display: grid; grid-template-columns: 64px 14px minmax(0, 1fr); gap: 10px; align-items: baseline; padding: 3px 0; }
/* long script paths in error lines break instead of widening the page (phones) */
.tl-row > div { min-width: 0; overflow-wrap: anywhere; }
.tl-time { font: var(--fs-2) var(--mono); color: var(--faint); white-space: nowrap; }
.tl-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-2); align-self: start; margin-top: .45em; justify-self: center; }
.tl-ic { display: grid; place-items: center; align-self: start; margin-top: .1em; color: var(--accent); }
.tl-ic svg { width: 14px; height: 14px; }
.tl-ic.ok { color: var(--ok); } .tl-ic.warn { color: var(--warn); } .tl-ic.bad { color: var(--bad); }
.tl-dot.ok { background: var(--ok); }
.tl-dot.bad { background: var(--bad); }
.tl-dot.accent { background: var(--accent); }
.tl-dot.warn { background: var(--warn); }

/* daily playtime bars on the player profile */
.daybars .mspark { width: 100%; }
.daybars-axis { display: flex; justify-content: space-between; font-size: var(--fs-1); color: var(--faint); margin-top: 4px; }

/* games home: game cards share the totals row's columns and gap (4 → 2 → 1 with the KPI tiles' 4 → 4 → 2),
   so their edges line up; a card's stats sit 2 × 2 until the card is wide enough for one row of four */
.home-games { gap: var(--sp-3); }
.home-card { container-type: inline-size; }
.home-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: var(--sp-3); gap: var(--sp-2) var(--sp-3); }
@container (min-width: 340px) { .home-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* log stream: the logs page is a viewport-tall flex column; the stream card takes the remaining height */
/* a definite height (not min-height), so the flex chain below can hand the stream exactly the leftover space */
.page.logs-page { height: calc(100dvh - var(--topbar) - 2 * var(--content-pad)); min-height: 640px; }
.logs-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.logs-card > .card-b, .logs-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.logs-filters { padding: var(--pad) var(--pad) 0; }
.logs-stream { position: relative; flex: 1; min-height: 320px; display: flex; flex-direction: column; }
.logstream { position: relative; /* contains absolutely positioned bits (sr-only labels) so they scroll with it */ flex: 1; min-height: 0; height: 0; overflow-y: auto; overscroll-behavior: contain; background: var(--bg-2); border-top: 1px solid var(--border); }
.logstream .logline { grid-template-columns: 150px 54px minmax(0, 1fr); }
.logstream .logline .ts { color: var(--faint); white-space: nowrap; }
.logstream .logline.new { animation: row-in var(--dur-3) var(--ease); }
.logstream .logline .srv { color: var(--faint); font-size: var(--fs-1); margin-left: 8px; }
.logstream mark { background: var(--warn-bg); color: var(--text-strong); border-radius: calc(var(--radius-s) / 3); padding: 0 1px; }
.tail-state { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-2); color: var(--muted); }
.tail-resume { position: absolute; left: 50%; bottom: var(--sp-4); transform: translateX(-50%); }

/* traces */
.waterfall { padding: 4px 0; }
.waterfall .wf-row { cursor: default; border-radius: var(--radius-s); padding: 3px 6px; transition: background-color var(--dur-1) var(--ease); }
.waterfall .wf-row:hover, .waterfall .wf-row.on { background: var(--panel-2); }
.waterfall .wf-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.waterfall .wf-name { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.waterfall .wf-axis { display: grid; grid-template-columns: 260px 1fr 80px; gap: 10px; font-size: var(--fs-1); color: var(--faint); padding: 0 6px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.waterfall .wf-axis .ticks { display: flex; justify-content: space-between; }
.dist { display: flex; align-items: flex-end; gap: 2px; height: 90px; padding-top: 6px; }
.dist i { flex: 1; background: var(--accent); opacity: .75; border-radius: calc(var(--radius-s) / 3) calc(var(--radius-s) / 3) 0 0; min-height: 1px; transition: opacity var(--dur-1) var(--ease); }
.dist i:hover { opacity: 1; }

/* metric builder */
.builder { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
/* kit .list / .list-item, two lines per metric (name, then kind · unit · series) */
.metric-list { max-height: calc(100dvh - 200px); overflow-y: auto; padding: 0 var(--sp-1) var(--sp-1); }
/* the list scrolls as a flex column: items must not shrink, or the name above the meta line collapses to zero height */
.metric-list .list-item { flex: none; height: auto; flex-direction: column; align-items: stretch; gap: 2px; padding: 6px 10px; }
.metric-list .list-item > .ellipsis { flex: none; }
.metric-list .list-item .meta { margin-left: 0; }
.tag-filter { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tag-filter .chip { cursor: default; }

.badge svg { width: 11px; height: 11px; }

@media (max-width: 1000px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .metric-list { max-height: 260px; }
  .waterfall .wf-axis { grid-template-columns: 120px 1fr 60px; }
}
@media (max-width: 760px) {
  .filters .search { min-width: 0; max-width: none; flex-basis: 100%; }
  /* filter rows stay one line each: chip sets scroll sideways instead of stacking four rows above the data */
  .filters > .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .filters > .chips::-webkit-scrollbar { display: none; }
  .filters > .chips > .chip { flex: none; }
  .srv-filters > .btn-group, .srv-filters > select { order: -1; }
  /* log lines: time + level on one line, message below */
  .logstream .logline { grid-template-columns: auto auto minmax(0, 1fr); row-gap: 2px; column-gap: 8px; }
  .logstream .logline .msg { grid-column: 1 / -1; }
  .err-row .msg { max-width: 70vw; }
  .tl-row { grid-template-columns: 56px 14px minmax(0, 1fr); gap: var(--sp-2); }
  .tl-time { font-size: var(--fs-1); }
  .detail-head .who .avatar.xl { width: 48px; height: 48px; }
}

/* a table cell that takes the remaining width and truncates instead of pushing other columns off-card */

.tl-count { margin-left: var(--sp-2); font-size: var(--fs-1); font-weight: 600; color: var(--muted); background: var(--hover); border-radius: 999px; padding: 1px 7px; }
.tl-more { padding: var(--sp-1) var(--pad) var(--sp-3); }
.tl-more:empty { display: none; }
.t td.fill .err-row { min-width: 0; }
.t td.fill .err-row .msg { max-width: 100%; }
.t td.fill .err-row .meta { overflow: hidden; }
.t td.fill .err-row .meta > .mono { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Errors as cards (phones / narrow panels): the message gets two lines, the meta line wraps */
@container tcards (max-width: 640px) {
  .t-cards .t td[data-card="title"] .err-row .msg { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; max-width: none; overflow-wrap: anywhere; }
  .t-cards .t td[data-card="title"] .err-row .meta { white-space: normal; }
}

/* row selection + floating bulk-action bar (liveTable select / bulkBar) */
.t th.sel-col, .t td.sel-col { width: 32px; padding-right: 0; }
.sel-col input { display: block; margin: 0; cursor: pointer; }
/* liveTable order freeze: rows hold still under the pointer / a menu / a selection; the pill applies the sort */
.live-table { position: relative; }
.resort-pill { position: absolute; z-index: 2; top: 3px; right: var(--sp-2); display: inline-flex; align-items: center; gap: var(--sp-1); height: 24px; padding: 0 var(--sp-2) 0 6px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 85%, var(--accent)); color: var(--accent-2); font: 600 var(--fs-1)/1 var(--font); cursor: pointer; box-shadow: var(--shadow-1); animation: pop-in var(--dur-2) var(--ease-out); }
.resort-pill[hidden] { display: none; }
.resort-pill svg { width: 12px; height: 12px; }
.resort-pill:hover { background: color-mix(in srgb, var(--panel) 75%, var(--accent)); }
@media (pointer: coarse) { .resort-pill { height: 32px; padding: 0 var(--sp-3) 0 var(--sp-2); } }
.t tbody tr.row-gone { opacity: .45; transition: opacity var(--dur-2) var(--ease); }
.bulkbar.float { position: fixed; top: auto; left: 50%; bottom: calc(var(--sp-5) + var(--safe-b, 0px)); transform: translateX(-50%); z-index: var(--z-sticky);
  /* max-content: a left:50% box would otherwise shrink to half the viewport and wrap its buttons */
  width: max-content; margin: 0; max-width: calc(100vw - 2 * var(--sp-4)); gap: var(--sp-2); padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); background: var(--panel); flex-wrap: wrap; justify-content: center; animation: bulk-in var(--dur-2) var(--ease-out); }
.bulkbar.float[hidden] { display: none; }
.bulkbar.float.leaving { animation: fade-out var(--dur-1) var(--ease) forwards; }
.bulkbar-n { font-size: var(--fs-2); font-weight: 600; white-space: nowrap; margin-right: var(--sp-2); }
.bulkbar-acts { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
@keyframes fade-out { to { opacity: 0; } }
@keyframes bulk-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (prefers-reduced-motion: reduce) { .bulkbar.float, .bulkbar.float.leaving { animation: none; } }
.undo-toast { display: flex; align-items: center; gap: var(--sp-3); }
.undo-toast > span { flex: 1; }
@media (max-width: 640px) {
  .bulkbar.float { left: var(--sp-4); right: var(--sp-4); width: auto; transform: none; max-width: none; flex-wrap: nowrap; justify-content: flex-start; padding-left: var(--sp-3); animation-name: rise; }
  .bulkbar.float .bulkbar-acts { flex: 1; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .bulkbar.float .bulkbar-acts .btn { flex: none; }
}
/* in cards the usage meter sits on the stat line: number, then a short bar */
@container tcards (max-width: 640px) {
  .t-cards .meter { grid-template-columns: auto 44px; align-items: center; gap: 6px; min-width: 0; }
}
