/* Final mobile schedule overrides. Loaded last on index.html. */
@media (max-width: 700px) {
  /* Normal rounds only. These selectors deliberately match the high specificity
     in mobile-schedule.css so the final layout cannot be overwritten. */
  html body #schedule :is(
    #sched-div1:not(:has(#week1 option:checked[value="21"])):not(:has(#week1 option:checked[value="22"])),
    #sched-div2:not(:has(#week2 option:checked[value="21"])):not(:has(#week2 option:checked[value="22"])),
    #sched-div3:not(:has(#week3 option:checked[value="20"])):not(:has(#week3 option:checked[value="21"])):not(:has(#week3 option:checked[value="22"]))
  ) .schedule-table tbody tr {
    grid-template-columns: minmax(96px, 1fr) 58px minmax(96px, 1fr) !important;
    grid-template-rows: auto auto auto !important;
    background: #ffffff !important;
  }

  /* Alternating backgrounds: white / clearly visible light blue. */
  html body #schedule :is(
    #sched-div1:not(:has(#week1 option:checked[value="21"])):not(:has(#week1 option:checked[value="22"])),
    #sched-div2:not(:has(#week2 option:checked[value="21"])):not(:has(#week2 option:checked[value="22"])),
    #sched-div3:not(:has(#week3 option:checked[value="20"])):not(:has(#week3 option:checked[value="21"])):not(:has(#week3 option:checked[value="22"]))
  ) .schedule-table tbody tr:nth-child(odd) {
    background: #ffffff !important;
    border-color: #dbe4ed !important;
  }

  html body #schedule :is(
    #sched-div1:not(:has(#week1 option:checked[value="21"])):not(:has(#week1 option:checked[value="22"])),
    #sched-div2:not(:has(#week2 option:checked[value="21"])):not(:has(#week2 option:checked[value="22"])),
    #sched-div3:not(:has(#week3 option:checked[value="20"])):not(:has(#week3 option:checked[value="21"])):not(:has(#week3 option:checked[value="22"]))
  ) .schedule-table tbody tr:nth-child(even) {
    background: #e6f0f8 !important;
    border-color: #c7d9e8 !important;
  }

  /* Cells must not paint over the card background. */
  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr > td {
    background-color: transparent !important;
  }

  /* Date: first column, always exactly one line. */
  html body #schedule :is(
    #sched-div1:not(:has(#week1 option:checked[value="21"])):not(:has(#week1 option:checked[value="22"])),
    #sched-div2:not(:has(#week2 option:checked[value="21"])):not(:has(#week2 option:checked[value="22"])),
    #sched-div3:not(:has(#week3 option:checked[value="20"])):not(:has(#week3 option:checked[value="21"])):not(:has(#week3 option:checked[value="22"]))
  ) .schedule-table tbody tr td:nth-child(2) {
    grid-column: 1 !important;
    grid-row: 1 !important;
    width: max-content !important;
    min-width: max-content !important;
    max-width: none !important;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    hyphens: none !important;
    text-align: left !important;
  }

  html body #schedule :is(
    #sched-div1:not(:has(#week1 option:checked[value="21"])):not(:has(#week1 option:checked[value="22"])),
    #sched-div2:not(:has(#week2 option:checked[value="21"])):not(:has(#week2 option:checked[value="22"])),
    #sched-div3:not(:has(#week3 option:checked[value="20"])):not(:has(#week3 option:checked[value="21"])):not(:has(#week3 option:checked[value="22"]))
  ) .schedule-table tbody tr td:nth-child(3) {
    grid-column: 2 !important;
    grid-row: 1 !important;
    text-align: center !important;
  }

  /* Home / result / away. */
  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr td:nth-child(4) {
    grid-column: 1 !important;
    grid-row: 2 !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr td:nth-child(5) {
    grid-column: 2 !important;
    grid-row: 2 !important;
    background: rgba(255,255,255,.72) !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr td:nth-child(7) {
    grid-column: 3 !important;
    grid-row: 2 !important;
  }

  /* The old combined team-points cell is hidden on mobile. Each team's points
     are shown directly below the corresponding team name. */
  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr.mobile-points-ready td:nth-child(6) {
    display: none !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr.mobile-points-ready td:nth-child(4)::after,
  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr.mobile-points-ready td:nth-child(7)::after {
    content: "LP " attr(data-team-points) !important;
    display: block !important;
    width: fit-content !important;
    margin-top: 5px !important;
    padding: 2px 7px !important;
    border-radius: 999px !important;
    background: rgba(31,58,95,.08) !important;
    color: #657487 !important;
    font-size: .58rem !important;
    font-weight: 700 !important;
    line-height: 1.35 !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr.mobile-points-ready td:nth-child(7)::after {
    margin-left: auto !important;
  }

  /* Trasseltjänst / omgång at bottom-left. */
  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr td:nth-child(1) {
    grid-column: 1 / -1 !important;
    grid-row: 3 !important;
  }

  /* Excel at bottom-right when available. */
  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr:has(.match-document-cell a) td:nth-child(1) {
    grid-column: 1 / 3 !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr .match-document-cell {
    grid-column: 3 !important;
    grid-row: 3 !important;
    align-self: end !important;
    justify-self: end !important;
    margin: 1px 0 0 !important;
    padding: 7px 0 0 !important;
    border: 0 !important;
    border-top: 1px solid #dce6ef !important;
    background: transparent !important;
    text-align: right !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr .match-document-cell:not(:has(a)) {
    display: none !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr .match-document-cell::after {
    content: none !important;
  }

  html body #schedule :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr .match-document-cell .public-download-link {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 28px !important;
    padding: 5px 9px !important;
    border: 1px solid rgba(31,58,95,.12) !important;
    border-radius: 8px !important;
    background: rgba(255,255,255,.72) !important;
    color: #1f3a5f !important;
    font-size: .62rem !important;
    font-weight: 800 !important;
    line-height: 1 !important;
    text-decoration: none !important;
    white-space: nowrap !important;
  }

  /* Correct labels. */
  html body #schedule:has(#teamFilter option:checked[value=""]) :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr td:nth-child(1)::before {
    content: "Trasseltjänst: " !important;
  }

  html body #schedule:has(#teamFilter option:checked:not([value=""])) :is(#sched-div1, #sched-div2, #sched-div3) .schedule-table tbody tr td:nth-child(1)::before {
    content: "Omgång: " !important;
  }
}
