:root {
  /** Shared by squad panel and pitch so they stay the same height; pitch width = 1.5 × this. */
  --squad-pitch-h: min(57.6vh, 419px);
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: #388bfd66;
  --pitch: #1a3d2e;
  --pitch-line: #ffffff22;
  --home-team: #f85149;
  --away-team: #a371f7;
  --success: #3fb950;
  --warning: #d29922;
  /** Pitch slot selection: neutral frost (not accent blue — reads with pitch + subs). */
  --slot-selected-edge: color-mix(in srgb, var(--text) 74%, transparent);
  --slot-selected-glow: color-mix(in srgb, var(--text) 12%, transparent);
  /** Keyboard focus on controls — same edge + glow as selected pitch tiles. */
  --focus-ring-edge: var(--slot-selected-edge);
  --focus-ring-glow: var(--slot-selected-glow);
}

body.theme-light {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-hover: #eef3f9;
  --border: #cfd8e3;
  --text: #111827;
  --muted: #5f6b79;
  --accent: #0b73ff;
  --accent-dim: #0b73ff33;
  --pitch: #1a3d2e;
  --pitch-line: #ffffff66;
  --home-team: #d9363e;
  --away-team: #6f42c1;
  --success: #22863a;
  --warning: #b58105;
  --slot-selected-edge: color-mix(in srgb, var(--text) 58%, transparent);
  --slot-selected-glow: color-mix(in srgb, var(--text) 10%, transparent);
}

@supports not (color: color-mix(in srgb, white 50%, black)) {
  :root {
    --slot-selected-edge: rgba(230, 237, 243, 0.74);
    --slot-selected-glow: rgba(230, 237, 243, 0.12);
  }
  body.theme-light {
    --slot-selected-edge: rgba(17, 24, 39, 0.58);
    --slot-selected-glow: rgba(17, 24, 39, 0.1);
  }
}

/* Light mode fixes for places that used hardcoded white text/overlays. */
body.theme-light .header-team-label {
  color: var(--muted);
}

body.theme-light .pitch-team-code,
body.theme-light .formation-on-pitch .formation-select {
  background: #ffffffde;
  color: var(--text);
  border-color: var(--border);
}

body.theme-light .roster-sublabel,
body.theme-light .team-squad .roster-sublabel,
body.theme-light .team-squad .roster-label,
body.theme-light .team-squad .chip,
body.theme-light .team-squad .chip .chip-num,
body.theme-light .team-squad .team-title,
body.theme-light .team-squad .formation-select {
  color: var(--text);
}

body.theme-light .team-squad .chip small,
body.theme-light .team-squad .sub-hint {
  color: var(--muted);
}

body.theme-light .slot .name {
  color: var(--text);
}

body.theme-light .slot-card-times {
  background: #00000020;
  color: var(--text);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/**
 * Focus rings: match `.slot.selected` — neutral edge + soft outer glow (not browser blue).
 * Buttons / selects: full tile-style outer rings.
 * Text inputs / textareas: border takes the “edge” so we only add the glow outside — avoids Chromium
 * painting the stacked outer 1px shadow tight against text inside the field.
 */
button:focus-visible,
.btn:focus-visible,
select:focus-visible,
summary:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px var(--focus-ring-edge), 0 0 0 3px var(--focus-ring-glow);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(
    [type="color"]
  ):not([type="hidden"]):focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--focus-ring-edge);
  box-shadow: 0 0 0 3px var(--focus-ring-glow);
}

button::-moz-focus-inner {
  border: 0;
}

/* Themed scrollbars — match app surfaces/borders (respects body.theme-light vars). */
:is(
    html,
    .pitch-column,
    .modal-library-body,
    .library-table-scroll,
    .roster-scroll,
    .player-panel .player-panel-body,
    .panel-body,
    .notes-list
  ) {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-hover) var(--surface);
}

:is(
    html,
    .pitch-column,
    .modal-library-body,
    .library-table-scroll,
    .roster-scroll,
    .player-panel .player-panel-body,
    .panel-body,
    .notes-list
  )::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

:is(
    html,
    .pitch-column,
    .modal-library-body,
    .library-table-scroll,
    .roster-scroll,
    .player-panel .player-panel-body,
    .panel-body,
    .notes-list
  )::-webkit-scrollbar-track {
  background: var(--surface);
  border-radius: 8px;
}

:is(
    html,
    .pitch-column,
    .modal-library-body,
    .library-table-scroll,
    .roster-scroll,
    .player-panel .player-panel-body,
    .panel-body,
    .notes-list
  )::-webkit-scrollbar-thumb {
  background: var(--surface-hover);
  border-radius: 8px;
  border: 2px solid var(--surface);
}

:is(
    html,
    .pitch-column,
    .modal-library-body,
    .library-table-scroll,
    .roster-scroll,
    .player-panel .player-panel-body,
    .panel-body,
    .notes-list
  )::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

:is(
    html,
    .pitch-column,
    .modal-library-body,
    .library-table-scroll,
    .roster-scroll,
    .player-panel .player-panel-body,
    .panel-body,
    .notes-list
  )::-webkit-scrollbar-corner {
  background: var(--surface);
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 1.25rem;
  min-height: 2.75rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.app-header-panel {
  padding: 0.45rem 1rem;
  border-top: 1px solid transparent;
}

.app-header--collapsed .app-header-panel {
  display: none;
}

.app-header--collapsed {
  border-bottom-color: var(--border);
}

.header-toggle {
  flex-shrink: 0;
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.85rem;
}

.match-clock-display {
  font-variant-numeric: tabular-nums;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  color: var(--text);
}

.btn-match-clock {
  padding: 0.2rem 0.5rem;
  font-size: 0.74rem;
}

.header-team-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.header-profile-row {
  flex: 1 0 100%;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem 0.75rem;
}

.header-profile-row-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.85rem;
  min-width: 0;
}

.header-profile-row-end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

@media (min-width: 900px) {
  .header-profile-row {
    width: auto;
  }
}

.header-team-controls-home {
  padding-top: 0.05rem;
}

.header-team-controls-away {
  padding-top: 0.05rem;
}

/** Full-width bar between home and away pitch columns (clock + change side). */
.team-block:has(+ .pitch-between-zone) {
  margin-bottom: 0;
}

.pitch-between-zone {
  width: 100%;
  margin: 0.45rem 0;
  padding: 0.2rem 0.45rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.app-header .pitch-between-zone {
  margin: 0;
  border-left: none;
  border-right: none;
  border-radius: 0;
}

.pitch-between-zone-inner {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-width: 0;
  min-height: 2rem;
}

/* Equal flex + max-width keeps side bands from covering the true centre. */
.pitch-between-left,
.pitch-between-right {
  flex: 1 1 0;
  min-width: 0;
  max-width: 46%;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.pitch-between-left {
  justify-content: flex-start;
  flex-wrap: wrap;
  row-gap: 0.2rem;
}

.pitch-between-right {
  justify-content: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
}

/*
 * Clock row: keep the numeric time at the true horizontal centre of the bar.
 * Logging + match Start sit immediately left of the time; Set clock right.
 * pointer-events: wrappers pass clicks through so left/right header columns stay usable underneath.
 */
.pitch-between-center {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  pointer-events: none;
}

.pitch-between-center-before,
.pitch-between-center-after {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  width: 100%;
  pointer-events: none;
}

.pitch-between-center-before {
  justify-content: flex-end;
}

.pitch-between-center-after {
  justify-content: flex-start;
}

.pitch-between-center .match-clock-display,
.pitch-between-center button {
  pointer-events: auto;
}

@media (max-width: 720px) {
  .pitch-between-zone {
    overflow-x: auto;
  }
}

.btn-match-aux {
  padding: 0.16rem 0.38rem;
  font-size: 0.68rem;
}

.header-team-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-team-controls .club-select {
  min-width: 130px;
  font-size: 0.8rem;
}

.header-team-controls .header-league-select {
  min-width: 150px;
}

.header-btn {
  padding: 0.28rem 0.55rem;
}

.header-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Match log: single toggle — recording state = red + soft ring pulse. */
.header-btn.header-btn--match-log-toggle.header-btn--logging {
  background: linear-gradient(180deg, #b91c1c 0%, #991b1b 100%);
  border-color: #f87171;
  color: #fff;
  box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.55);
  animation: match-log-rec-pulse 1.75s ease-out infinite;
}

.header-btn.header-btn--match-log-toggle.header-btn--logging:disabled {
  opacity: 1;
  cursor: default;
}

@keyframes match-log-rec-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.5);
  }
  65% {
    box-shadow: 0 0 0 7px rgba(248, 113, 113, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .header-btn.header-btn--match-log-toggle.header-btn--logging {
    animation: none;
    box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.65);
  }
}

body.theme-light .header-btn.header-btn--match-log-toggle.header-btn--logging {
  background: linear-gradient(180deg, #dc2626 0%, #b91c1c 100%);
  border-color: #fecaca;
  color: #fff;
}

.layout {
  display: block;
  min-height: calc(100vh - 48px);
}

.pitch-column {
  padding: 0.7rem;
  overflow: auto;
}

.team-block {
  margin-bottom: 0.8rem;
}

.team-block:last-child {
  margin-bottom: 0;
}

.teams-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  align-items: start;
}

.teams-split .team-block {
  margin-bottom: 0;
  order: 0;
}

.teams-split.teams-split--swapped .team-block:nth-child(1) {
  order: 2;
}

.teams-split.teams-split--swapped .team-block:nth-child(2) {
  order: 1;
}

.squad-club-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem 0.5rem;
  flex-shrink: 0;
  margin-bottom: 0.5rem;
}

.club-select-label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.club-select-caption {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.75);
}

.team-squad .club-select {
  width: 100%;
  min-width: 0;
  font-size: 0.78rem;
  padding: 0.28rem 0.45rem;
}

.squad-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  flex-shrink: 0;
  margin-bottom: 0.45rem;
}

.squad-top-row .team-title {
  min-width: 0;
}

.formation-label {
  flex-shrink: 0;
}

.team-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "pitch pitch"
    "squad panel";
  gap: 0.7rem;
  align-items: stretch;
}

/* Settings → panel order: squad + stats row above full-width pitch (both team columns). */
body.panel-order--stats-first .team-body {
  grid-template-areas:
    "squad panel"
    "pitch pitch";
}

@media (max-width: 1320px) {
  .teams-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .team-body {
    grid-template-columns: 1fr;
    grid-template-areas:
      "pitch"
      "squad"
      "panel";
  }

  body.panel-order--stats-first .team-body {
    grid-template-areas:
      "squad"
      "panel"
      "pitch";
  }
}

.team-pitch {
  position: relative;
  grid-area: pitch;
}

