/* ── RESET & BASE ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:        #0F6E56;
  --green-light:  #E1F5EE;
  --green-dark:   #085041;
  --blue:         #185FA5;
  --blue-light:   #E6F1FB;
  --amber:        #BA7517;
  --amber-light:  #FAEEDA;
  --red:          #A32D2D;
  --red-light:    #FCEBEB;
  --gray:         #888780;
  --gray-light:   #F1EFE8;
  --bg:           #FAFAF9;
  --surface:      #FFFFFF;
  --border:       rgba(0,0,0,0.08);
  --border-strong:rgba(0,0,0,0.14);
  --text:         #1A1A18;
  --text-muted:   #6B6A63;
  /* Was #9E9D96, which measured 2.72:1 on white and failed WCAG AA for normal
     text. #767570 measures 4.62:1 and keeps the muted/hint hierarchy intact. */
  --text-hint:    #767570;
  --sidebar-w:    240px;
  --font-head:    'Syne', sans-serif;
  --font-mono:    'IBM Plex Mono', monospace;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* 100vh is taller than the visible area on mobile (browser chrome is not
     subtracted), which pushed the bottom nav off-screen. dvh tracks the real
     viewport; the vh line stays as a fallback for older browsers. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── LAYOUT ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ── SIDEBAR ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--green);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.logo-text {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 700;
  color: var(--green);
  line-height: 1.2;
}

.logo-sub {
  font-size: 10px;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
  transition: all .15s;
  position: relative;
  font-family: inherit;
}

.nav-item:hover { background: var(--gray-light); color: var(--text); }
.nav-item.active { background: var(--green-light); color: var(--green); font-weight: 500; }

.nav-badge {
  margin-left: auto;
  background: var(--green);
  color: white;
  font-size: 10px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.sidebar-settings-compact {
  margin: auto 0 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.compact-setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.compact-label { font-size: 11px; color: var(--text-muted); display: inline-flex; align-items: center; }
.compact-value { font-family: var(--font-mono); font-size: 11px; font-weight: 500; color: var(--text-muted); }

/* Separates capital figures from the strategy knobs that drive sizing. */
.compact-group-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-hint);
  margin-top: 6px;
}
.compact-group-label:first-child { margin-top: 0; }

/* ── INLINE JARGON TOOLTIP ────────────────────────────────────────────────
   A real <button> so it is keyboard-reachable, and shown on :focus as well as
   :hover so a tap works where there is no hover state. Width is capped to the
   panel because .sidebar scrolls and would clip anything wider. */
.compact-setting { position: relative; }
.hint {
  border: none;
  background: none;
  padding: 0 0 0 4px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  cursor: help;
  color: var(--text-hint);
  line-height: 1;
}
.hint .ico { width: 12px; height: 12px; }
.hint:hover, .hint:focus-visible { color: var(--green); }
.hint::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  z-index: 60;
  background: var(--text);
  color: #fff;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.hint:hover::after, .hint:focus::after { opacity: 1; }

.sidebar-source {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-hint);
}

.source-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
  transition: background .3s;
}
.source-dot.live    { background: var(--green); box-shadow: 0 0 0 3px var(--green-light); }
.source-dot.demo    { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-light); }
.source-dot.error   { background: var(--red);   box-shadow: 0 0 0 3px var(--red-light); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  color: var(--text-hint);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-light);
}

/* ── MAIN ────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
  /* Stop the scroll chaining that triggers pull-to-refresh / body rubber-band
     when the panel is already at its top or bottom. */
  overscroll-behavior-y: contain;
}

.tab-panel { display: none; flex-direction: column; flex: 1; padding: 28px 32px; gap: 20px; }
.tab-panel.active { display: flex; }

/* ── PANEL HEADER ─────────────────────────────────────────────────────────── */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.panel-title {
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.panel-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── SPORT FILTERS ────────────────────────────────────────────────────────── */
.sport-filters {
  display: flex;
  gap: 4px;
  background: var(--gray-light);
  padding: 4px;
  border-radius: 10px;
}

.sub-filters {
  flex-wrap: wrap;
  width: 100%;
}

.sub-filters .sport-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  padding: 3px 10px;
}

.sub-filters .sport-btn.active {
  background: var(--green-light);
  color: var(--green-dark);
  border-color: var(--green);
}

.sport-btn, .market-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  white-space: nowrap;
}
.sport-btn.active, .market-btn.active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
/* ── ICONS ────────────────────────────────────────────────────────────────
   Sprite symbols carry no presentation of their own so a single class can
   size and colour them; they inherit the text colour of whatever they sit in. */
