/* =====================================================================
   The backend as a spreadsheet (admin pages, the workout builder, the master workout grid). Loaded after console.css.
   One rule for the whole layer: hairlines and square corners, no boxes inside boxes. A "card" becomes a ruled section under a grey
   header band (like the header row of the builder's table); a row of tiles becomes one ruled strip; pills become square tags and tabs.
   Scoped by what is on the page, so the members' pages keep their look.
   ===================================================================== */
body:is(:has(.admin-bar), :has(.builder-modal), :has(.wg)) {
  --sh-line: var(--line-strong, var(--color-rule-2));
  --sh-hair: var(--line, var(--color-rule));
  --sh-band: var(--surface-2, var(--color-paper-2));
  --sh-bg: var(--color-paper, var(--surface));
  /* Hover is the blue outline only; no fill change. (--sh-lift is the fill, kept transparent so every hover rule leaves the colour alone.) */
  --sh-lift: transparent;
}

/* ---------- Sections: .panel and its relatives lose the box, gain a header band ---------- */
body:has(.admin-bar) :is(.panel, .card-form, .form-card, .empty-state, .stat-tile, .notice, .flash) { border-radius: 0; box-shadow: none; }
body:has(.admin-bar) .panel,
body:has(.admin-bar) .card-form,
body:has(.admin-bar) .form-card { padding: 0; background: transparent; border: 1px solid var(--sh-line); margin-bottom: var(--space-md); }
body:has(.admin-bar) .panel > :not(.panel-head):not(table):not(.table-scroll):not(.table-wrap):not(.check-list):not(ul):not(ol) { margin-inline: var(--space-md); }
body:has(.admin-bar) .panel > :is(p, .hint, .muted, form, .field, .admin-form, fieldset, dl, div):not(.panel-head):not(.table-scroll):not(.table-wrap) { margin-inline: var(--space-md); }
body:has(.admin-bar) .panel > :last-child:not(table):not(.table-scroll):not(.table-wrap) { margin-bottom: var(--space-md); }
body:has(.admin-bar) .panel > :first-child:not(.panel-head):not(table):not(.table-scroll):not(.table-wrap) { margin-top: var(--space-md); }
body:has(.admin-bar) .panel-head { margin: 0 0 var(--space-md); padding: 0 var(--space-md); min-height: 36px; align-items: center; background: var(--sh-band); border-bottom: 1px solid var(--sh-line); }
body:has(.admin-bar) .panel-head h2 { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.02em; color: var(--ink-muted, var(--color-muted)); }
body:has(.admin-bar) .panel-sub { font-size: 0.74rem; }
body:has(.admin-bar) .panel > .table-scroll, body:has(.admin-bar) .panel > .table-wrap { margin: 0; }
body:has(.admin-bar) .admin-grid { gap: var(--space-md); }
/* Plain cards (guidance notes and the like) keep their padding but become ruled boxes */
body:has(.admin-bar) .wb-main :is(.card, .access-code-big) { border-radius: 0; box-shadow: none; border: 1px solid var(--sh-line); background: transparent; }

/* A panel that is only a table or a list: the table's own header row is the band */
body:has(.admin-bar) .panel > .panel-head + .table-scroll, body:has(.admin-bar) .panel > .panel-head + .table-wrap { margin-top: calc(var(--space-md) * -1); }

/* ---------- Stat tiles: one ruled strip ---------- */
body:has(.admin-bar) .stat-row { display: flex; flex-wrap: wrap; gap: 0; overflow: hidden; border: 1px solid var(--sh-line); background: transparent; }
body:has(.admin-bar) .stat-tile { flex: 1 1 150px; margin: 0 -1px -1px 0; background: transparent; border: 0; border-right: 1px solid var(--sh-hair); border-bottom: 1px solid var(--sh-hair); padding: var(--space-md); }
body:has(.admin-bar) .stat-label { font-size: 0.72rem; font-weight: 700; color: var(--ink-muted, var(--color-muted)); }

/* ---------- Notices and flash messages: a ruled strip with a coloured left edge ---------- */
body:has(.admin-bar) :is(.notice, .flash) { background: var(--sh-band); border: 1px solid var(--sh-line); border-left-width: 3px; padding: var(--space-sm) var(--space-md); }
body:has(.admin-bar) .notice-warning { border-left-color: var(--color-accent); background: var(--sh-band); color: var(--ink, var(--color-ink)); }
body:has(.admin-bar) .flash.error { border-left-color: var(--color-bad, var(--color-accent)); }
body:has(.admin-bar) .empty-state { background: transparent; border: 1px dashed var(--sh-line); }