.pitch-top-tools {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.pitch-team-code {
  min-width: 2.1rem;
  height: 1.65rem;
  text-align: center;
  padding: 0 0.32rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d1117d9;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.pitch-team-code:empty {
  display: none;
}

.formation-on-pitch {
  position: static;
}

.formation-on-pitch .formation-select {
  min-width: 84px;
  height: 1.65rem;
  box-sizing: border-box;
  font-size: 0.72rem;
  padding: 0 0.32rem;
  background: #0d1117d9;
}

.team-squad {
  grid-area: squad;
}

.player-panel {
  grid-area: panel;
}

.team-squad {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.45rem 0.55rem;
  height: var(--squad-pitch-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #fff;
}

.squad-two-cols {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.5rem;
}

.squad-coach-row {
  margin-top: 0.35rem;
}

.squad-bottom-row {
  margin-top: 0.45rem;
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.roster-single {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.roster-single .chip {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.squad-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.roster-sublabel {
  margin: 0 0 0.22rem;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgba(255, 255, 255, 0.92);
}

.team-squad .roster-sublabel {
  color: rgba(255, 255, 255, 0.92);
}

.roster-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  padding-right: 2px;
}

.roster-scroll .chip {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.team-squad .roster-label {
  color: #fff;
}

.team-squad .chip {
  color: #fff;
}

.team-squad .chip .chip-num {
  color: #fff;
}

.team-squad .chip small {
  color: rgba(255, 255, 255, 0.88);
}

.team-squad .chip.on-field {
  opacity: 1;
}

.team-squad .sub-hint {
  color: rgba(255, 255, 255, 0.9);
}

.team-squad .team-title {
  color: #fff;
}

.team-squad .formation-select {
  background: var(--bg);
  color: #fff;
  border-color: var(--border);
}

.team-pitch {
  height: var(--squad-pitch-h);
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
}

.team-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
}

.formation-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.26rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.pitch-wrap {
  position: relative;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--pitch);
  height: var(--squad-pitch-h);
  width: min(calc(var(--squad-pitch-h) * 1.78), 100%);
  max-height: var(--squad-pitch-h);
  box-sizing: border-box;
  margin: 0 auto;
  flex-shrink: 0;
}

/* Field graphics + tiles (controls like formation stay outside on .pitch-wrap). */
.pitch-graphics {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
}

.pitch-graphics .slots-layer {
  pointer-events: auto;
}

/* Handball: same card size as football (wide rectangle); blue pitch on wrap. */
html[data-active-sport="handball"] .pitch-wrap {
  background: linear-gradient(180deg, #3d8ad4 0%, #1e4a7a 100%);
  width: min(calc(var(--squad-pitch-h) * 1.78), 100%);
  height: var(--squad-pitch-h);
  max-height: var(--squad-pitch-h);
  max-width: 100%;
}

/*
 * Live handball team pitches: graphics fill the card (20×20 SVG + meet scales inside wide box).
 */
html[data-active-sport="handball"] .pitch-wrap:not(.formation-creator-pitch) .pitch-graphics {
  --pitch-line: rgba(255, 255, 255, 0.9);
  inset: 0;
  width: 100%;
  height: auto;
  transform: none;
  border-radius: inherit;
}

html[data-active-sport="handball"] .pitch-wrap:not(.formation-creator-pitch) .pitch-graphics > .pitch-handball-layer,
html[data-active-sport="handball"] .pitch-wrap:not(.formation-creator-pitch) .pitch-graphics > .slots-layer {
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Lineup uses the half-field coordinate box directly (no scaleY — avoids broken % flex + warped tiles). */

/* Same grid model as football (.formation-creator-pitch): square cells from --fc-grid-size;
   JS sets size from width÷36 and offsets so the bottom row is whole; partial row clips at top. */
html[data-active-sport="handball"] .formation-creator-pitch .pitch-graphics {
  background-image: linear-gradient(to right, #ffffff12 1px, transparent 1px),
    linear-gradient(to bottom, #ffffff12 1px, transparent 1px);
  background-size: var(--fc-grid-size) var(--fc-grid-size);
  background-position: var(--fc-grid-offset-x) var(--fc-grid-offset-y);
  background-color: transparent;
}

/* Hide every football pitch decoration inside the handball field (no midline, no centre circle, no pens). */
html[data-active-sport="handball"] .pitch-wrap .pitch-graphics .pitch-line,
html[data-active-sport="handball"] .pitch-wrap .pitch-graphics .pitch-box {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.pitch-handball-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  display: none;
}

html[data-active-sport="handball"] .pitch-graphics .pitch-handball-layer {
  display: block;
  /* Crop centre-line band from line art only; slots stay full size (clip on .pitch-graphics hid tiles). */
  clip-path: inset(30% 0 0 0);
  -webkit-clip-path: inset(30% 0 0 0);
}

/* Half-court markings: centre line, dashed 9m, solid 6m, 7m + 4m marks (broadcast-style). */
.pitch-handball-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
}

/* viewBox 0 0 20 20 — half-court in metres; 6m/9m = straight in front of goal + quarter arcs (IHF). */
.pitch-hb-line {
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 0.09;
  fill: none;
  stroke-linecap: square;
}

.pitch-hb-arc {
  fill: none;
  stroke: rgba(255, 255, 255, 0.94);
  stroke-width: 0.1;
  stroke-linejoin: round;
}

.pitch-hb-9m {
  stroke-dasharray: 0.28 0.32;
  stroke-linecap: round;
  opacity: 0.9;
}

.pitch-hb-7m,
.pitch-hb-4m {
  stroke-width: 0.085;
}

.pitch-line {
  position: absolute;
  background: var(--pitch-line);
}

.pitch-line.midline {
  width: 2px;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.pitch-box {
  position: absolute;
  border: 1px solid var(--pitch-line);
  border-radius: 2px;
}

.pitch-box.center-circle {
  width: 16%;
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.pitch-box.pen-left,
.pitch-box.pen-right {
  width: 15%;
  height: 48%;
  top: 50%;
  transform: translateY(-50%);
}

.pitch-box.pen-left {
  left: 0;
  border-left: none;
}

.pitch-box.pen-right {
  right: 0;
  border-right: none;
}

.pitch-box.goal-left,
.pitch-box.goal-right {
  width: 6%;
  height: 24%;
  top: 50%;
  transform: translateY(-50%);
}

.pitch-box.goal-left {
  left: 0;
  border-left: none;
}

.pitch-box.goal-right {
  right: 0;
  border-right: none;
}

/* Hide attacking-end boxes (big penalty box + small goal box). */
.pitch-wrap--team-a .pitch-box.pen-right,
.pitch-wrap--team-a .pitch-box.goal-right,
.pitch-wrap--team-b .pitch-box.pen-left,
.pitch-wrap--team-b .pitch-box.goal-left {
  display: none;
}

/* Formation editor uses the same one-direction view (attacking end on the right). */
.formation-creator-pitch .pitch-box.pen-right,
.formation-creator-pitch .pitch-box.goal-right {
  display: none;
}

.slots-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  /* Dynamic safe area set per-team in JS (keeper side gets extra margin). */
  padding: var(--slots-pad-top, 6%) var(--slots-pad-right, 11%) var(--slots-pad-bottom, 6%)
    var(--slots-pad-left, 11%);
}

.slots-layer--edit .slot {
  cursor: move;
}

.slots-layer--edit .slot-empty {
  cursor: move;
}

.slot {
  position: absolute;
  transform: translate(-50%, -50%);
  --slot-w: calc(124px * var(--slot-scale, 1));
  --slot-h: calc(var(--slot-w) * 0.4224);
  width: var(--slot-w);
  height: var(--slot-h);
  border-radius: 8px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: left;
  padding: 0.1rem;
  overflow: hidden;
}

@media (max-width: 1180px) {
  .slot {
    --slot-w: calc(116px * var(--slot-scale, 1));
  }
}

@media (max-width: 720px) {
  .slot {
    --slot-w: calc(108px * var(--slot-scale, 1));
  }
}

.slot:hover {
  background: transparent;
}

.slot.selected {
  border-color: transparent;
  box-shadow: 0 0 0 1px var(--slot-selected-edge), 0 0 0 3px var(--slot-selected-glow);
  z-index: 2;
}

.slot.on-pitch {
  background: transparent;
  color: var(--text);
}

.slot.on-pitch.has-yellow {
  box-shadow: none;
}

.slot.on-pitch.has-yellow.selected {
  box-shadow: 0 0 0 1px var(--slot-selected-edge), 0 0 0 3px var(--slot-selected-glow);
}

.slot.on-pitch.has-yellow .num {
  background: #d29922;
  border-color: #d29922;
  color: #0d1117;
}

.slot.on-pitch.has-red .slot-num-stack .num,
.slot.on-pitch.has-red:not(.has-yellow) .num {
  background: #f85149;
  border-color: #f85149;
  color: #0d1117;
}

.slot.on-pitch.has-red .slot-num-stack {
  border-color: #f85149;
}

.slot-num-btn:has(.slot-num-stack) {
  aspect-ratio: auto;
  min-width: 2.35rem;
  align-self: stretch;
}

.slot-num-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
  overflow: hidden;
  background: var(--bg);
}

.slot-num-stack .num {
  flex: 1 1 auto;
  min-height: 0;
  border: none;
  border-radius: 0;
  font-size: 1.22rem;
}

.slot.on-pitch.has-yellow .slot-num-stack {
  border-color: #d29922;
}

.slot.on-pitch.has-yellow .slot-num-stack .num {
  background: #d29922;
  border-color: #d29922;
  color: #0d1117;
}

.slot-card-times {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.06rem;
  padding: 0.1rem 0.16rem 0.14rem;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  min-height: 1.08rem;
  text-align: center;
  color: var(--text);
  background: #000000b3;
}

.slot-card-time {
  display: block;
  white-space: nowrap;
}

.slot .num {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  font-weight: 600;
  font-size: 1.55rem;
  line-height: 1;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
}

.slot .num.num-with-time {
  flex-direction: column;
  gap: 0.03rem;
  line-height: 1;
  padding: 0.06rem 0.1rem;
}

.slot .num .num-time {
  display: block;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.01em;
  color: inherit;
}

.slot-num-btn > .num {
  min-height: 0;
  width: 100%;
  height: 100%;
}

.slot .num.num-empty {
  font-size: 1.3rem;
  color: var(--muted);
}

.slot .abbr {
  font-size: 0.62rem;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-top,
.slot-empty {
  width: 100%;
  height: 100%;
  color: inherit;
  text-align: left;
  padding: 0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

.slot-empty {
  height: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
}

.slot-empty:hover {
  background: #ffffff14;
}

.slot-num-btn,
.slot-name-btn {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.slot-num-btn {
  width: auto;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  justify-self: start;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot-empty > .num {
  width: auto;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  min-height: 0;
  justify-self: start;
  align-self: stretch;
}

.slot .name {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  margin-top: 0;
  font-size: 0.88rem;
  line-height: 1.1;
  color: var(--text);
  overflow: hidden;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  padding: 0.12rem 0.42rem;
  min-height: 0;
}

.slot .name .name-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Two-row pitch tile layout:
   - Row 1: full-width one-line player name
   - Row 2: number+cards on the left, player position on the right */
.slot-name-btn--top {
  flex: 0 0 40%;
  height: 40%;
  width: 100%;
}

.slot-name-full {
  /* This element also has class `name`, so we override .slot .name below. */
}

.slot .name.slot-name-full {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  margin-top: 0;
  font-size: 0.88rem;
  line-height: 1.1;
  color: var(--text);
  overflow: hidden;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-left: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 0.12rem 0.42rem;
  min-height: 0;
}

.slot-bottom-row {
  flex: 0 0 60%;
  height: 60%;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: stretch;
  overflow: hidden;
}

/* Enforce the same 40/60 split on empty tiles too. */
.slot-empty > .name.slot-name-full {
  flex: 0 0 40%;
  height: 40%;
}

.slot-empty > .slot-bottom-row {
  flex: 0 0 60%;
  height: 60%;
}

.slot.on-pitch .slot-bottom-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.slot-empty > .slot-bottom-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.slot.on-pitch .slot-bottom-row > * {
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}

.slot-data-cell {
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.14rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  padding: 0 0.22rem;
  color: var(--text);
}

.slot-data-cell + .slot-data-cell {
  border-left: none;
}

.slot-data-cell:first-child {
  border-radius: 0 0 0 8px;
}

.slot-data-cell:last-child {
  border-radius: 0 0 8px 0;
}

.slot-data-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background: var(--bg);
  appearance: none;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
}

/* Occupied pitch hovers: after .slot .name.slot-name-full / .slot-data-btn so these backgrounds win in the cascade. */
.slot.on-pitch .slot-bottom-row .slot-data-cell:not(.slot-data-cell-num) {
  cursor: pointer;
}

/* Name highlight: direct hover, or stats row hover (JS toggles .slot--stats-row-hover on .slot).
   Keep border neutral — accent border reads like a thin blue “focus” line on mouseover. */
.slot.on-pitch .slot-name-btn:hover .name.slot-name-full,
.slot.on-pitch.slot--stats-row-hover .slot-name-btn .name.slot-name-full {
  background: var(--surface-hover);
  border-color: var(--border);
}

/* Shirt number = substitution trigger, but keep standard neutral hover styling. */
.slot.on-pitch .slot-data-btn.slot-data-cell-num:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.slot.on-pitch .slot-name-btn:hover,
.slot.on-pitch .slot-data-btn.slot-data-cell-num:hover {
  outline: none;
}

.slot.on-pitch button.slot-name-btn::-moz-focus-inner,
.slot.on-pitch button.slot-data-cell-num::-moz-focus-inner {
  border: 0;
}

.slot.on-pitch .slot-name-btn,
.slot.on-pitch .slot-data-btn.slot-data-cell-num {
  -webkit-tap-highlight-color: transparent;
}

.slot.on-pitch .slot-name-btn:focus,
.slot.on-pitch .slot-name-btn:focus-visible,
.slot.on-pitch .slot-name-btn:focus-within,
.slot.on-pitch .slot-data-btn.slot-data-cell-num:focus,
.slot.on-pitch .slot-data-btn.slot-data-cell-num:focus-visible,
.slot.on-pitch .slot-data-btn.slot-data-cell-num:focus-within {
  outline: none !important;
  box-shadow: none !important;
}

.slot-cell-label {
  font-size: 0.54rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-transform: uppercase;
}

.slot-cell-value {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

.slot-data-cell-num .slot-cell-value {
  font-size: 1rem;
}

.slot-data-cell-yellow.is-active {
  background: #d29922;
  border-color: #d29922;
  color: #0d1117;
}

.slot-data-cell-yellow.is-active .slot-cell-label {
  color: #0d1117cc;
}

.slot-bottom-row .slot-num-stack {
  border-top: none;
  border-right: none;
  border-radius: 0 0 0 8px;
}

.slot-pos-cell {
  min-width: 0;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: none;
  border-top: none;
  border-radius: 0 0 8px 0;
  padding: 0 0.42rem;
  color: var(--text);
}

.slot-pos-text {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.slot-bottom-row .slot-pos-empty {
  opacity: 1;
}



.roster-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.roster-row.roster-col {
  flex-direction: column;
  flex-wrap: nowrap;
  margin-top: 0.5rem;
}

.roster-row.roster-col .chip {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.roster-label {
  width: 100%;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.25rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.28rem 0.46rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.74rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.chip:hover {
  background: var(--surface-hover);
  border-color: var(--muted);
}

.chip.on-field {
  border-color: var(--success);
  opacity: 0.85;
}

.chip.sub-off-candidate {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px #58a6ff2e inset;
}

.chip.sub-selected-off {
  border-color: var(--accent);
  background: #58a6ff22;
}

.chip.sub-on-candidate {
  border-color: #f2cc60;
  box-shadow: 0 0 0 2px #d299222e inset;
}

/** XI teammate to swap with when substitution mode is armed from the pitch (squad list). */
.chip.sub-swap-candidate {
  border-color: var(--success);
  box-shadow: 0 0 0 2px #3fb95044 inset;
  background: #3fb95018;
}

.chip.red-carded {
  background: #f85149;
  border-color: #f85149;
  color: #0d1117;
}

.chip.red-carded small,
.chip.red-carded .chip-num {
  color: #0d1117;
}

.chip.yellow-carded:not(.red-carded) {
  background: #d29922;
  border-color: #d29922;
  color: #0d1117;
}

.chip.yellow-carded:not(.red-carded) small,
.chip.yellow-carded:not(.red-carded) .chip-num {
  color: #0d1117;
}

.chip.bench {
  opacity: 1;
}

.chip .chip-num {
  font-weight: 700;
  color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}

.toolbar.toolbar-col {
  flex-direction: column;
  align-items: stretch;
  flex-shrink: 0;
  margin-top: 0.5rem;
}

.toolbar.toolbar-col .sub-hint {
  margin-top: 0;
}

.team-squad .toolbar.toolbar-col {
  margin-top: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  padding: 0.34rem 0.64rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Kept for markup compatibility — same neutral chrome as .btn (no accent fill). */
.btn-primary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-primary.sub-armed {
  box-shadow: none;
}

.btn-danger {
  border-color: var(--home-team);
  color: var(--home-team);
}

.sub-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.player-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  height: var(--squad-pitch-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.player-panel .player-panel-head {
  padding: 0.65rem 0.75rem 0.5rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.player-panel .player-panel-head h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.player-panel .panel-tabs-bar {
  flex-shrink: 0;
}

.player-panel .panel-tabs {
  padding: 0 0.35rem;
  flex-shrink: 1;
  min-width: 0;
}

.player-panel .player-panel-hero {
  padding: 0.45rem 0.75rem;
  flex-shrink: 0;
}

.player-panel .player-panel-hero:not(:empty) {
  border-bottom: 1px solid var(--border);
}

.player-panel .player-panel-hero:empty {
  display: none;
}

.player-panel .player-panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.45rem 0.55rem;
}

/* Notes tab: single inset so padding is not doubled against .notes-wrap */
.player-panel .player-panel-body:has(.notes-wrap) {
  padding: 0;
}

.panel-league-table-intro-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0 0.45rem;
  min-width: 0;
}

.panel-league-table-intro-row .panel-league-table-intro {
  margin: 0;
  font-size: 0.78rem;
  flex: 1 1 auto;
  min-width: 0;
}

.panel-league-last-five-dots {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.42rem;
  flex: 0 0 auto;
}

.panel-league-last-five-dot {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  flex-shrink: 0;
  box-sizing: border-box;
}

.panel-league-last-five-dot--win {
  background: var(--success);
}

.panel-league-last-five-dot--draw {
  background: var(--warning);
}

.panel-league-last-five-dot--loss {
  background: var(--home-team);
}

.panel-league-last-five-dot--empty {
  background: transparent;
  border: 1px solid var(--muted);
}

.panel-league-table-intro {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
}

.panel-league-table-scroll {
  overflow: auto;
  max-height: min(38vh, 280px);
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.panel-league-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.panel-league-table th,
.panel-league-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.28rem 0.38rem;
  text-align: left;
  vertical-align: middle;
}

.panel-league-table th:nth-child(1),
.panel-league-table td:nth-child(1) {
  width: 1.55rem;
  padding-left: 0.25rem;
  padding-right: 0.2rem;
}

.panel-league-table th:nth-child(2),
.panel-league-table td:nth-child(2) {
  width: auto;
  min-width: 0;
}

.panel-league-table th:nth-child(3),
.panel-league-table td:nth-child(3),
.panel-league-table th:nth-child(4),
.panel-league-table td:nth-child(4),
.panel-league-table th:nth-child(5),
.panel-league-table td:nth-child(5) {
  width: 1.85rem;
  max-width: 2.15rem;
  padding: 0.26rem 0.1rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.panel-league-table th:nth-child(5),
.panel-league-table td:nth-child(5) {
  width: 2rem;
  max-width: 2.35rem;
}

.panel-league-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-hover);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-league-table tbody tr:last-child td {
  border-bottom: none;
}

/* Plain zebra: #1,3,5… darker · #2,4,6… lighter (header stays separate). */
.panel-league-table tbody tr:nth-child(odd) td {
  background: var(--bg);
}

.panel-league-table tbody tr:nth-child(even) td {
  background: var(--surface);
}

.panel-league-table-rank {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* Linked dashboard club: same green as success / Goal controls (zebra unchanged). */
.panel-league-table tbody tr.panel-league-table-row--current td:nth-child(2) {
  color: var(--success);
  font-weight: 600;
}

.panel-tabs-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.panel-player-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  padding: 0.28rem 0.5rem 0.28rem 0.4rem;
  flex: 0 0 auto;
}

.panel-tabs-bar .panel-tabs {
  width: 100%;
  flex: 0 0 auto;
  min-width: 0;
  margin: 0;
  border-top: 1px solid var(--border);
  border-bottom: none;
  padding: 0 0.35rem 0 0.4rem;
}

.panel-card-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  padding: 0;
}

.btn-card-toggle-compact {
  width: auto;
  min-width: 2.35rem;
  padding: 0.22rem 0.42rem;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.btn-panel-goal,
.btn-panel-nogoal {
  min-width: 3.1rem;
  padding-left: 0.32rem;
  padding-right: 0.32rem;
  border-color: var(--border);
  color: var(--text);
}

.btn-panel-goal:hover,
.btn-panel-nogoal:hover {
  border-color: var(--muted);
  background: var(--surface-hover);
}

.btn-panel-nogoal:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-yellow-toggle {
  border-color: #d29922aa;
  color: #f2cc60;
}

.btn-yellow-toggle.active {
  background: #d29922;
  border-color: #d29922;
  color: #0d1117;
}

.btn-red-toggle {
  border-color: #f85149aa;
  color: #ff7b72;
}

.btn-red-toggle.active {
  background: #f85149;
  border-color: #f85149;
  color: #0d1117;
}

/* Improve compact card-toggle contrast in light theme. */
body.theme-light .btn-panel-goal,
body.theme-light .btn-panel-nogoal,
body.theme-light .btn-yellow-toggle,
body.theme-light .btn-red-toggle {
  background: #ffffff;
  border-width: 1px;
}

body.theme-light .btn-panel-goal,
body.theme-light .btn-panel-nogoal {
  border-color: #aeb9c6;
  color: #1f2937;
}

body.theme-light .btn-yellow-toggle {
  border-color: #b58105;
  color: #7a5600;
}

body.theme-light .btn-red-toggle {
  border-color: #d9363e;
  color: #a61b22;
}

body.theme-light .btn-panel-goal:hover,
body.theme-light .btn-panel-nogoal:hover,
body.theme-light .btn-yellow-toggle:hover,
body.theme-light .btn-red-toggle:hover {
  background: #eef3f9;
}

.panel-header {
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.panel-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 0.6rem;
  border-bottom: 1px solid var(--border);
}

.panel-player-bar .panel-player-name {
  flex: 1 1 auto;
  min-width: 0;
  margin-right: auto;
  padding: 0.12rem 0.35rem 0.12rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab {
  padding: 0.44rem 0.68rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--muted);
  border-bottom-color: var(--muted);
}

.panel-body {
  padding: 0.65rem;
  flex: 1;
  overflow-y: auto;
}

.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem 1rem;
}

.player-hero {
  margin-bottom: 1rem;
}

.player-hero .name {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.player-hero .meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.42rem 0.52rem;
}

.stat-card .label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-card .value {
  font-size: 0.96rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.stats-edit-section {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.stats-edit-section .stats-edit-panel {
  display: none;
}

.stats-edit-section.is-open .stats-edit-panel {
  display: block;
}

.stats-edit-section.is-open .stats-edit-open-btn {
  display: none;
}

.stats-edit-section.stats-edit-section--tab {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.stats-edit-section.stats-edit-section--tab .stats-edit-panel {
  display: block;
}

.stats-edit-section.stats-edit-section--tab .stats-edit-open-btn {
  display: none;
}

.stats-edit-open-btn {
  font-size: 0.85rem;
}

.stats-edit-title {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Edit tab: same grid + card chrome as overview stat cards */
.stat-grid--edit {
  margin-bottom: 0.65rem;
}

label.stat-card.stat-card--edit {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  margin: 0;
  cursor: pointer;
  font-weight: inherit;
  color: inherit;
}

.stat-card--edit .stats-edit-input {
  width: 100%;
  min-width: 0;
  margin-top: 0.15rem;
  padding: 0.32rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.3;
  font-family: inherit;
}

.stats-edit-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.stats-save-btn,
.stats-edit-cancel-btn {
  font-size: 0.85rem;
}

.list-plain {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.list-plain li {
  margin-bottom: 0.35rem;
}

.notes-input {
  width: 100%;
  resize: vertical;
  min-height: 90px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.6rem 0.65rem;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.35;
}

.notes-actions {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.45rem;
  justify-content: flex-end;
}

.notes-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  padding: 0.75rem 0.85rem 0.65rem;
}

.notes-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.2rem 0.45rem 0.15rem 0;
}

.notes-list > .empty-state {
  padding: 1.35rem 0.65rem 1.5rem;
  margin: 0;
}

.note-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 3.15rem 0.55rem 0.65rem;
}

.note-card--used {
  outline: 1px solid var(--success);
  outline-offset: 0;
  border-color: color-mix(in srgb, var(--success) 55%, var(--border));
}

.note-card-actions {
  position: absolute;
  top: 0.42rem;
  right: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.28rem;
}

.note-used-toggle {
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--success) 55%, transparent);
  background: transparent;
  color: var(--success);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.note-used-toggle:hover {
  background: color-mix(in srgb, var(--success) 18%, transparent);
}

.note-used-toggle.is-pressed,
.note-used-toggle[aria-pressed="true"] {
  background: var(--success);
  border-color: var(--success);
  color: #0d1117;
}

.note-delete {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 999px;
  border: 1px solid #f85149aa;
  background: transparent;
  color: #f85149;
  font-size: 0.92rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.note-delete:hover {
  background: #f8514922;
}

.note-card p {
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text);
  white-space: pre-wrap;
}

.notes-entry {
  border-top: 1px solid var(--border);
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  padding-right: 0.05rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.ok {
  background: #23863633;
  color: var(--success);
}

.badge.warn {
  background: #bb800926;
  color: var(--warning);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: #000000aa;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Nested confirmations opened while another modal is open (same base z-index stacks by DOM order). */
#modal-formation-delete.modal-backdrop.open,
#modal-formation-category-delete.modal-backdrop.open,
#modal-saved-match-delete.modal-backdrop.open,
#modal-saved-match-load.modal-backdrop.open,
#modal-library-league-delete.modal-backdrop.open,
#modal-library-team-delete.modal-backdrop.open,
#modal-admin-user-delete.modal-backdrop.open {
  z-index: 110;
}

#modal-platform-customer-editor .platform-customer-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
  align-items: start;
}

/* Prep-style section tiles (see prep.html `.prep-section`): thin border + surface fill */
#modal-platform-customer-editor .platform-customer-panel--form,
#modal-platform-customer-editor .platform-customer-panel--members {
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--surface);
  padding: 0.65rem 0.75rem;
  min-width: 0;
  overflow: hidden;
}

#modal-platform-customer-editor .platform-customer-panel--form {
  grid-column: 1;
}

#modal-platform-customer-editor .platform-customer-panel--members {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#modal-platform-customer-editor .platform-customer-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

#modal-platform-customer-editor .platform-customer-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

#modal-platform-customer-editor .platform-customer-field-label {
  display: block;
  white-space: normal;
}

#modal-platform-customer-editor .platform-customer-field-input-wrap .library-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

#modal-platform-customer-editor .platform-customer-members-lede {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
}

/* Same wrapped scrolling list as Test accordion → long list (scroll); slightly taller in this modal. */
#modal-platform-customer-editor .platform-customer-members-long-wrap.test-acc-long-wrap {
  max-height: min(14rem, 40vh);
}

#modal-match-log-review.modal-backdrop.open {
  z-index: 115;
}

/* New match (nested over Matches list) */
#modal-match-create.modal-backdrop.open {
  z-index: 112;
}

#modal-dashboard-message.modal-backdrop.open {
  z-index: 118;
}

/* Teams / Formations / Settings / role shell: anchor to viewport top so inner height changes don’t jump vertically */
#modal-team-library.modal-backdrop,
#modal-formation-creator.modal-backdrop,
#modal-match-log-review.modal-backdrop,
#modal-match-prep.modal-backdrop,
#modal-match-archive-list.modal-backdrop,
#modal-match-create.modal-backdrop,
#modal-platform-shell.modal-backdrop,
#modal-org-shell.modal-backdrop,
#modal-user-settings.modal-backdrop,
#modal-platform-customer-editor.modal-backdrop {
  align-items: flex-start;
  justify-content: center;
  padding-top: max(2rem, env(safe-area-inset-top, 0px));
  padding-right: 2rem;
  padding-bottom: 2rem;
  padding-left: 2rem;
}

#modal-team-library.modal-backdrop .modal.modal-library,
#modal-formation-creator.modal-backdrop .modal.modal-library,
#modal-match-log-review.modal-backdrop .modal.modal-library,
#modal-match-prep.modal-backdrop .modal.modal-library,
#modal-match-archive-list.modal-backdrop .modal.modal-library,
#modal-match-create.modal-backdrop .modal.modal-library,
#modal-platform-shell.modal-backdrop .modal.modal-library,
#modal-org-shell.modal-backdrop .modal.modal-library,
#modal-user-settings.modal-backdrop .modal.modal-library,
#modal-platform-customer-editor.modal-backdrop .modal.modal-library {
  max-height: calc(100dvh - max(2rem, env(safe-area-inset-top, 0px)) - 2rem);
}

.match-create-modal-body .match-create-team-row {
  margin-top: 0.55rem;
}

.match-create-modal-body .match-create-title-row {
  margin-bottom: 0.25rem;
  width: 100%;
  max-width: 100%;
}

.match-create-modal-body .match-create-title-row.library-inline-fields {
  flex-wrap: nowrap;
}

.match-create-modal-body .match-create-title-row .library-inline-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: 1 1 100%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  gap: 0.28rem;
}

.match-create-modal-body .match-create-title-row .library-inline-label {
  align-self: flex-start;
}

.match-create-modal-body .match-create-title-row .library-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.match-create-formation-label .formation-select {
  min-width: 5.5rem;
  font-size: 0.8rem;
}

.layout.layout--archive-suspended {
  visibility: hidden;
  pointer-events: none;
}

/*
 * Archive: section count badges on accordion summaries use these + acc-summary-badge (app.js).
 * Row-level status pills can reuse the same classes if brought back.
 */
.match-archive-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
}

.match-archive-badge--pending {
  background: #bb800926;
  color: var(--warning, #d29922);
}

.match-archive-badge--logged {
  background: #23863633;
  color: var(--success, #3fb950);
}

.modal-match-side {
  max-width: 520px;
}

#modal-match-squad-select-list {
  max-height: 46vh;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

#modal-match-squad-select-list .match-squad-select-row {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

#modal-match-squad-select-list .match-squad-select-label {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin: 0;
}

#modal-match-squad-select-list .match-squad-select-label span {
  line-height: 1.25;
  word-break: break-word;
}

@media (max-width: 980px) {
  #modal-match-squad-select-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  #modal-match-squad-select-list {
    grid-template-columns: 1fr;
  }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 420px;
  width: 100%;
  padding: 1.25rem;
  box-shadow: 0 16px 48px #00000088;
}

.modal h3 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.modal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0 0 0.8rem;
}

