/*
 * MOS/Crown-style odds board shell (docs/DECISIONS.md D6). Built only from
 * public/sports/css/tokens.css custom properties; no external fonts/CDNs.
 * Layout notes:
 *  - Desktop (>=768px): each event is a 3-row (home/away/draw) dense CSS
 *    grid row aligned under the .sb-grid-columns header. Market-group
 *    wrappers use `display:contents` so their price cells participate
 *    directly in the outer grid without duplicating markup for mobile.
 *  - Mobile (<768px): the same DOM becomes a card; the six market groups
 *    become a 2x3 mini-grid. Zero horizontal overflow at 375px is a hard
 *    requirement (7KS design QA).
 */

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

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--ivory);
  color: var(--ink);
  font-family: var(--sans);
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- Header ---------- */

.sb-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  min-width: 0;
  padding: 8px 12px;
  background: var(--midnight);
  color: var(--ivory);
  border-bottom: var(--gold-hairline);
}

.sb-wordmark {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--gold-soft);
  white-space: nowrap;
}

.sb-board-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
}

.sb-board-tab {
  padding: 6px 10px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--platinum);
  white-space: nowrap;
}

.sb-board-tab.is-active {
  background: var(--ruby);
  color: var(--pearl);
}

.sb-board-tab.is-disabled {
  opacity: 0.45;
  cursor: default;
}

.sb-header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
  min-width: 0;
}

.sb-select-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--platinum);
}

.sb-select {
  background: var(--midnight-soft);
  color: var(--ivory);
  border: 1px solid var(--line-warm);
  border-radius: var(--radius-md);
  padding: 4px 6px;
  font-size: 0.8rem;
  max-width: 100%;
}

.sb-login-link {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: var(--gold);
  color: var(--midnight);
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Slip drawer toggle badge (header): hidden on desktop, shown <1280px where
   the bet slip becomes an off-canvas drawer instead of a static panel. */
.sb-slip-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--midnight-soft);
  color: var(--ivory);
  border: 1px solid var(--line-warm);
  font-size: 0.8rem;
  cursor: pointer;
}

.sb-slip-badge {
  min-width: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--ruby);
  color: var(--pearl);
  font-size: 0.68rem;
  line-height: 16px;
  text-align: center;
}

/* ---------- Body layout ---------- */

.sb-body {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 280px;
  gap: 12px;
  padding: 12px;
  min-width: 0;
}

.sb-main {
  min-width: 0;
}

/* The centre grid can be narrower than its own content's minimum width
   (fixed time/market columns); it scrolls horizontally inside its own box
   rather than clipping under the sidebar/slip or forcing page-level
   horizontal scroll (controller finding: desktop/tablet clipping). */
.sb-grid-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.sb-ht-toggle {
  display: none;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  background: var(--midnight-soft);
  color: var(--ivory);
  border: 1px solid var(--line-warm);
  font-size: 0.72rem;
  cursor: pointer;
}

.sb-grid-scroll {
  overflow-x: auto;
  min-width: 0;
}

.sb-sidebar {
  min-width: 0;
  background: var(--pearl);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px;
  align-self: start;
}