.ico {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  vertical-align: -0.18em;
}
.panel-title .ico { width: 1em; height: 1em; vertical-align: -0.08em; margin-right: 6px; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn-primary:hover { opacity: .9; }

/* Secondary/ghost. .btn-refresh is the long-standing name; .btn-ghost is the
   semantic alias so new markup doesn't have to claim to be a refresh button.
   Every non-primary header action uses this — no second accent colour. */
.btn-refresh, .btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all .15s;
}
.btn-ghost:hover { background: var(--gray-light); color: var(--text); }

.btn-refresh:hover { background: var(--gray-light); color: var(--text); }
.btn-refresh.spinning svg, .btn-ghost.spinning svg { animation: spin .6s linear infinite; }

/* ── MATCHES GRID ─────────────────────────────────────────────────────────── */
.matches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: default;
  transition: border-color .15s, box-shadow .15s;
}
.match-card:hover { border-color: var(--border-strong); box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.match-card.has-selection { border-color: var(--green); }

.match-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.match-league-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.sport-pip {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pip-football   { background: var(--green); }
.pip-tennis     { background: var(--blue); }
.pip-basketball { background: var(--amber); }

.match-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-hint);
}

.match-teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.team-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}
.team-name.away { text-align: right; }

.vs-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-hint);
  text-align: center;
}

/* ── ODDS BUTTONS ─────────────────────────────────────────────────────────── */
.odds-grid {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}
.odds-grid.three { grid-template-columns: repeat(3, 1fr); }
.odds-grid.two   { grid-template-columns: repeat(2, 1fr); }

.odd-btn {
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  position: relative;
}
.odd-btn:hover { border-color: var(--green); background: var(--green-light); }
.odd-btn.selected {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.odd-header { font-size: 10px; color: var(--text-hint); margin-bottom: 2px; }
.odd-btn.selected .odd-header { color: rgba(255,255,255,.65); }

.odd-value { font-family: var(--font-mono); font-size: 15px; font-weight: 500; }

.odd-prob  { font-size: 9px; color: var(--text-hint); margin-top: 1px; }
.odd-btn.selected .odd-prob { color: rgba(255,255,255,.6); }

/* ── ODDS CARD: VERDICT-LED HIERARCHY ──────────────────────────────────────
   The value verdict is the decision signal, so it reads first; the edge delta
   and model probability sit under it as supporting metadata. */
.odd-verdict {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: .1px;
  white-space: nowrap;
}
.odd-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-hint);
  margin-top: 3px;
}
/* Colour only the delta, not the whole metadata line — deliberately not the
   .tag-* classes, which also paint a background. */
.odd-delta.up   { color: var(--green); }
.odd-delta.down { color: var(--red); }
.odd-delta.flat { color: var(--text-hint); }
.odd-btn.selected .odd-delta { color: rgba(255,255,255,.85); }

/* Tier colours — one source of truth for the verdict chip. */
.tier-negative .odd-verdict { background: var(--red-light);   color: var(--red); }
.tier-marginal .odd-verdict { background: var(--gray-light);  color: var(--text-muted); }
.tier-low      .odd-verdict { background: var(--green-light); color: var(--green); }
.tier-medium   .odd-verdict { background: var(--amber-light); color: var(--amber); }
.tier-high     .odd-verdict { background: var(--red-light);   color: var(--red); }

/* Left edge tint so a long list can be scanned for genuine value at a glance. */
.odd-btn.tier-low    { border-left: 3px solid var(--green); }
.odd-btn.tier-medium { border-left: 3px solid var(--amber); }
.odd-btn.tier-high   { border-left: 3px solid var(--red); }

/* Selected state inverts the card, so the chip has to stay legible on green. */
.odd-btn.selected .odd-verdict {
  background: rgba(255,255,255,.22);
  color: #fff;
}
.odd-btn.selected .odd-meta { color: rgba(255,255,255,.7); }
.odd-btn.selected { border-left-color: var(--green-dark); }

.odd-edge-tag {
  position: absolute;
  top: -7px;
  right: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 500;
}
.tag-positive { background: var(--green-light); color: var(--green); }
.tag-negative { background: var(--red-light);   color: var(--red); }
.tag-neutral  { background: var(--gray-light);  color: var(--gray); }