.modal-title-row h3 {
  margin: 0;
}

.modal-row {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
  margin-top: 0.85rem;
  padding-top: 0.55rem;
}

.modal-clock-set {
  max-width: 440px;
}

.modal-clock-set-field {
  margin-bottom: 0;
}

.modal-clock-set-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  padding: 0.56rem 0.62rem;
}

.header-saved-team {
  min-width: 160px;
  max-width: 220px;
}

.modal.modal-library {
  max-width: min(920px, 96vw);
  width: 100%;
  min-height: 0;
  max-height: calc(100dvh - 4rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-formation-creator {
  max-width: min(980px, 96vw);
}

/*
 * Shared accordion system (`acc-*`) — single set of rules for any `<details>` stack.
 * Use the same class names in the Test modal, Teams library, and future UIs.
 *
 * Core structure:
 *   .acc-list — outer bordered shell. With `.admin-backup-list` on the same node: cancels 11rem cap
 *   (see `.admin-backup-list.acc-list`); parent `.modal-library-body` scrolls when sections open.
 *   .acc-item — one `<details>`; dividers between items.
 *   .acc-summary — `<summary>` row.
 *   .acc-panel — open body (replaces ad-hoc panel wrappers).
 *   .acc-inset — inner bordered box; add `.acc-rows` on the same node for stacked row rhythm.
 *   .acc-row / .acc-actions — utility rows inside demos or editors.
 *
 * Playground-only (#modal-test-accordion — modal chrome + widget demos):
 *   #modal-test-accordion.modal-backdrop — top-aligned dialog.
 *   body.modal-scroll-lock — lock page scroll while any `.modal-backdrop.open` (includes playground).
 *
 * Sections / widgets (prefixed test-acc-* — demos inside Test modal only):
 *   .test-acc-checklist-block + .acc-subhead — checklist groups with headers outside inner box.
 *   .acc-panel label — checklist rows.
 *   .acc-row, .acc-actions — flex rows + trailing buttons.
 *   .acc-item:not([open]) .acc-panel — hide collapsed body (JS single-open also).
 *   .test-acc-empty-toolbar, #test-acc-empty-host — empty list + add-item demo.
 *   .test-acc-edit-input — inline edit field.
 *   .test-acc-filter-toolbar, .test-acc-filter-row — filter input + filterable rows.
 *   .test-acc-long-wrap — scroll stress list (no acc-rows).
 *   .test-acc-meta-block, .test-acc-meta-sub — title + secondary line.
 *   .test-acc-disabled-note — copy next to disabled control demo.
 *
 * Rich summary & extra demos:
 *   .acc-summary-rich, .acc-summary-main, .acc-summary-title, .acc-summary-meta, .acc-summary-badge (library + playground)
 *   .test-acc-loading-row, .test-acc-spinner — busy body.
 *   #test-acc-demo-empty-host, .test-acc-demo-empty-line, #test-acc-demo-empty-add — empty body + add row.
 *   .test-acc-field-label, .test-acc-input-invalid, .test-acc-field-error — inline validation.
 *   .test-acc-content-sticky-footer, .test-acc-panel-scroll, .test-acc-panel-footer — sticky footer in open panel.
 *   Radio list — shares .acc-rows with <input type="radio">.
 *   .test-acc-truncate-demo — ellipsis single-line overflow.
 *   .test-acc-drag-row-wrap, .test-acc-drag-handle, .test-acc-drag-grip, .test-acc-drag-dot — HTML5 DnD from handle; 3×3 dots are real spans (avoids overflow clipping).
 *   #test-acc-drag-host — reorder targets for the drag demo.
 */

.modal-test-accordion {
  max-width: min(760px, 94vw);
}

/* Test accordion dialog: top-aligned in the viewport (separate from the shared library-modal backdrop block). */
#modal-test-accordion.modal-backdrop {
  align-items: flex-start;
  justify-content: center;
  padding-top: max(4rem, env(safe-area-inset-top, 0px));
  padding-right: 2rem;
  padding-bottom: 2rem;
  padding-left: 2rem;
}

#modal-test-accordion.modal-backdrop .modal.modal-library {
  max-height: calc(100dvh - max(4rem, env(safe-area-inset-top, 0px)) - 2rem);
}