/* ---------- Check list (setup checklist): rows with hairlines, a square mark ---------- */
body:has(.admin-bar) .check-list { margin: 0; padding: 0; list-style: none; }
body:has(.admin-bar) .check-list li { padding: var(--space-sm) var(--space-md); border-top: 1px solid var(--sh-hair); }
body:has(.admin-bar) .check-list li:first-child { border-top: 0; }
body:has(.admin-bar) .check-mark { border-radius: 0; }

/* ---------- The admin bar: a tab strip, not a pill ---------- */
body:has(.admin-bar) .admin-bar { gap: 0; padding: 0; border-radius: 0; background: transparent; box-shadow: none; width: auto; border-bottom: 1px solid var(--sh-line); }
body:has(.admin-bar) .admin-bar a { border-radius: 0; padding: var(--space-sm) var(--space-md); margin-bottom: -1px; border-bottom: 2px solid transparent; background: transparent; }
body:has(.admin-bar) .admin-bar a:hover { background: color-mix(in srgb, var(--ink, #fff) 6%, transparent); }
body:has(.admin-bar) .admin-bar a.active { background: transparent; color: var(--ink, var(--color-ink)); border-bottom-color: var(--color-accent); }
body:has(.admin-bar) .admin-bar-title { padding-left: 0; }

/* ---------- Tables: hairline grid, grey header, square ---------- */
body:has(.admin-bar) :is(.admin-table, .leaderboard, .data-table) { border-collapse: collapse; border-radius: 0; }
body:has(.admin-bar) :is(.admin-table, .leaderboard, .data-table) :is(th, td) { border: 1px solid var(--sh-hair); }
body:has(.admin-bar) :is(.admin-table, .leaderboard, .data-table) th { background: var(--sh-band); font-size: 0.72rem; font-weight: 700; color: var(--ink-muted, var(--color-muted)); }
body:has(.admin-bar) .panel > .table-scroll > table, body:has(.admin-bar) .panel > table { border-left: 0; border-right: 0; }
/* Hover: a blue outline and the faintest blue tint. Never a lighter grey, which washes the dark rows out. */
body:has(.admin-bar) :is(.admin-table, .leaderboard) tbody tr:hover { outline: 1px solid var(--color-accent); outline-offset: -1px; }
body:has(.admin-bar) :is(.admin-table, .leaderboard) tbody tr:hover :is(td, .lb-player, .lb-actions, .lb-rank) { background: linear-gradient(var(--sh-lift), var(--sh-lift)), var(--sh-bg); }
body:has(.admin-bar) .admin-table tr.is-pending:hover td { background: var(--sh-lift); }
body:has(.admin-bar) .icon-btn-round { border-radius: 0; width: 30px; height: 30px; }
body:has(.admin-bar) .admin-photo { border-radius: 0; box-shadow: none; border: 1px solid var(--sh-line); }

/* ---------- Controls: square fields and buttons, tags instead of pills ---------- */
body:is(:has(.admin-bar), :has(.builder-modal)) :is(.btn, .btn-sm, .btn-lg) { border-radius: 4px; }
body:has(.admin-bar) .field :is(input[type=text], input[type=number], input[type=search], input[type=password], input[type=email], input[type=url], input[type=date], textarea, select) { border-radius: 0; background: var(--sh-bg); border: 1px solid var(--sh-hair); box-shadow: none; }
body:has(.admin-bar) .field :is(input, textarea, select):focus { outline: 2px solid var(--color-accent); outline-offset: -2px; border-color: var(--color-accent); background: var(--color-accent-soft); }
body:has(.admin-bar) .wb-main :is(input:not([type=checkbox], [type=radio], [type=range], [type=file]), select, textarea) { border-radius: 0; }
body:has(.admin-bar) .wb-main :is(fieldset, .lb-scroll, .table-scroll, .table-wrap) { border-radius: 0; }
body:has(.admin-bar) .wb-main fieldset.field { border: 1px solid var(--sh-hair); padding: var(--space-md); }
body:has(.admin-bar) .wb-main fieldset.field > legend { padding: 0 var(--space-xs); font-size: 0.74rem; font-weight: 700; color: var(--ink-muted, var(--color-muted)); }
body:has(.admin-bar) .lb-scroll { border: 1px solid var(--sh-line); }
body:has(.admin-bar) :is(.pill, .division-badge, .filter-pill, .badge, .chip) { border-radius: 3px; }
body:has(.admin-bar) .admin-bar .admin-pending { border-radius: 3px; }

/* ---------- The master workout grid: it already is a sheet; square off the last rounded bits ---------- */
.wg-wrap { border-radius: 0; border-color: var(--wg-line); }
.wg-chip, .wg-pill { border-radius: 3px; }
.wg-flash { border-radius: 0; box-shadow: none; }
.wg-img img, .wg-img .wg-noimg { border-radius: 0; }

/* ---------- The workout builder ---------- */
/* Type switch: two square cells in a ruled box, not a pill */
.builder-body .workout-type-choice { border-radius: 0; border: 1px solid var(--sh-line); }
.builder-body .type-option + .type-option { border-left: 1px solid var(--sh-line); }

/* The table's footer is a row of the sheet: "+ Add another drill" spans the full width, attached to the last row */
.builder-table { margin-bottom: 0; }
body.wb .builder-modal .builder-table + .add-drill-btn.btn { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; margin: 0; border: 1px solid var(--sh-line); border-top: 0; border-radius: 0; background: var(--sh-band); color: var(--ink-muted, var(--color-muted)); font-weight: 600; box-shadow: none; }
body.wb .builder-modal .builder-table + .add-drill-btn.btn:hover, body.wb .builder-modal .builder-table + .add-drill-btn.btn:focus-visible { background: linear-gradient(var(--sh-lift), var(--sh-lift)), var(--sh-band); color: var(--ink, var(--color-ink)); outline: 1px solid var(--color-accent); outline-offset: -1px; }
.builder-table + .add-drill-btn + .hint { margin-top: var(--space-xs); }
.builder-table .drag-handle { border-radius: 0; }

/* A drill row on hover: blue outline, faint tint (the old grey-white tint made the dark rows too light) */
.builder-table .exercise-row:hover { outline: 1px solid var(--color-accent); outline-offset: -1px; }
.builder-table .exercise-row:hover td { background: var(--sh-lift); }
.builder-table .exercise-row.is-dragging td { background: color-mix(in srgb, var(--color-accent) 10%, var(--sh-bg)); }
.builder-more .suggest-item:hover { background: var(--sh-lift); outline: 1px solid var(--color-accent); outline-offset: -1px; }

.builder-table .drag-handle:hover, .builder-table .drag-handle:focus-visible, .builder-modal .builder-table .drag-handle:hover { background: var(--sh-lift); outline: 1px solid var(--color-accent); outline-offset: -1px; }
.builder-table .cell-remove .icon-btn.remove:hover, .builder-table .cell-remove .icon-btn.remove:focus-visible, .builder-modal .builder-table .cell-remove .icon-btn.remove:hover { background: var(--sh-lift); outline: 1px solid var(--color-accent); outline-offset: -1px; }

/* Everything else that used to lighten on hover in these pages (picker options, secondary buttons, close buttons): same blue outline, faint blue tint */
body:is(:has(.admin-bar), :has(.builder-modal)) :is(.video-picker-option, .tag-picker-option, .playlist-result, .builder-x):hover,
body:is(:has(.admin-bar), :has(.builder-modal)) .builder-x:focus-visible { background: var(--sh-lift); outline: 1px solid var(--color-accent); outline-offset: -1px; }
body:is(:has(.admin-bar), :has(.builder-modal)) .btn-secondary:is(:hover, :focus-visible) { background: var(--sh-lift) !important; color: var(--ink, var(--color-ink)) !important; outline: 1px solid var(--color-accent); outline-offset: -1px; border-color: transparent; }

/* Copy + remove share the last cell, side by side. Copy adds a duplicate of the row right below it (handy for HIIT rounds). */
.builder-table .col-remove { width: 92px; }
.builder-table .cell-remove { display: table-cell; white-space: nowrap; }
.builder-table .cell-remove .icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 48px; vertical-align: middle; }
.builder-table .cell-remove .icon-btn.copy { color: var(--ink-muted, var(--color-muted)); }
.builder-table .cell-remove .icon-btn.copy:hover, .builder-table .cell-remove .icon-btn.copy:focus-visible { color: var(--ink, var(--color-ink)); background: var(--sh-lift); outline: 1px solid var(--color-accent); outline-offset: -1px; }
.builder-table .cell-remove .icon-btn .icon { width: 22px; height: 22px; }
.builder-table .cell-remove .icon-btn.remove { font-size: 2.1rem; font-weight: 300; line-height: 1; padding: 0 0 4px; }

/* Superset cell: the checkbox never shrinks or sits on the text, and the column is wide enough for "with the one above" */
.builder-table.is-list .col-superset { width: 200px; }
.builder-table .superset-toggle { white-space: nowrap; gap: var(--space-sm); }
.builder-table .superset-toggle input { flex: none; width: 18px; height: 18px; margin: 0; }
.builder-modal .builder-table .cell-remove .icon-btn { width: 44px; height: 48px; min-height: 48px; }
.builder-table .exercise-row.is-new td { background: color-mix(in srgb, var(--color-accent) 16%, transparent); transition: background 0.9s ease; }

/* More details: a ruled section whose summary is a header band, and its fields sit flat inside it */
.builder-more { margin-top: var(--space-lg); padding: 0; border: 1px solid var(--sh-line); border-radius: 0; background: transparent; }
.builder-more > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--space-sm); padding-block: var(--space-xs); min-height: 44px; padding: 0 var(--space-md); background: var(--sh-band); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.02em; }
.builder-more > summary::after { float: none; margin-top: 0; }
.builder-more > summary small { display: inline; margin: 0; font-size: 0.74rem; font-weight: 400; }
.builder-more[open] > summary { border-bottom: 1px solid var(--sh-line); }
.builder-more[open] { padding-bottom: 0; }
.builder-more > :not(summary) { margin-inline: var(--space-md); }
.builder-more > .status-field { margin-top: var(--space-md); }
.builder-more > :last-child { margin-bottom: var(--space-md); }
.builder-more :is(input[type=text], input[type=number], input[type=search], textarea, select) { border-radius: 0; }
.builder-more input[type=file] { border-radius: 0; }
.builder-more .suggest-list { border-radius: 0; border-color: var(--sh-line); }
.builder-more .suggest-item { padding: var(--space-xs) var(--space-md); min-height: 40px; }
.builder-more img { border-radius: 0 !important; }