/* ── EDGE BAR ─────────────────────────────────────────────────────────────── */
.edge-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.edge-bar-label { font-size: 10px; color: var(--text-hint); white-space: nowrap; }
.edge-bar-track { flex: 1; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.edge-bar-fill  { height: 100%; border-radius: 2px; transition: width .4s; }
.fill-positive  { background: var(--green); }
.fill-negative  { background: var(--red); }
.edge-bar-val   { font-family: var(--font-mono); font-size: 10px; min-width: 40px; text-align: right; }
.val-positive   { color: var(--green); }
.val-negative   { color: var(--red); }

/* ── METHOD TABS ──────────────────────────────────────────────────────────── */
.method-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
}
.method-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
  font-family: inherit;
}
.method-tab:hover { color: var(--text); }
.method-tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 500; }

/* ── PORTFOLIO CONTENT ────────────────────────────────────────────────────── */
.portfolio-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-hint); margin-bottom: 4px; }
.metric-value { font-family: var(--font-mono); font-size: 20px; font-weight: 500; line-height: 1.2; }
.metric-sub   { font-size: 11px; color: var(--text-hint); margin-top: 3px; }
.positive { color: var(--green); }
.negative { color: var(--red); }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-hint);
  margin-bottom: 10px;
}

/* ── ALLOCATION BARS ──────────────────────────────────────────────────────── */
.allocations-list { display: flex; flex-direction: column; gap: 10px; }

.alloc-row {
  display: grid;
  grid-template-columns: 1fr 2fr 60px 70px;
  gap: 12px;
  align-items: center;
}

.alloc-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-bar-track { height: 5px; background: var(--gray-light); border-radius: 3px; overflow: hidden; }
.alloc-bar-fill  { height: 100%; border-radius: 3px; transition: width .4s; }
.alloc-pct  { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); text-align: right; }
.alloc-mise { font-family: var(--font-mono); font-size: 12px; font-weight: 500; text-align: right; }

/* ── BET TABLE ────────────────────────────────────────────────────────────── */
.bet-table-wrap { overflow-x: auto; }
.bet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.bet-table th {
  text-align: left;
  padding: 7px 12px;
  color: var(--text-hint);
  font-weight: 400;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.bet-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.bet-table tr:last-child td { border-bottom: none; }
.bet-table tr:hover td { background: var(--bg); }

.kelly-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
}
.kelly-good   { background: var(--green-light); color: var(--green); }
.kelly-low    { background: var(--amber-light); color: var(--amber); }
.kelly-skip   { background: var(--gray-light);  color: var(--gray); }

/* ── FRONTIER CHART ───────────────────────────────────────────────────────── */
.frontier-layout { display: flex; flex-direction: column; gap: 20px; }
.frontier-chart-wrap { position: relative; width: 100%; height: 400px; }

.frontier-legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-dot  { width: 8px;  height: 8px;  border-radius: 50%; flex-shrink: 0; }
.legend-line { width: 20px; height: 2px;  border-radius: 1px; flex-shrink: 0; }