.modal-test-accordion .modal-library-body {
  overscroll-behavior: contain;
}

body.modal-scroll-lock {
  overflow: hidden;
}

.acc-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-hover);
}

/* Same outer shell on `#library-team-list`: cancel `.admin-backup-list` short cap + inner scroll. */
.admin-backup-list.acc-list {
  max-height: none;
  overflow: visible;
  overflow-y: visible;
  padding: 0;
  margin-top: 0;
}

.acc-item {
  margin: 0;
  border: 0;
}

.acc-item:not(:first-child) {
  border-top: 1px solid var(--border);
}

.acc-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: normal;
  background: var(--surface-hover);
}

.acc-summary::-webkit-details-marker {
  display: none;
}

.acc-panel {
  padding: 0.6rem 0.75rem 0.7rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
}

.acc-inset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: var(--surface-hover);
  color: var(--text);
}

/* Row stack like closed accordion summaries (except checklist + long list, which omit this class). */
.acc-rows {
  padding: 0;
  overflow: hidden;
}

.acc-rows > * {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.acc-rows > * + * {
  border-top: 1px solid var(--border);
}

.acc-rows > #test-acc-empty-host {
  padding: 0;
}

.acc-rows > #test-acc-empty-host > * {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.acc-rows > #test-acc-empty-host > * + * {
  border-top: 1px solid var(--border);
}

