/* Admin console (web/screens/admin.js) - 4.0, T5-017 / R-026 / R-044.

   Screen-specific layout only. Every colour, radius, font and control surface
   comes from web/css/tokens.css + web/css/components.css (.card, .card-head,
   .card-flat, .seg.views, .btn, .iconbtn, .field, .tag, .list-more, .eyebrow);
   the Health view reuses web/css/more.css's `.more-stale`, `.more-health*` and
   `.more-events*` rules on purpose - it is the 3.1 More > Health card verbatim.
   Load order (web/index.html): tokens -> components -> shell -> per-screen, this
   file among the 4.0 screens that load last, so a rule here may override
   shell.css and components.css, never the other way round. Every var() used
   here is defined in tokens.css (tests/test_web.py).

   In-page rules are scoped to `#admin-body`. The sheets (actions, confirmations,
   the link result) render in #sheet-root, outside it, so their classes carry
   the `admin-` prefix and are unscoped.

   Layout ladder:
     <560      the six view tabs wrap, three per row; lists are STACKED rows (name
               and flags on the first line, the figures under them with their
               labels); tiles two across; one column.
     560-767   the tabs sit on one row; still stacked rows.
     >=768     lists become a GRID with a header row (the per-row labels hide);
               tiles three across; card pairs two across (.grid-2).
     320       no horizontal scroll anywhere: every flex/grid child that holds
               text has min-width 0 and wraps anywhere. */

/* ---------- stack ---------- */

#admin-body .admin-pane { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) { #admin-body .admin-pane { gap: 16px; } }
#admin-body .admin-grid { align-items: start; gap: 12px; }
@media (min-width: 768px) { #admin-body .admin-grid { gap: 16px; } }
/* A grid item's automatic minimum width is its min-content, and a card holding a
   nowrap row (the events fold's `.more-event-row`) would widen the `1fr` track
   past a 320px phone - the same "grid blowout" more.css guards with `.more-col`. */
#admin-body .admin-grid > * { min-width: 0; }

/* The view tabs: six segments. Below 560px they wrap three per row so no label
   is clipped at 320px; the control keeps its own 16px bottom margin. */
#admin-body .admin-tabs .seg.views { flex-wrap: wrap; margin-bottom: 12px; }
#admin-body .admin-tabs .seg.views button { flex: 1 1 calc(33.333% - 4px); padding-left: 6px; padding-right: 6px; }
@media (min-width: 560px) {
  #admin-body .admin-tabs .seg.views { flex-wrap: nowrap; }
  #admin-body .admin-tabs .seg.views button { flex: 1 1 0; }
}
@media (min-width: 768px) {
  #admin-body .admin-tabs .seg.views { margin-bottom: 16px; }
  #admin-body .admin-tabs .seg.views button { flex: none; padding-left: 18px; padding-right: 18px; }
}

/* ---------- notices ---------- */

#admin-body .admin-stale { color: var(--warn); font-size: 12px; }
#admin-body .admin-server-stale { margin-bottom: 8px; }
#admin-body .admin-note { padding: 0 2px; }
#admin-body .admin-banner {
  padding: 10px 12px; border-radius: 12px;
  background: var(--warn-soft); color: var(--ink); font-size: 13px; line-height: 1.4;
}
#admin-body .admin-count { margin-top: 8px; }
#admin-body .admin-error { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
#admin-body .admin-error .error-text { margin-top: 0; }

/* ---------- overview tiles ---------- */

#admin-body .admin-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 768px) { #admin-body .admin-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }

#admin-body .admin-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 96px; width: 100%; min-width: 0;
  border: 1px solid transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
#admin-body .admin-tile:hover { border-color: var(--line-2); }
#admin-body .admin-tile-value { font-size: 28px; line-height: 1.1; overflow-wrap: anywhere; }
#admin-body .admin-tile-sub { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
#admin-body .admin-tile-sub:empty { display: none; }

/* A tile is a slot: the tile button and, for the poll tile, an info tip that is its SIBLING (a
   <details> cannot live inside a <button>). The tip's "i" sits in the tile's top-right corner and
   its note spans the tile's width below it (T5-030c SA9). */
#admin-body .admin-tile-slot { position: relative; display: flex; min-width: 0; }
#admin-body .admin-tile-slot > .admin-tile { flex: 1 1 auto; }
#admin-body .admin-tile-slot.has-tip > .admin-tile { padding-right: 40px; }
#admin-body .admin-tile-slot > .info-tip { position: static; width: 0; }
#admin-body .admin-tile-slot > .info-tip > summary { position: absolute; top: 10px; right: 10px; margin: 0; }
#admin-body .admin-tile-slot .info-tip-note { left: 0; right: 0; width: auto; max-width: none; }

#admin-body .admin-policy .seg { display: flex; width: 100%; }
#admin-body .admin-policy .seg button { flex: 1 1 0; min-width: 0; justify-content: center; }
#admin-body .admin-policy-note { margin-top: 8px; }
#admin-body .admin-policy-error,
#admin-body .admin-invite-error { margin-top: 8px; }