.methods-comparison {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.comparison-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.comparison-card.highlighted { border-color: var(--green); }
.comparison-method { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-hint); margin-bottom: 8px; }
.comparison-sharpe { font-family: var(--font-mono); font-size: 22px; font-weight: 500; }
.comparison-details { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.comparison-detail { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; }
.comparison-detail .val { font-family: var(--font-mono); }

/* ── SETTINGS ─────────────────────────────────────────────────────────────── */
.settings-layout { display: flex; flex-direction: column; gap: 16px; }
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.settings-card-title { font-size: 14px; font-weight: 600; margin-bottom: 16px; }

.setting-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

.setting-label { font-size: 13px; }
.setting-hint  { display: block; font-size: 11px; color: var(--text-hint); margin-top: 2px; }
.setting-control { display: flex; align-items: center; gap: 12px; }
.setting-value { font-family: var(--font-mono); font-size: 13px; min-width: 60px; text-align: right; white-space: nowrap; }

.settings-info { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

.explainer { display: flex; flex-direction: column; gap: 12px; }
.explainer-item { padding: 10px; background: var(--bg); border-radius: 8px; }
.explainer-title { font-size: 12px; font-weight: 600; color: var(--green); margin-bottom: 4px; }
.explainer-body  { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

.disclaimer {
  font-size: 11px;
  color: var(--text-hint);
  line-height: 1.6;
  padding: 12px;
  background: var(--amber-light);
  border-radius: 8px;
  border-left: 3px solid var(--amber);
}

/* ── LOADING & EMPTY STATES ───────────────────────────────────────────────── */
.loading-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── SKELETONS ────────────────────────────────────────────────────────────
   Placeholders shaped like the content that is about to arrive. A spinner
   says "wait"; a skeleton says "here is what you are getting", which reads as
   faster even at identical latency. */
.skel {
  background: linear-gradient(90deg, var(--gray-light) 25%, #E6E4DC 37%, var(--gray-light) 63%);
  background-size: 400% 100%;
  animation: skel-shimmer 1.3s ease infinite;
  border-radius: 6px;
}
@keyframes skel-shimmer {
  from { background-position: 100% 50%; }
  to   { background-position: 0 50%; }
}
.skel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}
.empty-icon { opacity: .2; }
.empty-state h3 { font-size: 16px; font-weight: 500; color: var(--text); }
.empty-state p  { font-size: 13px; max-width: 400px; }

/* ── CARD TABLE ───────────────────────────────────────────────────────────── */
.card-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.card-section-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── UTILITIES ────────────────────────────────────────────────────────────── */
.mono { font-family: var(--font-mono); }

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.modal.visible {
  display: flex;
}
.modal-content {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 800px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--text-main);
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #999;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text-main);
}
.best-bet-card.clickable {
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.best-bet-card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-color: var(--green);
}

/* ── CUSTOM RANGE ────────────────────────────────────────────────────────── */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  flex: 1;
  background: transparent;
  cursor: pointer;
  --value: 50%;
}
input[type=range]:focus {
  outline: none;
}
/* WebKit (Chrome, Safari, Edge) */
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background: linear-gradient(to right, var(--green) 0%, var(--green) var(--value), #e0e0e0 var(--value), #e0e0e0 100%);
  border-radius: 4px;
  border: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--green);
  margin-top: -7px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 2.5px solid white;
}
input[type=range]:hover::-webkit-slider-thumb {
  transform: scale(1.2);
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}
/* Mozilla (Firefox) */
input[type=range]::-moz-range-track {
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 4px;
  border: none;
}
input[type=range]::-moz-range-progress {
  height: 6px;
  background: var(--green);
  border-radius: 4px;
}
input[type=range]::-moz-range-thumb {
  height: 16px;
  width: 16px;
  border: 2.5px solid white;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.15s ease;
}
input[type=range]:hover::-moz-range-thumb {
  transform: scale(1.2);
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.anim-in { animation: fadeIn .25s ease; }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .portfolio-metrics { grid-template-columns: repeat(2, 1fr); }
  .methods-comparison { grid-template-columns: 1fr; }
  .tab-panel { padding: 20px 16px; }
}

@media (max-width: 700px) {
  /* Hide desktop sidebar, show bottom tab bar */
  .sidebar { display: none; }
  /* Clear the fixed bottom nav *and* the home-indicator inset beneath it. */
  .main {
    margin-left: 0 !important;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .tab-panel { padding: 16px 12px !important; }

  /* iOS Safari force-zooms the whole page whenever a focused field is under
     16px. Every text-entry control has to clear that bar — the visual size is
     tuned back via padding, not font-size. */
  input[type="text"],
  input[type="number"],
  input[type="password"],
  input[type="email"],
  input[type="search"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Touch feedback: the default highlight is suppressed globally on body, so
     give pressable things an explicit pressed state instead. */
  button:active,
  .btn-primary:active,
  .sport-btn:active,
  .suivi-btn:active,
  .bt-pill:active,
  .nav-item:active {
    transform: scale(0.97);
    opacity: 0.85;
  }
  button, .sport-btn, .bt-pill, .suivi-btn {
    touch-action: manipulation; /* removes the 300ms double-tap-zoom delay */
  }

  /* Tap targets: the desktop pills sit around 28px tall, well under a
     comfortable thumb target. Grow them on phones only. */
  .sport-btn, .market-btn, .bt-pill {
    padding: 9px 14px !important;
    font-size: 13px !important;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
  .sub-filters .sport-btn {
    padding: 7px 12px !important;
    font-size: 12px !important;
    min-height: 36px;
  }

  /* Horizontally scrolling pill rows: snap to each pill and drop the
     scrollbar, which otherwise eats vertical space on mobile. */
  .sport-filters, .method-tabs, #bt-sport-pills {
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .sport-filters::-webkit-scrollbar,
  .method-tabs::-webkit-scrollbar,
  #bt-sport-pills::-webkit-scrollbar { display: none; }
  .sport-btn, .bt-pill { scroll-snap-align: start; }

  /* Mobile bottom nav */
  .mobile-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
    z-index: 999;
    padding: 4px 0 env(safe-area-inset-bottom, 4px);
  }
  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s;
    position: relative;
  }
  .mobile-nav-btn.active { color: var(--green); }
  .mobile-nav-btn svg { width: 20px; height: 20px; }
  .mobile-nav-btn .mob-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 18px);
    background: #c62828;
    color: white;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }

  /* Panel header responsive */
  .panel-header {
    flex-direction: column !important;
    gap: 12px !important;
    align-items: flex-start !important;
  }
  .panel-title { font-size: 22px !important; }
  .header-actions { flex-wrap: wrap !important; width: 100% !important; }

  /* Sport filter pills scroll */
  .sport-filters { overflow-x: auto; flex-wrap: nowrap !important; -webkit-overflow-scrolling: touch; }
  .sport-btn { flex-shrink: 0; }

  /* Match cards single column */
  .matches-grid { grid-template-columns: 1fr !important; }
  .best-bets-grid { grid-template-columns: 1fr !important; }

  /* Portfolio metrics 2-col */
  .portfolio-metrics { grid-template-columns: repeat(2, 1fr) !important; }
  
  /* Allocations */
  .alloc-row { grid-template-columns: 1fr 60px 70px !important; }
  .alloc-row .alloc-bar-track { display: none; }
  
  /* Suivi KPI cards */
  #suivi-stats { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; }
  .stat-card { padding: 10px !important; }
  .stat-card-value { font-size: 18px !important; }

  /* Suivi: show cards on mobile, hide table */
  .suivi-cards { display: flex !important; }
  .suivi-table-wrap { display: none !important; }
  .suivi-card {
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    margin-bottom: 8px;
  }
  .suivi-actions { gap: 4px !important; }
  .suivi-btn { padding: 8px 12px !important; font-size: 15px !important; min-height: 44px !important; min-width: 44px !important; }

  /* Crowd intelligence table */
  #crowd-content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Method tabs scroll */
  .method-tabs { overflow-x: auto; flex-wrap: nowrap !important; }

  /* Validate FAB hide on mobile (buttons are inline) */
  .validate-fab { display: none !important; }
}