.acc-rows .test-acc-filter-toolbar {
  margin-bottom: 0;
}

.acc-rows .test-acc-disabled-note {
  margin: 0;
}

.acc-rows .test-acc-meta-block + .test-acc-meta-block {
  margin-top: 0;
}

.acc-rows > .test-acc-action-row + .test-acc-action-row {
  margin-top: 0;
}

.acc-rows .test-acc-filter-row + .test-acc-filter-row {
  margin-top: 0;
}

.acc-panel label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.acc-panel label + label {
  margin-top: 0.35rem;
}

.acc-subhead {
  margin: 0.15rem 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.test-acc-checklist-block + .test-acc-checklist-block {
  margin-top: 0.65rem;
}

.test-acc-checklist-block > .acc-subhead {
  margin: 0 0 0.35rem;
}

.acc-subhead + label {
  margin-top: 0;
}

.acc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.acc-row + .acc-row {
  margin-top: 0.35rem;
}

.acc-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.acc-item:not([open]) .acc-panel {
  display: none;
}

/*
 * Library modals — optional rich summary (matches Test accordion “Leagues” row):
 * default: title + meta stacked; Teams list uses `.acc-summary-main--league-line` (name + country / hint on one row).
 * Then pill count and `.library-league-actions`.
 */
.acc-summary.acc-summary-rich {
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
}

.acc-summary-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  gap: 0.12rem;
  flex: 1;
}

/* Teams library: league name + country (or unassigned hint) on one row, name first. */
.acc-summary-main.acc-summary-main--league-line {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
}

.acc-summary-main.acc-summary-main--league-line .acc-summary-meta {
  font-size: 0.82rem;
}

.acc-summary-main.acc-summary-main--league-line .acc-summary-badge {
  margin-left: 0.15rem;
}

.acc-summary-title {
  color: var(--text);
}

.acc-summary-meta {
  font-size: 0.72rem;
  font-weight: normal;
  color: var(--muted);
}

.acc-summary-badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* Archive accordion: count badge color = section kind (overrides neutral .acc-summary-badge). */
#modal-match-archive-list .acc-summary-badge.match-archive-badge--pending {
  background: #bb800926;
  color: var(--warning, #d29922);
  border-color: color-mix(in srgb, var(--warning, #d29922) 45%, var(--border));
}

#modal-match-archive-list .acc-summary-badge.match-archive-badge--logged {
  background: #23863633;
  color: var(--success, #3fb950);
  border-color: color-mix(in srgb, var(--success, #3fb950) 45%, var(--border));
}

.acc-summary.acc-summary-rich .library-league-actions {
  flex-shrink: 0;
  margin-left: auto;
}

.library-group-teams.acc-panel {
  padding: 0.6rem 0.75rem 0.7rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  box-sizing: border-box;
}

.acc-inset.acc-rows > .admin-backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  border-bottom: none;
  background: transparent;
  box-shadow: none;
}

.acc-inset.acc-rows > .admin-backup-row + .admin-backup-row {
  border-top: 1px solid var(--border);
}

/* Team library: drag handle + team strip (replaces direct `.admin-backup-row` children). */
.acc-inset.acc-rows > .library-team-drag-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.acc-inset.acc-rows > .library-team-drag-wrap > .admin-backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.acc-inset.acc-rows > .muted-small {
  display: block;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  margin: 0;
}

.test-acc-empty-toolbar {
  margin-bottom: 0.45rem;
}

.test-acc-edit-input {
  flex: 1;
  min-width: 0;
  padding: 0.32rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
}

.test-acc-filter-toolbar {
  margin-bottom: 0.45rem;
}

.test-acc-filter-row + .test-acc-filter-row {
  margin-top: 0.28rem;
}

.test-acc-filter-toolbar input[type="search"],
.test-acc-filter-toolbar input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.32rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
}

/* Archive (etc.): label + trailing action, aligned like filter rows with extra control. */
.test-acc-filter-row:has(> .btn) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.test-acc-filter-row:has(> .btn) > :first-child {
  flex: 1;
  min-width: 0;
}

.test-acc-long-wrap {
  max-height: 11rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  margin: 0 -0.15rem 0 0;
}

.test-acc-long-wrap > div + div {
  margin-top: 0.28rem;
}

.test-acc-meta-block {
  align-items: flex-start;
}

.test-acc-meta-block + .test-acc-meta-block {
  margin-top: 0.5rem;
}

.test-acc-meta-sub {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.test-acc-disabled-note {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

@keyframes test-acc-spin {
  to {
    transform: rotate(360deg);
  }
}

#modal-test-accordion .test-acc-spinner {
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: test-acc-spin 0.65s linear infinite;
}

#modal-test-accordion .test-acc-loading-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#modal-test-accordion #test-acc-demo-empty-host .test-acc-demo-empty-line {
  padding: 0.35rem 0;
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
}

#modal-test-accordion #test-acc-demo-empty-host .test-acc-demo-empty-line:first-child {
  border-top: none;
  padding-top: 0;
}

.test-acc-field-label {
  display: block;
  margin-bottom: 0.28rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.test-acc-input-invalid {
  border-color: var(--home-team, #f85149);
}

.test-acc-field-error {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--home-team, #f85149);
}

#modal-test-accordion .test-acc-content-sticky-footer {
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
}

#modal-test-accordion .test-acc-panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 11rem;
  overflow-y: auto;
  padding: 0.6rem 0.75rem 0.5rem;
}

#modal-test-accordion .test-acc-panel-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#modal-test-accordion .test-acc-panel-footer #test-acc-sticky-status {
  margin-right: auto;
}

#modal-test-accordion .test-acc-truncate-demo {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#modal-test-accordion .test-acc-drag-row-wrap,
#modal-team-library .library-team-drag-wrap,
#modal-formation-creator .library-team-drag-wrap {
  position: relative;
}

