/* ==============================================
   BASE TABLE STYLE
   ============================================== */
  .rr-matrix-table {
    border-collapse: collapse !important;
    table-layout: fixed !important;
    background: #ffffff !important;
    width: max-content !important;
    min-width: min(100%, 720px);
    margin-bottom: 0;
  }

  /* Matrix must scroll */
  .rr-matrix-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    padding-bottom: 5px;
    scrollbar-gutter: stable;
  }

  .rr-group-section + .rr-group-section {
    margin-top: 30px;
  }

  .rr-group-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 10px;
  }

  .rr-group-heading h6 { margin: 0; }
  .rr-group-meta { color: #69778c; font-size: 12px; }

  /* ----------------------------------------------
   All cells — uniform sizing via table-layout:fixed
   ---------------------------------------------- */
  .rr-matrix-table td {
    padding: 0 !important;
    height: 46px !important;
    min-width: 148px;
    text-align: center;
    vertical-align: middle;
    border: 1px solid #dcdcdc !important;
    font-size: 12px !important;
    background: #ffffff !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* ==============================================
   DIAGONAL BLACK
   ============================================== */
  .rr-matrix-table td.bg-light,
  .rr-matrix-table td.bg-diagonal {
    background-color: #f3f5f7 !important;
    background-image: repeating-linear-gradient(135deg, transparent, transparent 6px, #e8ebef 6px, #e8ebef 7px) !important;
    border: 1px solid #e1e5ea !important;
  }

  /* ==============================================
   HEADER — column names (border only, no fill)
   ============================================== */
  .rr-matrix-table thead th {
    padding: 6px 10px !important;
    background: #fff !important;
    color: #0a3566 !important;
    border: 2px solid #0a3566 !important;
    font-weight: 700;
    font-size: 12px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 148px;
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .rr-matrix-table thead th:first-child {
    left: 0;
    min-width: 180px;
    z-index: 5;
  }

  /* ==============================================
   LEFT NAMES — row headers (border only, no fill)
   ============================================== */
  .rr-matrix-table tbody th {
    background: #fff !important;
    color: #0b722e !important;
    border: 2px solid #0b722e !important;
    font-weight: 700;
    font-size: 13px !important;
    padding: 6px 12px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 180px;
    position: sticky;
    left: 0;
    z-index: 2;
  }

  .rr-matrix-table tbody tr:hover > :is(th, td) { background-color: #f7faf9 !important; }
  .rr-matrix-table tbody tr:hover > td.bg-diagonal { background-color: #eef1f3 !important; }

  .rr-score-action {
    display: flex;
    width: 100%;
    min-height: 45px;
    padding: 6px 10px;
    border: 0;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    color: #25324b;
    background: transparent;
    font: inherit;
    line-height: 1.2;
    cursor: pointer;
  }

  .rr-score-action:hover { background: #eaf4f2; }
  .rr-score-action:focus-visible { outline: 3px solid #14796e; outline-offset: -3px; }
  .rr-cell-action { color: #14796e; font-weight: 650; }
  .rr-cell-time { color: #25324b; font-weight: 600; }
  .rr-cell-hint { color: #69778c; font-size: 10px; }
  .rr-mobile-match-list { display: none; }

  .rr-mobile-match {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid #e3e7ee;
    border-radius: 10px;
    background: #fff;
    color: #25324b;
    text-align: left;
  }

  .rr-mobile-match + .rr-mobile-match { margin-top: 8px; }
  .rr-mobile-players { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 650; }
  .rr-mobile-versus { color: #8491a5; font-size: 11px; font-weight: 500; }
  .rr-mobile-status { display: block; margin-top: 6px; color: #14796e; font-size: 12px; }

  /* The public grid has plain schedule text rather than score-entry buttons. */
  .rr-public-view .rr-public-matrices,
  .rr-public-view .rr-group-section { min-width: 0; }
  .rr-public-view .rr-matrix-table {
    width: 100% !important;
    min-width: var(--rr-matrix-width) !important;
  }
  .rr-public-view .rr-matrix-player-column { width: 220px; }
  .rr-public-view .rr-matrix-table :is(td, th) {
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  .rr-public-view .rr-matrix-table td {
    height: auto !important;
    padding: 10px 8px !important;
    line-height: 1.4;
  }
  .rr-public-view .rr-public-match-time,
  .rr-public-view .rr-public-match-venue { display: block; }
  .rr-public-view .rr-public-match-time { color: #27435d; }
  .rr-public-view .rr-public-match-time strong { color: #0d675e; }
  .rr-public-view .rr-public-match-venue { margin-top: 3px; font-size: 11px; color: #617286; }
  .rr-public-view .rr-mobile-players > span { min-width: 0; overflow-wrap: anywhere; }
  .rr-public-view .rr-mobile-status { overflow-wrap: anywhere; }

  /* ==============================================
   SCORE COLORS
   ============================================== */
  .rr-matrix-table .rr-win {
    color: #00a859 !important;
    font-weight: bold;
  }

  .rr-matrix-table .rr-loss {
    color: #d32f2f !important;
    font-weight: bold;
  }

  /* ==============================================
   SORTABLE / DRAG-DROP STYLES
   ============================================== */
  .rr-sortable {
    min-height: 50px;
    border: 2px dashed transparent;
    border-radius: 4px;
    transition: all 0.2s ease;
  }

  .rr-sortable.drop-zone-active {
    border-color: #0d6efd;
    background: rgba(13, 110, 253, 0.05);
  }

  .rr-sortable.sortable-chosen {
    border-color: #0d6efd;
    background: #e7f1ff;
  }

  .rr-sortable .list-group-item {
    cursor: grab !important;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none;
  }
  
  .rr-sortable .list-group-item:active {
    cursor: grabbing !important;
  }

  .rr-sortable .list-group-item:hover {
    background: #f8f9fa;
    transform: translateX(2px);
  }

  .rr-sortable .list-group-item.sortable-ghost {
    opacity: 0.3;
    background: #e3f2fd !important;
    border: 2px dashed #2196f3 !important;
  }
  
  .rr-sortable .list-group-item.sortable-chosen {
    background: #e7f1ff !important;
    border-color: #0d6efd !important;
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.3);
  }
  
  .rr-sortable .list-group-item.sortable-drag {
    background: #fff !important;
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
    opacity: 0.9 !important;
    transform: rotate(2deg);
  }

  /* ── Locked state ── */
  .rr-item-locked {
    cursor: not-allowed !important;
    user-select: none;
    -webkit-user-select: none;
    opacity: 0.75;
  }

  .rr-item-locked:hover {
    background: inherit !important;
    transform: none !important;
  }

  /* Mute the drag handle area when locked */
  .rr-sortable.rr-sortable-locked {
    border-color: transparent !important;
    background: transparent !important;
  }

  .rr-sortable.rr-sortable-locked .list-group-item {
    cursor: not-allowed !important;
  }
  
  /* Ensure fallback clone is visible */
  .sortable-fallback {
    opacity: 0.8 !important;
    background: #fff !important;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25) !important;
  }

  .rr-group {
    border: 2px dashed #dee2e6;
    transition: all 0.2s ease;
  }

  .rr-group.drop-zone-active {
    border-color: #198754;
    background: rgba(25, 135, 84, 0.05);
  }

  .rr-group:empty::after {
    content: 'Drop players here';
    display: block;
    text-align: center;
    color: #adb5bd;
    padding: 20px;
    font-size: 12px;
  }

  /* ==============================================
   BRACKET ZOOM CONTROLS
   ============================================== */
  .bracket-zoom-controls {
    display: flex;
    gap: 6px;
    align-items: center;
  }
  .bracket-zoom-controls .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
  }
  .bracket-zoom-level {
    font-size: 12px;
    min-width: 40px;
    text-align: center;
    color: #666;
  }
  .bracket-zoom-hint {
    display: none;
    font-size: 11px;
    color: #999;
  }
  #bracket-zoom-inner {
    transform-origin: 0 0;
    transition: transform 0.1s ease;
  }

  /* ==============================================
   BRACKET VISUALIZATION STYLES
   ============================================== */
  .bracket-container {
    display: inline-block;
    padding: 15px;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    margin: 10px;
    min-width: 200px;
  }
  
  .bracket-round {
    display: inline-block;
    vertical-align: top;
  }
  
  .bracket-matchup {
    margin: 8px 0;
    position: relative;
    background: white;
    border-radius: 6px;
    padding: 8px;
    border: 1px solid #dee2e6;
  }
  
  .bracket-seed {
    background: white;
    border: 2px solid #0d6efd;
    border-radius: 4px;
    padding: 6px 10px;
    margin: 1px 0;
    min-width: 160px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .bracket-seed.winner {
    background: #d1ecf1;
    border-color: #0dcaf0;
  }
  
  .bracket-seed-num {
    font-weight: bold;
    color: #0d6efd;
    min-width: 35px;
    font-size: 13px;
  }
  
  .bracket-seed-source {
    font-size: 12px;
    color: #fff;
    background: #198754;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: bold;
  }
  
  .bracket-connector {
    position: absolute;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 2px;
    background: #dee2e6;
  }

  /* ==============================================
   RESPONSIVE — SMALL DEVICES
   ============================================== */
  @media (max-width: 767.98px) {
    /* Tab navigation: scrollable pills */
    #rrTabs {
      flex-wrap: nowrap !important;
      overflow-x: auto;
      overflow-y: hidden;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
      white-space: nowrap;
      padding-bottom: 2px;
    }
    #rrTabs::-webkit-scrollbar { display: none; }
    #rrTabs .nav-item { flex-shrink: 0; }
    #rrTabs .nav-link { font-size: 12px; padding: 6px 10px; }

    /* Draw navigator header — stack vertically */
    .card.border-primary .d-flex.justify-content-between {
      flex-direction: column !important;
      align-items: flex-start !important;
      gap: 8px;
    }
    .card.border-primary .d-flex.justify-content-between > div:last-child {
      width: 100%;
      flex-wrap: wrap;
    }

    /* Settings — overview stats: 2 per row */
    #settings-pane .row.g-3 > .col-md-3 { flex: 0 0 50%; max-width: 50%; }

    /* Settings — preset selector full width */
    #settings-pane .col-md-8 { flex: 0 0 100%; max-width: 100%; }

    /* Settings — basic settings cols */
    #settings-pane .col-md-3 { flex: 0 0 100%; max-width: 100%; }

    /* Playoff config position buttons — smaller */
    .position-btn { font-size: 10px !important; padding: 2px 5px !important; }

    /* Groups tab — header stack */
    #groups-pane .alert.d-flex {
      flex-direction: column !important;
      align-items: flex-start !important;
      gap: 8px;
    }
    #groups-pane .alert .d-flex.align-items-center.gap-2 {
      flex-wrap: wrap;
      width: 100%;
    }

    /* Groups — available players + groups: full-width stacked */
    #groups-pane .col-md-4,
    #groups-pane .col-md-8 {
      flex: 0 0 100%;
      max-width: 100%;
    }
    #groups-pane .col-md-8 .col-6 {
      flex: 0 0 100%;
      max-width: 100%;
    }
    /* Reduce group card height on mobile */
    #groups-pane .card-body[style*="min-height: 150px"] {
      min-height: 80px !important;
    }

    /* OOP table — horizontal scroll */
    #oop-pane .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #rr-order-table { min-width: 600px; }
    #rr-order-table th, #rr-order-table td { font-size: 11px; padding: 4px 6px !important; white-space: nowrap; }

    /* Print tab — 2 per row instead of 4 */
    #print-pane .col-md-3 { flex: 0 0 50%; max-width: 50%; }
    #print-pane .card-body.d-flex { padding: 12px 8px !important; }
    #print-pane .card-body i[style*="font-size: 2.5rem"] { font-size: 1.8rem !important; }
    #print-pane h6 { font-size: 12px; }
    #print-pane p.small { font-size: 10px; margin-bottom: 8px !important; }

    /* Bracket SVG wrapper — pinch-to-zoom */
    #main-bracket-wrapper { overflow: auto; -webkit-overflow-scrolling: touch; }
    #main-bracket-wrapper svg { min-width: 800px; }
    .bracket-zoom-controls { display: flex !important; }
    .bracket-zoom-hint { display: block !important; }

    /* Matrix — already scrollable, ensure touch */
    .rr-matrix-scroll { -webkit-overflow-scrolling: touch; }

    /* Bracket visualization containers */
    .bracket-container { min-width: 180px; padding: 10px; margin: 5px; }
    .bracket-seed { min-width: 120px; padding: 4px 6px; font-size: 11px; }
    .bracket-matchup { padding: 5px; margin: 5px 0; }

    /* Score modal — full width on mobile */
    #rrScoreModal .modal-dialog { margin: 8px; max-width: calc(100% - 16px); }

    /* Card header flex items — wrap on small */
    .card-header.d-flex {
      flex-wrap: wrap;
      gap: 6px;
    }
  }

  @media (max-width: 575.98px) {
    /* Extra-small: print cards single column */
    #print-pane .col-md-3 { flex: 0 0 100%; max-width: 100%; }

    /* Groups: reduce source player list height */
    #groups-pane .card-body[style*="max-height: 500px"] {
      max-height: 250px !important;
    }

    /* Standings / matrix heading sizes */
    h5.card-title, .card-header h5 { font-size: 14px; }
    h6.fw-bold { font-size: 13px; }
  }

  @media (max-width: 767.98px) {
    #rr-matrix-wrapper { padding: 12px !important; }
    .rr-matrix-table-shell { display: none; }
    .rr-mobile-match-list { display: block; }
    .rr-group-section + .rr-group-section { margin-top: 24px; }
    .rr-group-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
    .rr-mobile-match:focus-visible { outline: 3px solid #14796e; outline-offset: 2px; }
  }

/* Stack the playoff editor into labelled cards on phones. */
@media (max-width: 767.98px) {
  #playoff-config-table,
  #playoff-config-table tbody {
    display: block;
    width: 100%;
    min-width: 0;
  }
  #playoff-config-table thead { display: none; }
  #playoff-config-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid #dbe3eb;
    border-radius: 10px;
    background: #fff;
  }
  #playoff-config-table tbody td {
    display: block;
    min-width: 0;
    padding: 0 !important;
    border: 0;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  #playoff-config-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: #52637a;
    font-size: 12px;
    font-weight: 600;
  }
  #playoff-config-table td[data-label="Enabled"] { grid-area: 1 / 1; }
  #playoff-config-table td[data-label="Actions"] { grid-area: 1 / 2; text-align: right; }
  #playoff-config-table td[data-label="Playoff name"] { grid-area: 2 / 1 / auto / -1; }
  #playoff-config-table td[data-label="Bracket size"] { grid-area: 3 / 1; }
  #playoff-config-table td[data-label="Preview"] { grid-area: 3 / 2; }
  #playoff-config-table td[data-label="Group positions"] { grid-area: 4 / 1 / auto / -1; }
  #playoff-config-table .playoff-name,
  #playoff-config-table .playoff-size { width: 100% !important; min-width: 0 !important; }
  #playoff-config-table .position-btn {
    min-width: 38px;
    min-height: 32px;
    padding: 5px 7px !important;
    font-size: 12px !important;
  }
  #playoff-config-table td[colspan] { grid-column: 1 / -1; }
}
/* Shared standings: keep rules available without crowding the results. */
.rr-detailed-standings .table { margin-bottom: 0; }
.rr-detailed-standings .table th,
.rr-detailed-standings .table td { padding: .35rem .5rem; }
.rr-detailed-standings .table tbody th { text-transform: none; letter-spacing: normal; }
.rr-standings-information { margin: .5rem 0 .75rem; }
.rr-standings-information > summary {
  display: list-item;
  width: fit-content;
  padding: .5rem .75rem;
  min-height: 44px;
  border: 1px solid #ccd5df;
  border-radius: .375rem;
  cursor: pointer;
  color: #33475b;
  font-size: .875rem;
}
.rr-player-match { border-bottom: 1px solid #e2e7ec; }
.rr-player-match > summary {
  cursor: pointer;
  padding: .5rem 0;
  min-height: 44px;
  overflow-wrap: anywhere;
  line-height: 1.4;
}
.rr-match-counts {
  display: block;
  margin-left: 1rem;
  color: #64748b;
  font-size: .8rem;
  font-weight: normal;
}
.rr-player-match li { font-size: .875rem; }
.rr-detailed-standings summary:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
@media (min-width: 576px) {
  .rr-match-counts { display: inline; margin-left: .75rem; }
}