#admin-body .admin-invite-form { display: flex; flex-wrap: wrap; gap: 8px; }
#admin-body .admin-invite-form .field { flex: 1 1 180px; }
@media (max-width: 420px) {
  #admin-body .admin-invite-form .btn { flex: 1 1 100%; }
}

/* ---------- toolbars ---------- */

#admin-body .admin-toolbar { display: flex; align-items: center; gap: 8px; }
#admin-body .admin-toolbar .field { flex: 1; }
@media (min-width: 768px) {
  #admin-body .admin-toolbar .field { max-width: 380px; }
  #admin-body .admin-toolbar .admin-select { max-width: 260px; }
}

/* ---------- lists: stacked rows on a phone, a grid from 768px ---------- */

#admin-body .admin-listbox { min-width: 0; }

#admin-body .admin-list {
  background: var(--s1); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
}
#admin-body .admin-list > * { border-top: 1px solid var(--line); }
#admin-body .admin-list > *:first-child { border-top: 0; }

#admin-body .admin-head-row { display: none; }

#admin-body .admin-row {
  position: relative;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  width: 100%; min-width: 0; min-height: 56px;
  padding: 12px 40px 12px 14px;
  background: transparent; border: 0; border-radius: 0;
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
#admin-body .admin-row:hover { background: var(--s2); }
#admin-body .admin-row:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

#admin-body .admin-line { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 14px; min-width: 0; }
#admin-body .admin-line:first-of-type { flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; }

#admin-body .admin-cell { min-width: 0; }
#admin-body .admin-main { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; }
#admin-body .admin-name { font-weight: 800; overflow-wrap: anywhere; }
#admin-body .admin-sub { font-size: 12px; overflow-wrap: anywhere; }
#admin-body .admin-flags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; flex: 0 1 auto; max-width: 62%; }
#admin-body .admin-meta { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
#admin-body .admin-cell-label { color: var(--ink-3); margin-right: 4px; }
#admin-body .admin-notes { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; }
#admin-body .admin-notes:empty { display: none; }
#admin-body .admin-note-err { color: var(--bad); overflow-wrap: anywhere; }

#admin-body .admin-go {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  display: inline-flex; color: var(--ink-3);
}

/* Status pills reuse components.css `.tag` (uppercase 11px, 22px tall). */
#admin-body .admin-tag.gold { background: var(--gold-soft); color: var(--gold); }
#admin-body .admin-tag.good { background: var(--good-soft); color: var(--good); }
#admin-body .admin-tag.bad { background: var(--bad-soft); color: var(--bad); }
#admin-body .admin-tag.warn { background: var(--warn-soft); color: var(--warn); }
#admin-body .admin-tag { max-width: 100%; height: auto; min-height: 22px; white-space: normal; text-align: center; line-height: 1.25; padding-top: 2px; padding-bottom: 2px; }

/* The grid from 768px. The column templates are written out per list (no local custom
   property: every var() in web/** must be defined in tokens.css, tests/test_web.py).
   The header row and every data row of one list share ONE template. */
@media (min-width: 768px) {
  #admin-body .admin-users .admin-head-row,
  #admin-body .admin-users .admin-row {
    grid-template-columns: minmax(0, 2.4fr) minmax(0, 1.3fr) 76px 110px 24px;
  }
  #admin-body .admin-players .admin-head-row,
  #admin-body .admin-players .admin-row {
    grid-template-columns: minmax(0, 1.5fr) 118px 84px 84px 96px minmax(0, 1.9fr) 24px;
  }
  #admin-body .admin-outbox .admin-head-row,
  #admin-body .admin-outbox .admin-row {
    grid-template-columns: minmax(0, 2.1fr) minmax(0, 1.4fr) 90px 76px minmax(0, 1.5fr) 24px;
  }

  #admin-body .admin-head-row {
    display: grid; gap: 12px; align-items: end;
    padding: 0 16px 6px;
    font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
  }
  #admin-body .admin-row {
    display: grid; align-items: center; gap: 12px;
    padding: 10px 16px; min-height: 52px;
  }
  /* The two stacked lines dissolve into the grid: their cells become columns. */
  #admin-body .admin-line,
  #admin-body .admin-line:first-of-type { display: contents; }
  #admin-body .admin-flags { justify-content: flex-start; max-width: none; }
  /* An empty Notes cell stays a (blank) grid cell: hiding it would pull the chevron
     into the Notes column and break the column alignment of the rows below. */
  #admin-body .admin-notes:empty { display: block; }
  #admin-body .admin-cell-label { display: none; }
  #admin-body .admin-meta { font-size: 13px; }
  #admin-body .admin-go { position: static; transform: none; order: 99; justify-self: end; }
}

/* ---------- outbox rows ---------- */