#modal-test-accordion .test-acc-drag-row-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

#modal-test-accordion .test-acc-drag-handle,
#modal-team-library .test-acc-drag-handle,
#modal-formation-creator .test-acc-drag-handle {
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  padding: 0.12rem 0.2rem;
  line-height: 0;
}

/* 3×3 grip: real elements (box-shadow on ::before was clipped by .acc-rows overflow). */
#modal-test-accordion .test-acc-drag-grip {
  display: inline-grid;
  grid-template-columns: repeat(3, 3px);
  grid-template-rows: repeat(3, 3px);
  gap: 2px;
  align-items: center;
  justify-items: center;
  vertical-align: middle;
}

#modal-team-library .test-acc-drag-grip {
  display: grid;
  box-sizing: content-box;
  width: 13px;
  min-width: 13px;
  height: 13px;
  min-height: 13px;
  grid-template-columns: repeat(3, 3px);
  grid-template-rows: repeat(3, 3px);
  gap: 2px;
  align-items: center;
  justify-items: center;
}

#modal-test-accordion .test-acc-drag-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
}

#modal-team-library .test-acc-drag-dot,
#modal-formation-creator .test-acc-drag-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
}

#modal-test-accordion .test-acc-drag-label {
  flex: 1;
  min-width: 0;
}

#modal-test-accordion .test-acc-drag-row-wrap.test-acc-dragging,
#modal-team-library .library-team-drag-wrap.test-acc-dragging,
#modal-formation-creator .library-team-drag-wrap.test-acc-dragging {
  opacity: 0.55;
}

/* Drop preview: light grey bar on the gap above/below this row (matches insertBefore logic). */
#modal-test-accordion .test-acc-drag-row-wrap.test-acc-insert-before::before,
#modal-team-library .library-team-drag-wrap.test-acc-insert-before::before,
#modal-formation-creator .library-team-drag-wrap.test-acc-insert-before::before {
  content: "";
  position: absolute;
  left: 0.35rem;
  right: 0.35rem;
  top: 0;
  height: 3px;
  margin-top: -2px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--text) 42%, var(--border));
  box-shadow: 0 0 10px color-mix(in srgb, var(--text) 16%, transparent);
  pointer-events: none;
  z-index: 1;
}

#modal-test-accordion .test-acc-drag-row-wrap.test-acc-insert-after::after,
#modal-team-library .library-team-drag-wrap.test-acc-insert-after::after,
#modal-formation-creator .library-team-drag-wrap.test-acc-insert-after::after {
  content: "";
  position: absolute;
  left: 0.35rem;
  right: 0.35rem;
  bottom: 0;
  height: 3px;
  margin-bottom: -2px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--text) 42%, var(--border));
  box-shadow: 0 0 10px color-mix(in srgb, var(--text) 16%, transparent);
  pointer-events: none;
  z-index: 1;
}

/* Member editor: avoid clipping under modal chrome when `.modal-library-body` scrolls into view. */
#modal-org-shell #admin-user-editor.library-editor {
  scroll-margin-top: 0.85rem;
  scroll-margin-bottom: 1rem;
}

/* Square chrome on Organization shell footer (design prefs; default .btn is rounded). */
#modal-org-shell .modal-library-footer-actions .btn {
  border-radius: 0;
}

.admin-import-feedback,
.admin-export-feedback,
.library-team-save-feedback,
.library-league-save-feedback {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
}

.admin-import-feedback[hidden],
.admin-export-feedback[hidden],
.library-team-save-feedback[hidden],
.library-league-save-feedback[hidden] {
  display: none !important;
}

.admin-import-feedback--success,
.admin-export-feedback--success,
.library-team-save-feedback--success,
.library-league-save-feedback--success {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
}

.admin-import-feedback--error,
.admin-export-feedback--error,
.library-team-save-feedback--error,
.library-league-save-feedback--error {
  border-color: color-mix(in srgb, var(--home-team) 55%, var(--border));
  background: color-mix(in srgb, var(--home-team) 10%, var(--surface));
}

.admin-import-feedback--info,
.admin-export-feedback--info {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  background: color-mix(in srgb, var(--accent) 11%, var(--surface));
}

.admin-users-extra:not(:empty) {
  margin-top: 0.75rem;
}

.admin-backup-block {
  margin-bottom: 0.65rem;
}

.admin-backup-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.admin-backup-block-head .library-section-label {
  margin: 0;
}

.admin-backup-quick {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.btn-tiny-text {
  padding: 0.15rem 0.42rem;
  font-size: 0.72rem;
  font-weight: 600;
}

.admin-backup-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 11rem;
  overflow: hidden;
  overflow-y: auto;
  padding: 0 0.65rem;
  margin-top: 0.28rem;
  background: var(--bg);
}

/* Settings card fills its own inner padding — avoid doubling horizontal inset. */
.admin-backup-list.admin-backup-list--static {
  padding-left: 0;
  padding-right: 0;
}

/* Export + Users lists: grow with content (no inner scrollbar). Import lists keep max-height + scroll. */
#admin-users-list,
#platform-customers-list,
#admin-export-leagues-list,
#admin-export-teams-list,
#admin-export-formations-list {
  max-height: none;
}

/*
 * Filled `.admin-backup-list` shells (Profiles, platform customers, export + import + library lists).
 * Same scroll host fill / padding / scrollbar — avoids `--bg` gutters next to `--surface-hover` rows.
 */
#admin-users-list.admin-backup-list,
#platform-customers-list.admin-backup-list,
#admin-export-leagues-list.admin-backup-list,
#admin-export-teams-list.admin-backup-list,
#admin-export-formations-list.admin-backup-list,
#admin-import-leagues-list.admin-backup-list,
#admin-import-teams-list.admin-backup-list,
#admin-import-formations-list.admin-backup-list {
  background: var(--surface-hover);
  scrollbar-color: var(--muted) var(--surface-hover);
}

#admin-users-list.admin-backup-list::-webkit-scrollbar-track,
#platform-customers-list.admin-backup-list::-webkit-scrollbar-track,
#admin-export-leagues-list.admin-backup-list::-webkit-scrollbar-track,
#admin-export-teams-list.admin-backup-list::-webkit-scrollbar-track,
#admin-export-formations-list.admin-backup-list::-webkit-scrollbar-track,
#admin-import-leagues-list.admin-backup-list::-webkit-scrollbar-track,
#admin-import-teams-list.admin-backup-list::-webkit-scrollbar-track,
#admin-import-formations-list.admin-backup-list::-webkit-scrollbar-track {
  background: var(--surface-hover);
}

#admin-users-list.admin-backup-list::-webkit-scrollbar-thumb,
#platform-customers-list.admin-backup-list::-webkit-scrollbar-thumb,
#admin-export-leagues-list.admin-backup-list::-webkit-scrollbar-thumb,
#admin-export-teams-list.admin-backup-list::-webkit-scrollbar-thumb,
#admin-export-formations-list.admin-backup-list::-webkit-scrollbar-thumb,
#admin-import-leagues-list.admin-backup-list::-webkit-scrollbar-thumb,
#admin-import-teams-list.admin-backup-list::-webkit-scrollbar-thumb,
#admin-import-formations-list.admin-backup-list::-webkit-scrollbar-thumb {
  border-color: var(--surface-hover);
}

#admin-users-list.admin-backup-list,
#platform-customers-list.admin-backup-list,
#admin-export-leagues-list.admin-backup-list,
#admin-export-teams-list.admin-backup-list,
#admin-export-formations-list.admin-backup-list,
#admin-import-leagues-list.admin-backup-list,
#admin-import-teams-list.admin-backup-list,
#admin-import-formations-list.admin-backup-list {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.modal-library-backup-block {
  margin-bottom: 0.75rem;
}

/* Section label + list gap (avoid margin collapse making label flush to list). */
.modal-library-backup-block .admin-backup-block-head .library-section-label {
  margin: 0;
  display: block;
}

/* Settings: same bordered “list” shell as export blocks, for non-row content. */
#modal-user-settings .admin-backup-list--static {
  max-height: none;
  overflow: hidden;
}

#modal-user-settings .admin-backup-list--static > .admin-backup-list-pad {
  padding: 0.6rem 0.75rem 0.65rem;
  background: var(--surface-hover);
}

#modal-org-shell #org-subscription-block.admin-backup-list--static {
  max-height: none;
  overflow: hidden;
}

#modal-org-shell #org-subscription-block.admin-backup-list--static > .admin-backup-list-pad {
  padding: 0.6rem 0.75rem 0.65rem;
  background: var(--surface-hover);
}

#modal-user-settings .admin-settings-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.65rem 1rem;
}

#modal-user-settings .admin-settings-inline .library-inline-fields {
  flex: 1 1 auto;
  margin-bottom: 0;
  min-width: min(100%, 12rem);
}

#modal-user-settings .admin-settings-inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* User Settings: sentence-case labels (same fields as Admin lab, friendlier copy). */
#modal-user-settings .admin-settings-inline .library-inline-label {
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 0.75rem;
}

#modal-user-settings .admin-settings-inline .library-inline-field {
  gap: 0.5rem;
}

.admin-backup-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem 0.45rem 0.65rem;
  font-size: 0.88rem;
  line-height: 1.25;
  border-bottom: 1px solid var(--border);
  background: var(--surface-hover);
}

.admin-backup-row:last-child {
  border-bottom: none;
}

/* Custom checkboxes site-wide (grey scheme: surface, border, muted, surface-hover, text). */
input[type="checkbox"]:not(.visually-hidden) {
  appearance: none;
  -webkit-appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  background-color: var(--surface);
  cursor: pointer;
  vertical-align: top;
  transition:
    border-color 0.12s ease,
    background-color 0.12s ease,
    box-shadow 0.12s ease;
}

input[type="checkbox"]:not(.visually-hidden):hover {
  border-color: var(--muted);
}

input[type="checkbox"]:not(.visually-hidden):checked {
  background-color: var(--surface-hover);
  border-color: var(--muted);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.62rem auto;
}

/** Tick uses --text (SVG data URL cannot read CSS vars). */
body:not(.theme-light) input[type="checkbox"]:not(.visually-hidden):checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23e6edf3' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M2.5 6.2 5.3 9 9.8 3.5'/%3E%3C/svg%3E");
}

body.theme-light input[type="checkbox"]:not(.visually-hidden):checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23111827' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M2.5 6.2 5.3 9 9.8 3.5'/%3E%3C/svg%3E");
}

input[type="checkbox"]:not(.visually-hidden):checked:hover {
  border-color: var(--text);
}

input[type="checkbox"]:not(.visually-hidden):not(:checked) {
  background-image: none;
}