/* BEST BETS SECTION */
.best-bets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.best-bet-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.best-bet-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.best-bet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.best-bet-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
  line-height: 1.2;
}

.best-bet-badge {
  background: var(--green-bg);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
}

.best-bet-market {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
  align-self: flex-start;
}

.best-bet-details {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.best-bet-stat {
  display: flex;
  flex-direction: column;
}

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

.stat-value {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
}

.best-bet-stake {
  background: var(--green);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  text-align: center;
}

.stake-label {
  font-size: 10px;
  opacity: 0.9;
  text-transform: uppercase;
}

.stake-value {
  font-size: 18px;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}

/* ── HOME CROWD WIDGET ───────────────────────────────────────────────────── */
.crowd-summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.crowd-stat-card {
  background: linear-gradient(135deg, #f8fffe, #eef7f3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.crowd-stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--green);
  line-height: 1.2;
}
.crowd-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-hint);
  margin-top: 4px;
}
.crowd-row:hover {
  background: #e3f2fd !important;
}
.crowd-row-selected {
  background: #e8f5e9 !important;
}

@media (max-width: 700px) {
  .crowd-summary-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ── SUIVI (BET TRACKING) ───────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.06); }
.stat-card-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.stat-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-hint);
  margin-top: 4px;
}

/* Default: hide mobile cards, show desktop table */
.suivi-cards { display: none; flex-direction: column; gap: 8px; }
.suivi-table-wrap { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.suivi-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.suivi-table thead th {
  background: #f8f8f6;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
}
.suivi-table tbody tr {
  border-left: 4px solid transparent;
  transition: background 0.15s;
}
.suivi-table tbody tr:hover { background: #f9f9f7; }
.suivi-table tbody tr.bet-won { border-left-color: #2e7d32; }
.suivi-table tbody tr.bet-lost { border-left-color: #c62828; }
.suivi-table tbody tr.bet-pending { border-left-color: #e65100; }
.suivi-table tbody tr.bet-void { border-left-color: #888; }
.suivi-table td {
  padding: 12px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.suivi-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.suivi-status.pending { background: #fff3e0; color: #e65100; }
.suivi-status.won { background: #e8f5e9; color: #2e7d32; }
.suivi-status.lost { background: #fce4ec; color: #c62828; }
.suivi-status.void { background: #f5f5f5; color: #888; }

.suivi-actions {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}
.suivi-btn {
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}
.suivi-btn:hover { transform: scale(1.04); }
.suivi-btn:active { transform: scale(0.96); }
.suivi-btn.btn-won { background: #e8f5e9; color: #2e7d32; }
.suivi-btn.btn-lost { background: #fce4ec; color: #c62828; }
.suivi-btn.btn-void { background: #f5f5f5; color: #888; }
.suivi-btn.btn-del { background: #fff; border: 1px solid #e0e0e0; color: #999; font-size: 10px; }

.validate-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 14px 24px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(15, 110, 86, 0.3);
  z-index: 100;
  transition: transform 0.15s, box-shadow 0.15s;
  display: none;
}
.validate-fab:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(15, 110, 86, 0.4); }
.validate-fab.visible { display: flex; align-items: center; gap: 8px; }

/* ── YESTERDAY RESULTS TABLE ──────────────────────────────────────────────── */
.yesterday-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.yesterday-table thead th {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-hint);
  position: sticky;
  top: 0;
  z-index: 2;
}
.yesterday-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.yesterday-table tbody tr:hover { background: rgba(0,0,0,0.02); }
.yesterday-table td {
  padding: 10px 12px;
  vertical-align: middle;
}
.yesterday-table .match-cell { min-width: 200px; }
.yesterday-table .score-cell { font-family: 'IBM Plex Mono', monospace; font-size: 14px; }

tr.result-correct { background: rgba(46, 125, 50, 0.04); }
tr.result-wrong { background: rgba(198, 40, 40, 0.04); }

.result-label {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.result-label.result-correct { background: #e8f5e9; color: #2e7d32; }
.result-label.result-wrong { background: #ffebee; color: #c62828; }
.result-label.result-pending { background: #fff3e0; color: #e65100; }

.pred-badge {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 4px;
  font-weight: 700;
  font-size: 11px;
  background: var(--green);
  color: white;
  margin-right: 6px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── COMPREHENSIVE MOBILE OPTIMIZATION ──────────────────────────────────── */
@media (max-width: 700px) {

  /* ── Best Selections: Stats Grid → 2x3 ── */
  #best-content > div[style*="grid"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
    margin-bottom: 10px !important;
  }
  #best-content > div[style*="grid"] > div {
    padding: 10px 6px !important;
    border-radius: 8px !important;
  }
  #best-content > div[style*="grid"] > div > div:first-child {
    font-size: 18px !important;
  }
  #best-content > div[style*="grid"] > div > div:last-child {
    font-size: 9px !important;
  }

  /* ── Best Selections: Source Status Banner ── */
  #best-content > div[style*="display:flex"][style*="border-radius"] {
    flex-direction: column !important;
    gap: 4px !important;
    padding: 8px 10px !important;
    margin-bottom: 10px !important;
    font-size: 12px !important;
  }

  /* ── Best Selections: Cards ── */
  .best-bets-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  .best-bet-card {
    padding: 10px !important;
    gap: 6px !important;
    border-radius: 10px !important;
  }
  .best-bet-title {
    font-size: 13px !important;
    line-height: 1.2 !important;
  }
  .best-bet-header {
    gap: 4px !important;
  }
  .best-bet-details {
    padding-top: 6px !important;
  }
  .best-bet-stake {
    padding: 6px 10px !important;
  }
  .stake-value {
    font-size: 14px !important;
  }

  /* ── Best Selections: Section headers ── */
  #best-content div[style*="font-size:18px"] {
    font-size: 15px !important;
  }

  /* ── Best Selections: Actualiser button ── */
  #best-content .btn-primary,
  #best-content button[onclick*="loadBestSelections"] {
    width: 100% !important;
    padding: 12px !important;
    font-size: 14px !important;
    border-radius: 10px !important;
  }

  /* ── Inline styles fix: edge/confidence badges ── */
  #best-content div[style*="display:flex"][style*="gap:8px"] > div {
    font-size: 11px !important;
    padding: 2px 8px !important;
  }

  /* ── Forebet panel ── */
  #forecasts-content .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
  }
  #forecasts-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Yesterday results ── */
  .yesterday-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    font-size: 11px !important;
  }
  .yesterday-table td, .yesterday-table th {
    padding: 6px 8px !important;
    white-space: nowrap !important;
  }

  /* ── Settings panel ── */
  .setting-row {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  /* .setting-control is a flex row. On a phone that crushed the bankroll
     row's input, hint and checkbox into three slivers side by side. Allowing
     wrap lets those stack (their first child is width:100%) while short
     pairings like [slider][value] still share a line. */
  .setting-control {
    flex-wrap: wrap !important;
    width: 100%;
    min-width: 0;
  }
  .setting-control > input[type=range] { flex: 1 1 60%; min-width: 0; }

  /* Grid and flex children default to min-width:auto, so anything that can't
     shrink — a fixed-size canvas, a long unbreakable input row — widens its
     track and pushes the panel past the viewport. The panel clips at
     overflow-x:hidden, so this surfaced as silently cut-off content. */
  .setting-row > *,
  #suivi-stats > *,
  .tab-panel div[style*="grid"] > * { min-width: 0; }

  /* Same problem one level deeper: the API-key row is an inline flex whose
     input carries an intrinsic min-width (larger now that inputs are 16px to
     stop iOS zooming), so it has to be allowed to shrink and wrap. */
  .setting-control > div[style*="display:flex"] { flex-wrap: wrap; min-width: 0; }
  .setting-control > div[style*="display:flex"] > * { min-width: 0; }
  #odds-api-key { min-width: 0; }

  /* Hard-coded two-column chart grids stack on a phone. */
  .tab-panel div[style*="grid-template-columns:1fr 1fr"],
  .tab-panel div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  #calib-draw-wrap { max-width: 100% !important; }
  .settings-card {
    padding: 14px !important;
  }

  /* ── Frontier chart ── */
  .frontier-chart-wrap {
    height: 250px !important;
  }

  /* ── Auto-Optim: compact table ── */
  #auto-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 11px;
  }

  /* ── Touch-friendly buttons ── */
  button, .btn-primary {
    min-height: 40px;
  }

  /* ── Body scrolling fix for iOS ── */
  .main {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
  /* Only clip overflow on the ACTIVE panel — applying overflow-x:hidden to
     display:none panels creates an implicit scroll container in iOS Safari
     which can cause the panel to partially paint outside its hidden bounds */
  .tab-panel.active {
    overflow-x: hidden !important;
  }

  /* The "Plus" menu is now a bottom sheet anchored to the viewport edge — it
     owns its own safe-area padding, so the old dropdown offset is gone. */

  /* ── Charts: smaller on mobile ── */
  canvas {
    max-height: 250px !important;
    max-width: 100% !important;
  }

  /* ── Crowd Intelligence: sport pills smaller ── */
  #crowd-sport-filters .sport-btn {
    font-size: 11px !important;
    padding: 6px 12px !important;
  }

  /* ── Modal on mobile ── */
  .modal-content {
    width: 96% !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
    padding: 16px !important;
  }
}

/* ── TABLET BREAKPOINT (701-900px) ───────────────────────────────────────── */
@media (max-width: 900px) and (min-width: 701px) {
  .best-bets-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  #best-content > div[style*="grid"] {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .setting-row {
    grid-template-columns: 1fr 2fr !important;
  }
}

/* ── SMALL PHONE (< 380px) ──────────────────────────────────────────────── */
@media (max-width: 380px) {
  .panel-title { font-size: 18px !important; }
  .mobile-nav-btn { font-size: 9px !important; padding: 6px 2px !important; }
  .mobile-nav-btn svg { width: 18px !important; height: 18px !important; }
  .best-bet-card { padding: 8px !important; }
  .best-bet-title { font-size: 12px !important; }
  #best-content > div[style*="grid"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  #best-content > div[style*="grid"] > div > div:first-child {
    font-size: 14px !important;
  }
  .stat-card-value { font-size: 16px !important; }
  .tab-panel { padding: 12px 8px !important; }
}

/* ── SIMULATION DASHBOARD RESPONSIVE ─────────────────────────────────────── */
#sim-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

#sim-stats-grid .stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  text-align: center;
}

#sim-stats-grid .stat-card .stat-value {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

#sim-stats-grid .stat-card .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

@media (max-width: 900px) {
  #sim-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
}

@media (max-width: 700px) {
  /* Sim dashboard: prevent horizontal overflow and flex collapse */
  #best-sim-dashboard {
    flex-shrink: 0 !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Sim dashboard header */
  #best-sim-dashboard .panel-header {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  /* Panel title wrap */
  #best-sim-dashboard .panel-title {
    font-size: 16px !important;
    word-break: break-word !important;
  }

  /* Stats grid: 2 columns on mobile */
  #sim-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  #sim-stats-grid .stat-card {
    padding: 10px 8px !important;
    overflow: hidden !important;
    word-break: break-word !important;
  }

  #sim-stats-grid .stat-card .stat-value {
    font-size: 14px !important;
    word-break: break-all !important;
  }

  #sim-stats-grid .stat-card .stat-label {
    font-size: 9px !important;
    line-height: 1.3 !important;
  }

  /* Chart cards: prevent overflow */
  #best-sim-dashboard .card {
    overflow: hidden !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  #best-sim-dashboard .card h3 {
    font-size: 13px !important;
    word-break: break-word !important;
  }

  #best-sim-dashboard .card p {
    font-size: 10px !important;
    word-break: break-word !important;
  }

  /* Canvas: constrain to parent */
  #sim-bankroll-chart,
  #sim-dd-chart,
  #sim-dist-chart {
    max-width: 100% !important;
  }

  /* Charts: stack vertically */
  #best-sim-dashboard div[style*="grid-template-columns: 1fr 1fr"],
  #best-sim-dashboard div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Header buttons stack on mobile */
  #tab-best .panel-header > div[style*="display:flex; gap:10px"] {
    flex-direction: column !important;
    gap: 6px !important;
    width: 100%;
  }
  #tab-best .panel-header > div[style*="display:flex; gap:10px"] .btn-primary {
    width: 100% !important;
    font-size: 13px !important;
    padding: 10px !important;
  }
}