.sb-sidebar-toggle {
  display: none;
  width: 100%;
  padding: 8px;
  background: var(--midnight);
  color: var(--ivory);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.sb-competition-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sb-competition-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 6px 8px;
  background: none;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.sb-competition-item.is-active,
.sb-competition-item:hover {
  background: var(--paper);
}

.sb-competition-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.sb-slip {
  min-width: 0;
  background: var(--pearl);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
  align-self: start;
}

.sb-slip-title {
  font-family: var(--display);
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.sb-slip-empty {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

/* ---------- Grid header row ---------- */

.sb-grid-columns,
.sb-event-block {
  display: grid;
  grid-template-columns: 56px minmax(200px, 1fr) repeat(6, 86px) 48px;
  align-items: center;
  min-width: max-content;
}

.sb-grid-columns {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--midnight-soft);
  color: var(--platinum);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  padding: 4px 0;
}

/* Sticky first two columns (time, event) while the grid scrolls
   horizontally, so the match identity stays visible under the market
   columns. */
.sb-col-time,
.sb-cell-time {
  position: sticky;
  left: 0;
  z-index: 1;
  background: inherit;
}

.sb-col-event {
  position: sticky;
  left: 56px;
  z-index: 1;
  background: inherit;
}

.sb-cell-team {
  position: sticky;
  left: 56px;
  z-index: 1;
  background: var(--pearl);
  align-self: stretch;
}

.sb-col {
  padding: 0 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Competitions and events ---------- */

.sb-competition {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  /* The surrounding .sb-grid-scroll owns horizontal clipping. Keeping this
     wrapper wide lets the final HT and more-markets columns be scrolled to. */
  overflow: visible;
}

@media (min-width: 768px) {
  .sb-competition {
    min-width: max-content;
  }
}

.sb-competition-header {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--midnight);
  color: var(--gold-soft);
  font-size: 0.8rem;
}

.sb-event-block {
  grid-template-rows: repeat(3, 28px);
  border-top: 1px solid var(--line);
  /* Keep event rows on the identical column track as the sticky header.
     The scroll container, not an event row, owns horizontal clipping. */
  min-width: max-content;
}

.sb-event-block:first-of-type {
  border-top: none;
}

.sb-cell {
  padding: 0 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  font-size: 0.8rem;
}

.sb-cell-time {
  grid-column: 1;
  grid-row: 1 / span 3;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: normal;
}

.sb-cell-time.is-live {
  color: var(--ruby);
  font-weight: 600;
}

.sb-cell-team {
  grid-column: 2;
}

.sb-cell-team-home { grid-row: 1; }
.sb-cell-team-away { grid-row: 2; }
.sb-cell-team-draw { grid-row: 3; color: var(--muted); font-size: 0.72rem; }

.sb-cell-team.is-favourite {
  color: var(--ruby);
}

.sb-cell-team .sb-live-score {
  font-weight: 700;
  margin-left: 6px;
}

.sb-cell-more {
  grid-column: 9;
  grid-row: 1 / span 3;
  justify-content: center;
  color: var(--gold);
  font-weight: 600;
  font-size: 0.72rem;
}

.sb-event-card-header,
.sb-market-groups,
.sb-market-group {
  display: contents;
}

.sb-market-group[data-market-group="ft_hdp"] .sb-price-cell { grid-column: 3; }
.sb-market-group[data-market-group="ft_ou"] .sb-price-cell { grid-column: 4; }
.sb-market-group[data-market-group="ft_1x2"] .sb-price-cell { grid-column: 5; }
.sb-market-group[data-market-group="ht_hdp"] .sb-price-cell { grid-column: 6; }
.sb-market-group[data-market-group="ht_ou"] .sb-price-cell { grid-column: 7; }
.sb-market-group[data-market-group="ht_1x2"] .sb-price-cell { grid-column: 8; }

.sb-market-group .sb-price-cell:nth-of-type(1) { grid-row: 1; }
.sb-market-group .sb-price-cell:nth-of-type(2) { grid-row: 2; }
.sb-market-group .sb-price-cell:nth-of-type(3) { grid-row: 3; }

.sb-price-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--line);
  height: 100%;
}

.sb-price-cell .sb-price-line {
  color: #5b6373;
  font-size: 0.65rem;
}

.sb-price-cell.is-empty {
  visibility: hidden;
}

.sb-price-cell.sb-suspended {
  border-color: #c9bdac;
  background: #ece6da;
  color: #5b6373;
  opacity: 1;
  position: relative;
  cursor: default;
}

.sb-price-cell.sb-suspended .sb-price-line,
.sb-price-cell.sb-suspended .sb-price-selection {
  color: #5b6373;
  opacity: 1;
}

.sb-price-cell.sb-suspended::after {
  content: "\1F512";
  font-size: 0.7rem;
  margin-left: 4px;
}

.sb-price-cell[role="button"] {
  cursor: pointer;
}

.sb-price-cell.sb-up {
  animation: sb-flash-up 1.5s ease-out;
}

.sb-price-cell.sb-down {
  animation: sb-flash-down 1.5s ease-out;
}

@keyframes sb-flash-up {
  0% { background-color: color-mix(in srgb, #1f9d55 45%, transparent); }
  100% { background-color: transparent; }
}

@keyframes sb-flash-down {
  0% { background-color: color-mix(in srgb, var(--ruby) 45%, transparent); }
  100% { background-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .sb-price-cell.sb-up,
  .sb-price-cell.sb-down {
    animation: none;
    background-color: transparent;
  }
}

/* ---------- Loading skeleton (first paint, before the first snapshot) ---------- */

.sb-skeleton-row {
  height: 84px;
  margin-bottom: 8px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--paper) 25%, var(--pearl) 37%, var(--paper) 63%);
  background-size: 400% 100%;
  animation: sb-skeleton 1.4s ease infinite;
}

@keyframes sb-skeleton {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sb-skeleton-row {
    animation: none;
    background: var(--paper);
  }
}

/* ---------- "Added to slip" toast placeholder ---------- */

.sb-toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translate(-50%, 8px);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--midnight);
  color: var(--ivory);
  font-size: 0.8rem;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  z-index: 80;
}

.sb-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .sb-toast {
    transition: none;
    transform: translate(-50%, 0);
  }
}