input[type="checkbox"]:not(.visually-hidden):focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px var(--focus-ring-edge), 0 0 0 3px var(--focus-ring-glow);
}

input[type="checkbox"]:not(.visually-hidden):disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.admin-backup-row input[type="checkbox"] {
  margin-top: 0.12rem;
}

.admin-backup-row label {
  cursor: pointer;
  min-width: 0;
}

.admin-backup-empty {
  margin: 0;
  padding: 0.5rem 0.25rem;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Keep title and footer border full width of the modal so they align with body
   content. Pitch/editor rows stay centered via their own width rules inside the body. */
.modal-formation-creator > h3 {
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
}

.formation-creator-pitch {
  margin-top: 0.4rem;
  /* Football: JS sets --fc-grid-size from height ÷ --fc-grid-rows (16). Handball grid is on .pitch-graphics with the same square-cell model (see app.js). */
  --fc-grid-rows: 16;
  --fc-grid-size: 28px;
  --fc-grid-offset-x: 0px;
  --fc-grid-offset-y: 0px;
  background-image:
    linear-gradient(to right, #ffffff12 1px, transparent 1px),
    linear-gradient(to bottom, #ffffff12 1px, transparent 1px);
  background-size: var(--fc-grid-size) var(--fc-grid-size);
  background-position: var(--fc-grid-offset-x) var(--fc-grid-offset-y);
}

.formation-creator-tools {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 4;
}

.fc-snap-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.2rem 0.38rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d1117cc;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.fc-snap-toggle input {
  margin: 0;
}

body.theme-light .fc-snap-toggle {
  background: #ffffffde;
  color: var(--text);
  border-color: var(--border);
}

/* Increase field-line contrast in formation editor only. */
.formation-creator-pitch .pitch-line {
  background: #ffffff70;
}

.formation-creator-pitch .pitch-box {
  border-color: #ffffff70;
}

.fc-editor-footer-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0;
  margin-top: 0.8rem;
  margin-bottom: 0.2rem;
  width: min(calc(var(--squad-pitch-h) * 1.78), 100%);
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  min-width: 0;
  box-sizing: border-box;
}

/* Name + category stay left as a tight group; free space sits before the buttons. */
.fc-editor-fields-cluster {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  flex-wrap: nowrap;
  gap: 0.35rem;
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
}

.fc-editor-name-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.fc-editor-footer-row .fc-editor-fields-cluster > .fc-editor-name-field {
  margin: 0;
}

/* Formation block only as wide as its input (category follows immediately). */
.fc-editor-footer-row .fc-editor-fields-cluster > .fc-editor-formation-name-field {
  flex: 0 0 auto;
  min-width: 0;
}

.fc-editor-footer-row .fc-editor-fields-cluster > .fc-editor-category-field {
  flex: 0 0 auto;
}

.fc-editor-footer-row .fc-editor-fields-cluster > .fc-editor-name-field .library-input {
  margin: 0;
}

.fc-editor-name-field .library-inline-label {
  flex-shrink: 0;
}

.fc-editor-name-field.fc-editor-formation-name-field .library-input {
  flex: 0 0 auto;
  min-width: 8rem;
  /* ~40% shorter cap than previous 22rem (22 × 0.6). */
  width: min(13.2rem, 42vw);
  max-width: 100%;
  box-sizing: border-box;
}

.fc-editor-name-field.fc-editor-category-field .library-input {
  width: min(9.5rem, 28vw);
  max-width: 100%;
  flex: 0 0 auto;
  min-width: 0;
  box-sizing: border-box;
}

.fc-editor-footer-buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.5rem;
  flex: 0 0 auto;
  margin-left: auto;
  padding-left: 1.25rem;
  white-space: nowrap;
}

/* New league / New category: fields + Cancel/Save on one row (same idea as formation footer). */
.library-editor-compact-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0.5rem;
  margin-top: 0.45rem;
  margin-bottom: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.library-editor-compact-row .library-inline-fields--editor-compact {
  flex: 1 1 0;
  min-width: 0;
  flex-wrap: nowrap;
  margin-bottom: 0;
  gap: 0.35rem 0.55rem;
}

.library-editor-compact-row .library-inline-field {
  flex: 1 1 0;
  min-width: 0;
}

.library-editor-compact-row .library-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.library-editor-compact-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  margin-left: auto;
  white-space: nowrap;
}

/* New category: one field — don’t let it eat the full row (league keeps two fields sharing space). */
#fc-category-editor .library-editor-compact-row .library-inline-fields--editor-compact {
  flex: 0 1 auto;
  width: auto;
  max-width: min(18rem, 72vw);
}

#fc-category-editor .library-editor-compact-row .library-inline-field {
  flex: 0 0 auto;
}

#fc-category-editor .library-editor-compact-row .library-input {
  flex: 0 0 auto;
  width: min(14rem, 42vw);
  min-width: 9rem;
  max-width: 100%;
}

/* New league: League + Country inputs ~50% shorter than flex-fill stretch. */
#library-league-editor .library-editor-compact-row .library-inline-fields--editor-compact {
  flex: 0 1 auto;
  width: auto;
  max-width: min(26rem, 90vw);
}

#library-league-editor .library-editor-compact-row .library-inline-field {
  flex: 0 0 auto;
}

#library-league-editor .library-editor-compact-row .library-input {
  flex: 0 0 auto;
  width: min(11rem, 34vw);
  min-width: 7rem;
  max-width: 100%;
}

.modal.modal-library > h3 {
  flex: 0 0 auto;
}

.modal-library-footer-actions {
  flex: 0 0 auto;
  margin-top: auto;
}

/* Footer bar: same width as scroll body, top rule, padding — all library shells (Teams, Archive, Settings, …). */
.modal.modal-library > .modal-actions.modal-library-footer-actions {
  width: calc(100% - 0.65rem);
  max-width: calc(100% - 0.65rem);
  margin-top: auto;
  margin-right: 0.65rem;
  margin-left: 0;
  margin-bottom: 0;
  align-self: flex-start;
  box-sizing: border-box;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

/* Library modal body: breathing room above footer / scrollbar gutter (see footer rule below). */
.modal-library-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 0.65rem;
  padding-bottom: 0.75rem;
}

.muted-small {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.library-list-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: none;
  overflow: visible;
  margin-bottom: 0.75rem;
}

.library-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem 0.45rem 3rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-hover);
  font-size: 0.88rem;
}

.library-row:last-child {
  border-bottom: 0;
}

/* Nested league/category hosts: default `library-row` tucks actions (not used for export-style `admin-backup-row` strips). */
.library-group-teams .library-row {
  padding-right: 0;
}

/* Profile + platform customer rows (shared `.admin-backup-row` strip inside lists). */
#admin-users-list.admin-backup-list > .admin-backup-row,
#platform-customers-list.admin-backup-list > .admin-backup-row {
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

#admin-users-list.admin-backup-list > .admin-backup-row {
  align-items: flex-start;
}

.admin-user-row-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  text-align: left;
}

.admin-user-row-primary {
  font-weight: 600;
  word-break: break-word;
}

.admin-user-row-name {
  font-size: 0.82em;
  font-weight: 400;
  word-break: break-word;
}

.library-league-group > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}

.library-league-group > summary::-webkit-details-marker {
  display: none;
}

.library-league-title {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.library-league-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.library-league-action {
  padding: 0.22rem 0.5rem;
  font-size: 0.78rem;
}

.library-group-teams {
  border-top: 0;
  padding: 0.5rem 0.65rem 0.65rem;
  box-sizing: border-box;
}

/* Align folded summary bottom with wrapped list edge (host already has outer border). */
.library-list-wrap > .library-league-group:last-child:not([open]) > summary {
  border-bottom: none;
}

.library-league-group:not([open]) .library-group-teams {
  display: none;
}

.library-empty-group {
  margin: 0;
  padding: 0.55rem 0.65rem;
}

.library-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}

.library-row-actions .btn {
  padding: 0.22rem 0.5rem;
  font-size: 0.78rem;
}

.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.library-hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* Only when team editor is open — avoids a stray rule + gap above modal Close when editors are closed. */
.library-editor > .library-hr--team-editor-top:first-child {
  margin-top: 0.35rem;
}

.library-field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.library-inline-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.75rem;
  margin-bottom: 0.45rem;
}

.library-inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.library-inline-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.library-team-fields .library-inline-field {
  flex: 1 1 160px;
}

.library-team-fields .library-inline-field-id {
  flex: 0 0 7.25rem;
}

.library-team-fields .library-inline-field-league {
  flex: 1 1 160px;
  min-width: 0;
}

.library-team-fields .library-inline-field-league .library-input {
  flex: 1 1 auto;
  min-width: 6rem;
  max-width: 100%;
}

/* Input width matches league table P / GD / PTS columns (4rem). */
.library-inline-field-league-table-size {
  flex: 0 1 auto;
}

.library-inline-field-league-table-size .library-input {
  width: 4rem;
  min-width: 4rem;
  max-width: 4rem;
  box-sizing: border-box;
}

/* Groups League / Country / Teams in table — same thin tile as prep / platform customer panels */
.library-league-editor-meta-row {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--surface);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
}

.library-league-editor-fields {
  flex-wrap: wrap;
}

.library-league-table-section {
  margin-top: 0.65rem;
}

.library-league-table-heading {
  display: block;
  margin-bottom: 0.25rem;
}

.library-league-table-hint {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
}

.library-league-table-scroll {
  overflow-x: auto;
  margin-bottom: 0.45rem;
  max-height: 42vh;
  overflow-y: auto;
}

.library-league-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.library-league-table th,
.library-league-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.35rem 0.45rem;
  text-align: left;
  vertical-align: middle;
}