@media (max-width: 380px) {
  #sim-stats-grid .stat-card .stat-value {
    font-size: 12px !important;
  }
  #sim-stats-grid .stat-card .stat-label {
    font-size: 8px !important;
  }
}

/* ── BACKTEST PAGE ──────────────────────────────────────────────────────── */
.bt-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}
.bt-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.bt-bench-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.bt-hero-stat {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 10px 16px;
  text-align: center;
  backdrop-filter: blur(4px);
  min-width: 90px;
}
.bt-hero-stat-val {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  font-family: 'IBM Plex Mono', monospace;
}
.bt-hero-stat-lbl {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-top: 3px;
}

@media (max-width: 900px) {
  .bt-layout {
    grid-template-columns: 1fr;
  }
  .bt-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* Mobile */
@media (max-width: 700px) {
  .bt-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  /* Every direct child of bt-layout must stay within viewport */
  .bt-layout > div {
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }
  /* All cards inside bt-layout — reduce inner padding on mobile */
  .bt-layout > div > div {
    max-width: 100%;
    box-sizing: border-box;
    padding: 14px 14px !important;
  }
  /* Hero inner flex: stack cleanly */
  #tab-backtest > div:first-child > div {
    gap: 10px !important;
  }
  /* bt-summary KPI grid: 2 cols on mobile (inline style override) */
  #bt-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  /* Hero: compact + prevent flex-shrink collapse */
  #tab-backtest > div:first-child {
    padding: 18px 16px !important;
    border-radius: 12px !important;
    margin-bottom: 14px !important;
    flex-shrink: 0 !important;
    /* Must stay clipped: the hero's decorative circles are positioned at
       right:-40px and pushed the panel 28px past the viewport when this was
       `visible`, giving the whole Backtest tab a sideways scroll. */
    overflow: hidden !important;
  }
  #tab-backtest > div:first-child h1 {
    font-size: 18px !important;
  }
  #tab-backtest > div:first-child p {
    font-size: 11px !important;
  }
  #bt-hero-stats {
    display: none !important;
  }
  /* Sport pills: scroll horizontally */
  #bt-sport-pills {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    max-width: 100%;
  }
  .bt-pill {
    flex-shrink: 0;
  }
  /* KPI summary grid: 2 cols */
  .bt-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  /* Benchmark: stack */
  .bt-bench-grid {
    grid-template-columns: 1fr !important;
  }
  /* Top bets table: scroll */
  #bt-top-bets table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    font-size: 11px !important;
  }
  #bt-top-bets td, #bt-top-bets th {
    padding: 6px 8px !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 380px) {
  .bt-kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }
  .bt-kpi-grid > div > div:first-child {
    font-size: 16px !important;
  }
}