#admin-body .admin-mail-head[aria-expanded="true"] .admin-go { transform: translateY(-50%) rotate(180deg); }
@media (min-width: 768px) {
  #admin-body .admin-mail-head[aria-expanded="true"] .admin-go { transform: rotate(180deg); }
}
#admin-body .admin-mail-detail {
  display: flex; flex-direction: column; gap: 10px;
  padding: 4px 14px 14px; background: var(--s1);
}
#admin-body .admin-mail-text {
  margin: 0; padding: 10px 12px; max-height: 300px; overflow: auto;
  background: var(--s2); border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; line-height: 1.5;
  color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere;
}
#admin-body .admin-mail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#admin-body .admin-mail-detail .admin-facts { max-width: 520px; }
#admin-body .admin-link-state { overflow-wrap: anywhere; }
#admin-body .admin-copy-note:empty { display: none; }

/* ---------- health ---------- */

#admin-body .admin-server .admin-section + .admin-section { margin-top: 14px; }
#admin-body .admin-server .admin-section { display: flex; flex-direction: column; gap: 4px; }
#admin-body .admin-section-title { margin: 0 0 4px; }
#admin-body .admin-server .more-health-row { align-items: baseline; }
#admin-body .admin-server .more-health-row > span:first-child { flex: none; }
#admin-body .admin-server .more-health-row > span:last-child { min-width: 0; text-align: right; overflow-wrap: anywhere; }
/* A row with an info tip (Tracking > Effective rate, PRM-F4): the tip sits between the label and the value
   (the auto margin keeps the value on the right). Like a card head's tip, its note hangs from the ROW - the
   row is the positioned box, the tip itself is static - so it never leaves the card. The button keeps the
   40px hit area (components.css) but gives the height back, so the row is no taller than its neighbours. */
#admin-body .admin-server .more-health-row.has-tip { position: relative; align-items: center; }
#admin-body .admin-server .more-health-row.has-tip > .info-tip { position: static; margin-right: auto; }
#admin-body .admin-server .more-health-row.has-tip > .info-tip > summary { margin: -12px -4px; }
#admin-body .admin-server .more-health-row.has-tip .info-tip-note { left: 0; right: 0; width: auto; max-width: none; }
@media (min-width: 768px) {
  #admin-body .admin-server .more-health-row.has-tip .info-tip-note { left: auto; width: min(340px, 100%); }
}
/* The Health card itself (`.more-health-card`) is NOT restyled here: it is the 3.1
   More card verbatim and keeps more.css's rules. */

/* ---------- settings form ---------- */

#admin-body .admin-form { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) { #admin-body .admin-form { gap: 16px; } }
#admin-body .admin-field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
#admin-body .admin-field:first-of-type { margin-top: 4px; }
#admin-body .admin-field-label { font-weight: 700; font-size: 13px; color: var(--ink); }
#admin-body .admin-field .field { flex: none; width: 100%; }
#admin-body .admin-field-help { line-height: 1.4; }
#admin-body .admin-field-error { margin-top: 0; overflow-wrap: anywhere; }
#admin-body .admin-field .field[aria-invalid="true"] { border-color: var(--bad); }
#admin-body .admin-form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#admin-body .admin-form-actions .btn:disabled { opacity: .45; cursor: default; }
#admin-body .admin-form-error { margin-top: 0; }

/* ---------- sheets (rendered in #sheet-root) ---------- */

.admin-lede { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }

.admin-facts {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px;
  margin: 0; font-size: 13px;
}
.admin-facts dt { white-space: nowrap; }
.admin-facts dd { margin: 0; overflow-wrap: anywhere; text-align: right; }

.admin-actions { display: flex; flex-direction: column; }
.admin-action {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; min-height: 56px; padding: 10px 0;
  background: transparent; border: 0; border-top: 1px solid var(--line);
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.admin-actions .admin-action:first-child { border-top: 0; }
.admin-action:hover .admin-action-title { color: var(--gold); }
.admin-action:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.admin-action-title { font-weight: 800; font-size: 15px; }
.admin-action-desc { font-size: 12px; line-height: 1.35; color: var(--ink-3); overflow-wrap: anywhere; }
.admin-action.danger .admin-action-title { color: var(--bad); }
.is-busy .admin-action { opacity: .55; pointer-events: none; }

.admin-sheet-error { margin-top: 0; overflow-wrap: anywhere; }
.admin-sheet-error:empty { display: none; }

.admin-limit-form { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.admin-limit-row { display: flex; gap: 8px; }
.admin-limit-row .field { flex: 1; }

.admin-confirm-label { display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.admin-confirm-label .field { flex: none; width: 100%; }

.admin-link-field {
  flex: none; width: 100%;
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px;
}
.admin-valid { line-height: 1.4; }
.admin-copy-note:empty { display: none; }

/* The confirm button is the shared `.btn.danger` (components.css, T5-030c); only the disabled look is here. */
.admin-danger-btn:disabled { opacity: .45; cursor: default; }