/* On a phone the rows are stacked sheets: square, one ruled box each, no corner radii */
@media (max-width: 820px) {
  .builder-table .exercise-row:hover td { background: var(--color-paper, var(--surface)); }
  .builder-table .cell-video { grid-column: 3 / span 7; }
  .builder-table .cell-remove { grid-column: 10 / span 3; display: flex; align-items: stretch; justify-content: stretch; }
  .builder-table .cell-remove .icon-btn, .builder-modal .builder-table .cell-remove .icon-btn { flex: 1 1 0; width: auto; height: auto; min-height: 48px; }
  .builder-table td.cell-superset[data-label]::before { display: none; }
  .builder-table td.cell-superset[data-label] { padding-top: 0; }
  .builder-table tr.exercise-row { border-radius: 0; }
  .builder-table .cell-handle, .builder-table .cell-remove { border-radius: 0 !important; }
  .builder-table .video-picker-panel { border-radius: 0; }
}

/* HIIT builder: two fixed rows, a red one for work and a green one for rest; they are not reordered, copied or removed */
.builder-table.is-hiit .drag-handle, .builder-table.is-hiit .cell-remove > * { display: none; }
.builder-table.is-hiit .hiit-role { font-weight: 700; margin-bottom: var(--space-xs); }
.builder-table.is-hiit .is-work .hiit-role { color: var(--color-bad); }
.builder-table.is-hiit .is-rest .hiit-role { color: var(--color-ok); }
.builder-table.is-hiit .is-work td:first-child { box-shadow: inset 4px 0 0 var(--color-bad); }
.builder-table.is-hiit .is-rest td:first-child { box-shadow: inset 4px 0 0 var(--color-ok); }
.builder-total { margin: var(--space-sm) 0 0; font-weight: 600; color: var(--ink-muted, var(--color-muted)); }
.builder-total:empty { display: none; }