.sb-no-events {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Event ("more markets") page ---------- */

.sb-event-header {
  padding: 12px;
  margin-bottom: 12px;
  background: var(--pearl);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.sb-event-competition {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sb-event-teams {
  margin: 0 0 6px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.3rem;
}

.sb-event-vs {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 6px;
}

.sb-event-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.sb-event-clock.is-live {
  color: var(--ruby);
  font-weight: 600;
  margin-right: 8px;
}

.sb-event-score {
  font-weight: 700;
  color: var(--ink);
}

.sb-market-group-block {
  margin-bottom: 14px;
}

.sb-market-group-heading {
  margin: 0 0 6px;
  padding: 6px 10px;
  background: var(--midnight);
  color: var(--gold-soft);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-family: var(--display);
  font-weight: 600;
}

.sb-event-market-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
}

.sb-event-market-line {
  min-width: 48px;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.sb-event-market-cells {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.sb-event-price-cell {
  flex-direction: row;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  height: auto;
}

.sb-price-selection {
  color: #5b6373;
  font-size: 0.72rem;
  text-transform: uppercase;
}

/* ---------- Mobile bottom tab bar ---------- */

.sb-mobile-tabs {
  display: none;
}

.sb-mobile-market-label {
  display: none;
}

/* ---------- Responsive breakpoints ---------- */

/* 1024-1279: the bet slip collapses into a header-toggled drawer so the
   centre grid gets its freed width (controller finding: HT columns and the
   more-markets link were clipped under the slip panel at this width). */
@media (max-width: 1279px) {
  .sb-body {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .sb-slip-toggle {
    display: inline-flex;
  }

  .sb-slip {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(320px, 90vw);
    z-index: 60;
    margin: 0;
    overflow-y: auto;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.25s var(--ease);
    box-shadow: var(--shadow-lift);
    visibility: hidden;
    pointer-events: none;
  }

  .sb-slip.is-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }
}

@media (max-width: 1023px) {
  .sb-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .sb-sidebar {
    grid-column: 1 / -1;
  }

  .sb-sidebar-toggle {
    display: block;
  }

  .sb-competition-nav {
    display: none;
  }

  .sb-sidebar.is-open .sb-competition-nav {
    display: block;
  }
}

/* 768-1023: table rows are kept, but the HT columns hide behind a toggle by
   default to fit the narrower centre width (controller finding). */
@media (min-width: 768px) and (max-width: 1023px) {
  .sb-ht-toggle {
    display: inline-flex;
  }

  #sb-app:not(.is-ht-open) .sb-grid-columns,
  #sb-app:not(.is-ht-open) .sb-event-block {
    grid-template-columns: 56px minmax(200px, 1fr) repeat(3, 86px) 48px;
  }

  #sb-app:not(.is-ht-open) [data-market-group^="ht_"] {
    display: none;
  }

  #sb-app:not(.is-ht-open) .sb-cell-more {
    grid-column: 6;
  }
}

@media (max-width: 767px) {
  .sb-body {
    display: block;
    padding: 8px;
  }

  .sb-sidebar,
  .sb-slip {
    margin-bottom: 8px;
  }

  .sb-grid-columns {
    display: none;
  }

  .sb-event-block {
    display: block;
    grid-template-columns: none;
    min-width: 0;
    background: var(--pearl);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    padding: 6px;
  }

  .sb-event-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--line);
  }

  .sb-event-card-header {
    display: flex;
  }

  .sb-cell-time,
  .sb-cell-team,
  .sb-cell-more {
    position: static;
    grid-column: auto;
    grid-row: auto;
    white-space: normal;
  }

  .sb-cell-team-draw {
    display: none;
  }

  .sb-market-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    margin-top: 6px;
  }

  .sb-market-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 4px;
  }

  /* Truly absent groups (no market object; suspended/offered markets are
     marked by JS instead) are omitted on mobile so match cards stay dense.
     Desktop keeps them (display: contents) for table column alignment. */
  .sb-market-group.is-absent {
    display: none;
  }

  .sb-mobile-market-label {
    display: block;
    color: var(--muted);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1.2;
    padding: 1px 0 4px;
    text-transform: uppercase;
  }

  .sb-market-group .sb-price-cell {
    grid-column: auto !important;
    grid-row: auto !important;
    flex-direction: row;
    justify-content: space-between;
    border-left: none;
    border-top: 1px solid var(--line);
    height: auto;
    padding: 2px 0;
  }

  .sb-market-group .sb-price-cell:first-of-type {
    border-top: none;
  }

  .sb-mobile-tabs {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    background: var(--midnight);
    border-top: var(--gold-hairline);
    padding: 6px 0;
  }

  .sb-mobile-tab {
    color: var(--platinum);
    font-size: 0.7rem;
    text-align: center;
    padding: 4px 6px;
  }
}

@media (min-width: 768px) {
  .sb-mobile-tabs {
    display: none;
  }
}

/* ---------- Print ---------- */

@media print {
  .sb-header,
  .sb-sidebar,
  .sb-slip,
  .sb-mobile-tabs {
    display: none;
  }

  .sb-body {
    display: block;
    padding: 0;
  }

  .sb-event-block {
    grid-template-rows: repeat(3, 16px);
  }
}