.library-league-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.library-league-table-rank {
  width: 2.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.library-league-table .library-input {
  min-width: 0;
}

.library-league-table th:nth-child(1),
.library-league-table td:nth-child(1) {
  width: 2.75rem;
}

/* Team column: 100% wider than original 8rem min (→ 16rem). */
.library-league-table th:nth-child(2),
.library-league-table td:nth-child(2) {
  min-width: 16rem;
  width: auto;
}

.library-league-table th:nth-child(3),
.library-league-table td:nth-child(3),
.library-league-table th:nth-child(4),
.library-league-table td:nth-child(4),
.library-league-table th:nth-child(5),
.library-league-table td:nth-child(5) {
  width: 4rem;
}

/* Was 8rem / 16rem cap; now 2× each = 16rem / 32rem. */
.library-league-table .library-league-table-team {
  width: 100%;
  min-width: 16rem;
  max-width: 32rem;
  box-sizing: border-box;
}

.library-league-table-p,
.library-league-table-gd,
.library-league-table-pts {
  width: 100%;
  max-width: 100%;
}

.library-league-table-toolbar {
  margin-top: 0.35rem;
  margin-bottom: 0;
}

.library-league-editor-footer-actions {
  margin-top: 0.65rem;
}

.library-leagues-block {
  margin: 0.35rem 0 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.library-leagues-heading {
  display: block;
}

/* Bordered shell under a `.library-section-label` (additional leagues, last five matches, etc.). */
.library-editor-inset-wrap {
  margin: 0 0 0.55rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-hover);
  box-sizing: border-box;
  min-width: 0;
}

.library-editor-inset-wrap .library-inline-fields {
  margin-bottom: 0;
}

.library-editor-inset-wrap .library-leagues-checklist {
  border: none;
  border-radius: 6px;
  background: var(--bg);
  padding: 0.35rem 0.45rem;
}

.library-last-five-selects {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  min-width: 0;
}

.library-last-five-select {
  flex: 1 1 0;
  min-width: 3.75rem;
  max-width: 6rem;
  box-sizing: border-box;
}

.library-leagues-checklist {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  padding: 0.4rem 0.5rem;
  max-height: 9rem;
  overflow-y: auto;
}

.library-leagues-checklist--cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.2rem 0.65rem;
  align-content: start;
}

.library-leagues-checklist--cols > .library-leagues-checklist-msg {
  grid-column: 1 / -1;
}

/* Single-column checklist (e.g. prep edit team): avoid tall grid rows; tighter than flex-start + multi-col. */
.library-leagues-checklist--stack {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.26rem 0.4rem;
}

.library-leagues-checklist--stack .library-league-check-row {
  align-items: center;
  gap: 0.3rem;
  font-size: 0.76rem;
}

.library-leagues-checklist--stack .library-league-check-name {
  line-height: 1.15;
}

.library-leagues-checklist--stack input[type="checkbox"]:not(.visually-hidden) {
  width: 0.92rem;
  height: 0.92rem;
  margin-top: 0;
}

.library-leagues-checklist--stack input[type="checkbox"]:not(.visually-hidden):checked {
  background-size: 0.55rem auto;
}

.library-league-check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  min-width: 0;
  font-size: 0.78rem;
}

.library-league-check-name {
  cursor: pointer;
  min-width: 0;
  line-height: 1.25;
}

.library-inline-field .library-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

.library-section-label {
  margin: 0.55rem 0 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Settings → Views: single toolbar strip — same fill as sport tiles / `.acc-inset`. */
#modal-user-settings .settings-views-toolbar-wrap {
  margin: 0;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: var(--surface-hover);
}

.settings-console-sport-fieldset {
  margin: 0.5rem 0 0;
  padding: 0;
  border: none;
  min-width: 0;
}

/* Legend ignores fieldset padding in some UAs — pad the legend and leave air above the radio row. */
#modal-user-settings .settings-console-sport-fieldset .settings-console-sport-legend {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 0.55rem;
  padding: 0 0.35rem;
}

.settings-console-sports-inner {
  margin: 0;
  min-width: 0;
}

/* Four columns: Football · Handball · (reserved) · (reserved). */
#modal-user-settings .settings-console-sport-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 0.55rem 0.65rem;
}

#modal-user-settings .settings-console-sport-wrap {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: var(--surface-hover);
}

.settings-console-sport-wrap label {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}

#modal-user-settings .settings-console-sport-wrap--locked {
  opacity: 0.88;
}

.settings-console-sport-wrap--locked label {
  cursor: default;
  color: var(--muted);
}

.library-label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 1 1 120px;
  min-width: 0;
}

.library-label-team-code {
  flex: 0 0 6.6rem;
}

.library-label-league {
  flex: 0 0 12rem;
}

.library-input {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
}

/** Text fields (not selects): reset UA chrome; extra horizontal padding so text clears the border + glow. */
input.library-input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(
    [type="color"]
  ):not([type="hidden"]),
textarea.library-input {
  margin: 0;
  padding: 0.45rem 0.85rem;
  font: inherit;
  line-height: 1.35;
  -webkit-appearance: none;
  appearance: none;
}

.library-input-team-code {
  text-transform: uppercase;
}

.library-table-scroll {
  overflow-x: auto;
  overflow-y: visible;
  max-height: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding-bottom: 0.4rem;
  box-sizing: border-box;
}

.library-squad-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  table-layout: fixed;
}

.library-squad-table th,
.library-squad-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.library-squad-table th {
  background: var(--surface-hover);
  color: var(--muted);
  font-weight: 600;
}

.library-squad-table input {
  width: 100%;
  min-width: 0;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
}

.library-coach-table input:disabled {
  color: var(--muted);
  opacity: 0.55;
  cursor: default;
}

.library-squad-table .lib-col-num {
  width: 2.75rem;
}

.library-squad-table .lib-col-name {
  width: calc(100% - 43rem);
}

.library-squad-table th:not(:nth-child(2)) {
  width: 3rem;
}

.library-squad-table th:nth-child(3),
.library-squad-table th:nth-child(4),
.library-squad-table th:nth-child(5),
.library-squad-table th:nth-child(6) {
  width: 4rem;
}

.library-squad-table .lib-col-num,
.library-squad-table .lib-col-compact,
.library-squad-table .lib-col-stat,
.library-squad-table .lib-col-actions {
  width: 3rem;
  max-width: 3rem;
}

.library-squad-table .lib-col-nat,
.library-squad-table .lib-col-pos,
.library-squad-table .lib-col-signed,
.library-squad-table .lib-col-leaves {
  width: 4rem;
  max-width: 4rem;
}

.library-squad-table .lib-col-actions {
  width: 3rem;
  max-width: 3rem;
  text-align: center;
}

/* Coach row uses the same `library-squad-table` class as the squad grid — these rules must
   come *after* the squad column widths so Nat/Signed/Leaves match players and Name gets
   the slack (the full-squad `calc(100% - 43rem)` name width does not apply here). */
.library-squad-table.library-coach-table {
  table-layout: auto;
  width: 100%;
}

.library-squad-table.library-coach-table .lib-col-coach-title {
  width: 5.5rem;
  max-width: 6.5rem;
}

.library-squad-table.library-coach-table .lib-col-name {
  width: auto;
  min-width: 0;
}

.library-squad-table.library-coach-table .lib-col-nat,
.library-squad-table.library-coach-table .lib-col-pos,
.library-squad-table.library-coach-table .lib-col-signed,
.library-squad-table.library-coach-table .lib-col-leaves {
  width: 4rem;
  max-width: 4rem;
}

.library-squad-table.library-coach-table .lib-col-num,
.library-squad-table.library-coach-table .lib-col-compact,
.library-squad-table.library-coach-table .lib-col-stat,
.library-squad-table.library-coach-table .lib-col-actions {
  width: 3rem;
  max-width: 3rem;
}

.library-squad-table.library-coach-table .lib-col-compact.lib-col-coach-title {
  width: 5.5rem;
  max-width: 6.5rem;
}

.library-squad-table.library-coach-table thead th:nth-child(1) {
  width: 5.5rem;
}

.library-squad-table.library-coach-table thead th:nth-child(2) {
  width: auto;
}

.library-squad-table.library-coach-table thead th:nth-child(3),
.library-squad-table.library-coach-table thead th:nth-child(4),
.library-squad-table.library-coach-table thead th:nth-child(5) {
  width: 4rem;
}

.library-squad-table.library-coach-table thead th:nth-child(6),
.library-squad-table.library-coach-table thead th:nth-child(7),
.library-squad-table.library-coach-table thead th:nth-child(8),
.library-squad-table.library-coach-table thead th:nth-child(9),
.library-squad-table.library-coach-table thead th:nth-child(10),
.library-squad-table.library-coach-table thead th:nth-child(11) {
  width: 3rem;
}

.btn-icon-remove {
  padding: 0.15rem 0.35rem;
  font-size: 1rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--home-team);
  cursor: pointer;
  border-radius: 4px;
}

.btn-icon-remove:hover {
  color: var(--home-team);
  background: color-mix(in srgb, var(--home-team) 18%, transparent);
}

@supports not (color: color-mix(in srgb, white 50%, black)) {
  .btn-icon-remove:hover {
    background: rgba(248, 81, 73, 0.18);
  }

  body.theme-light .btn-icon-remove:hover {
    background: rgba(217, 54, 62, 0.16);
  }
}

/* Match log review */
.match-log-review-body {
  overflow-y: auto;
  max-height: min(52vh, 28rem);
}

.match-log-team-block {
  margin-bottom: 1.25rem;
}

.match-log-team-block:last-child {
  margin-bottom: 0;
}

.match-log-team-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.match-log-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.match-log-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.match-log-col-shirt {
  width: 2.75rem;
}

.match-log-col-name {
  width: 34%;
  min-width: 0;
}

.match-log-col-stat {
  width: 13.2%;
}

.match-log-table th,
.match-log-table td {
  padding: 0.35rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.match-log-table th.match-log-th-stat,
.match-log-table td.match-log-stat-cell {
  text-align: center;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.match-log-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.match-log-table tbody tr:last-child td {
  border-bottom: none;
}

.match-log-table .match-log-shirt {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.match-log-table .match-log-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
}

.match-log-stat-cell {
  box-sizing: border-box;
}

.match-log-stat-input {
  box-sizing: border-box;
  width: 100%;
  max-width: 3.5rem;
  min-width: 0;
  margin: 0 auto;
  display: block;
  padding: 0.22rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

.match-log-stat-input::-webkit-outer-spin-button,
.match-log-stat-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* --------------------------------------------------------------------------
 * Dev-only role shell (localhost / ?devShell=1): preview Super admin / Admin / User UI.
 * Remove or gate when replacing with real Supabase RBAC.
 * -------------------------------------------------------------------------- */
#btn-platform-shell,
#btn-org-shell,
#btn-test-accordion {
  display: none !important;
}

body.dev-role-shell-enabled[data-effective-role="superadmin"] #btn-platform-shell,
body.dev-role-shell-enabled[data-effective-role="superadmin"] #btn-test-accordion {
  display: inline-flex !important;
}

body.dev-role-shell-enabled[data-effective-role="admin"] #btn-org-shell {
  display: inline-flex !important;
}

/* Role-shell modals: same .open pattern as other modals (stack above main chrome). */
#modal-platform-shell.modal-backdrop.open,
#modal-org-shell.modal-backdrop.open {
  z-index: 10050;
}

/* Add/edit customer — must stack above Platform / Org shell (10050). */
#modal-platform-customer-editor.modal-backdrop.open {
  z-index: 10060;
}

.dev-role-shell-mount {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.dev-role-shell-mount[hidden] {
  display: none !important;
}

.dev-role-shell-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  max-width: 100%;
  font-size: inherit;
}

.dev-role-shell-select {
  max-width: min(10.5rem, 36vw);
}
