/* ==========================================================================
   Mobile-first hardening — tap targets, fluid header, no sideways scroll.
   Applied unconditionally (these rules are safe on desktop too).
   ========================================================================== */
:root {
  --tap-min: 44px;
  --bottom-nav-h: 60px;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  -webkit-text-size-adjust: 100%;
  /* Ensure content clears both bottom-nav + potential unlock bar with safe area */
  padding-bottom: calc(var(--bottom-nav-h) + 72px + env(safe-area-inset-bottom, 16px));
  box-sizing: border-box;
}

/* All buttons: prevent double-tap zoom and give tactile feedback */
button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  opacity: 0.85;
}

/* Stop iOS auto-zoom on input focus (font-size must be >= 16px) */
input, select, textarea {
  font-size: 16px !important;
  touch-action: manipulation;
}

/* ==========================================================================
   Topbar — fluid, no overflow at any width
   ========================================================================== */
.topbar {
  padding: 10px 12px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
  margin-bottom: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-shrink: 1;
}

.brand-text h1 {
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin-left: auto;
}

/* Compact action buttons */
.topbar-export-btn,
.topbar-admin-btn,
.api-tag,
.how-btn {
  min-height: 40px;
  min-width: 40px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

/* Ensure minimum readable typography for accessibility (WCAG 2.2 AA) */
.meta-date,
.free-tag,
.alias-arrow,
.admin-review-pair small,
.edge-pill,
.elo-pill,
.team-meta span {
  font-size: 11px;
}

/* Scrollable tabs / filter / market bars */
.tabs,
.market-bar,
.filter-bar {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.tabs {
  gap: 4px;
  padding: 3px 3px 6px;
}

.tab {
  min-height: var(--tap-min);
  padding: 10px 12px;
  font-size: 12px;
  flex: 0 0 auto;
}

.market-chip,
.day-chip,
.filter-chip {
  min-height: 42px;
  padding: 9px 13px;
}

/* ==========================================================================
   Main content area
   ========================================================================== */
#content {
  padding: 10px 12px;
}

/* Search input — font-size 16px already set above via input rule */
.search-bar input {
  font-size: 16px;
}

.search-clear {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

/* ==========================================================================
   Fixture cards
   ========================================================================== */
.fixture-row {
  padding: 12px;
  border-radius: 14px;
}

.fixture-row-header {
  gap: 8px;
}

.fixture-call {
  row-gap: 6px;
}

/* Market grid inside expanded fixture drawer */
.market-grid {
  grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
}

/* Settlement stats card — 2-col on very narrow screens */
@media (max-width: 380px) {
  .settlement-card {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Copy button tap target */
.copy-btn,
.rec-copy,
.hero-copy,
.modal-close,
.vip-upsell-btn,
.bet-tier-chip,
.slip-config-chip,
.road-build-btn {
  min-height: var(--tap-min);
}

.copy-btn {
  padding: 10px 14px;
  font-size: 12px;
}

/* ==========================================================================
   Bottom Navigation Bar  (shown on mobile only via @media below)
   ========================================================================== */
.bottom-nav {
  display: none;
}

@media (max-width: 767px) {
  /* Hide desktop tab row — bottom-nav takes over */
  .tabs {
    display: none;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* Height = nav area + iOS home-bar safe area */
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(15, 23, 42, 0.97);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 100;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 0;
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--hint);
    padding: 10px 6px 6px;
    cursor: pointer;
    border-radius: 10px;
    transition: color 0.18s, background 0.18s;
    flex: 1;
    text-decoration: none;
    min-height: 56px;
    position: relative;
  }

  /* Active state: soft pill background */
  .bottom-nav-item.active {
    color: var(--link);
  }

  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--link);
    border-radius: 2px;
  }

  .bottom-nav-icon {
    font-size: 19px;
    line-height: 1;
    margin-bottom: 3px;
    margin-top: 4px;
  }

  .bottom-nav-label {
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  /* Unlock bar sits above bottom-nav */
  .unlock-bar {
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }

  /* Prevent bottom nav and unlock bar from overlapping modals/popups */
  body.modal-open .bottom-nav,
  body.modal-open .unlock-bar {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  /* Comprehensive scroll clearance so bottom items are never covered */
  #content {
    padding-bottom: calc(var(--bottom-nav-h) + 40px + env(safe-area-inset-bottom, 0px));
  }

  .trust-block {
    padding-bottom: calc(var(--bottom-nav-h) + 72px + env(safe-area-inset-bottom, 16px)) !important;
  }

  .vip-upsell {
    margin-bottom: 24px;
  }

  .admin-dashboard {
    padding-bottom: calc(var(--bottom-nav-h) + 64px + env(safe-area-inset-bottom, 16px)) !important;
  }
}

/* ==========================================================================
   Toast — sits above modals & bottom-nav
   ========================================================================== */
.toast {
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
  z-index: 10000 !important;
  /* On mobile sit above bottom-nav */
  bottom: calc(var(--bottom-nav-h) + 64px + env(safe-area-inset-bottom, 0px));
}

/* ==========================================================================
   Modals — slide up from bottom on mobile, sit above all navbars
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999 !important;
  background: rgba(10, 15, 29, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom, 0px)) 12px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  box-sizing: border-box;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(88vh - env(safe-area-inset-bottom, 0px));
  max-height: calc(88dvh - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 20px 20px 16px 16px;
  box-sizing: border-box;
  margin-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

/* ==========================================================================
   Betslip / Road components
   ========================================================================== */
.bet-tiers-bar,
.slip-config-chips {
  padding-bottom: 4px;
}

.bet-tier-chip {
  flex: 0 0 auto;
}

.slip-card,
.rec-card,
.hero-card,
.vip-upsell-card {
  overflow-wrap: anywhere;
}

.slip-leg {
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.slip-leg-pick {
  overflow-wrap: anywhere;
}

.road-table-wrap {
  margin: 0 -4px 14px;
}

.road-form {
  grid-template-columns: repeat(2, 1fr);
}

.road-field input,
.slip-config-toggle {
  min-height: var(--tap-min);
}

/* ==========================================================================
   Admin dashboard grid — prevent overflow on narrow screens
   ========================================================================== */
.admin-stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

.admin-form-row {
  flex-direction: column;
  align-items: stretch;
}

.admin-input,
.admin-select {
  min-width: 0;
  width: 100%;
}

.admin-input-small {
  width: 100%;
  text-align: left;
}

.admin-btn-row {
  flex-direction: column;
}

.admin-outline-btn,
.admin-action-btn {
  min-height: var(--tap-min);
  width: 100%;
  text-align: center;
}

/* ==========================================================================
   Extra-small screens (≤ 380px)
   ========================================================================== */
@media (max-width: 380px) {
  .brand-mark {
    display: none; /* hide BW mark to save space */
  }

  .brand-text h1 {
    font-size: 15px;
  }

  .sub-brand {
    display: none;
  }

  .how-btn span,
  .how-btn-text {
    display: none; /* hide label, keep icon */
  }

  .hero-match {
    font-size: 15px;
  }

  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-copy {
    width: 100%;
  }

  .trust-grid {
    grid-template-columns: 1fr;
  }

  .steps {
    flex-direction: column;
  }

  /* Market grid: 2 columns on tiny screens */
  .market-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==========================================================================
   Tablet / wide layout (≥ 768px) — centre-constrain all sections
   ========================================================================== */
@media (min-width: 768px) {
  body {
    padding-bottom: 80px; /* no bottom-nav on desktop */
  }

  #content,
  .hero,
  .legend,
  .trust-block,
  .vip-upsell {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }

  .topbar-row,
  .tabs,
  .market-bar,
  .filter-bar {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }

  .unlock-bar {
    bottom: 0; /* sits at very bottom on desktop — no bottom-nav */
  }

  .toast {
    bottom: 80px;
  }
}

/* ==========================================================================
   Accessibility: honour reduced-motion preference
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Ensure images and tables never cause horizontal scroll */
img,
table {
  max-width: 100%;
}