/* ── MOBILE "PLUS" BOTTOM SHEET ──────────────────────────────────────────── */
/* Replaces the old bottom-right dropdown: a sheet gives full-width tap targets
   and can be dismissed by tapping anywhere outside it. */
.mob-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 1000;
}
.mob-sheet-backdrop.mob-more-open {
  opacity: 1;
  pointer-events: auto;
}

.mob-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  z-index: 1001;
  padding: 8px 8px calc(12px + env(safe-area-inset-bottom, 0px));
  max-height: 80dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateY(100%);
  transition: transform .24s cubic-bezier(.32, .72, 0, 1);
}
.mob-sheet.mob-more-open { transform: translateY(0); }

.mob-sheet-grip {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 4px auto 10px;
}

.mob-sheet-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  min-height: 52px;          /* comfortable thumb target */
  border: none;
  background: none;
  text-align: left;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}
.mob-sheet-item:active { background: var(--gray-light); }
.mob-sheet-item.active {
  background: var(--green-light);
  color: var(--green);
  font-weight: 600;
}
.mob-sheet-danger { color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  .mob-sheet, .mob-sheet-backdrop { transition: none; }
}

/* Desktop uses the sidebar — the sheet and bar must never appear there. */
@media (min-width: 701px) {
  .mobile-nav,
  .mob-sheet,
  .mob-sheet-backdrop { display: none !important; }
}
