:root[data-uhud-theme="dark"]{color-scheme:dark;--bg:#0b1220;--card:#172338;--text:#eef3fb;--muted:#a5b4ca;--line:#33445d;--green-bg:#173f32;--green-text:#9ef0b8;--orange-bg:#46351d;--blue-bg:#1b3653}
:root[data-uhud-theme="dark"] body{background:var(--bg)!important;color:var(--text)!important}
:root[data-uhud-theme="dark"] input,:root[data-uhud-theme="dark"] select,:root[data-uhud-theme="dark"] textarea{background:#19283d;color:#eef3fb;border-color:#46536b}
#uhud-controls{position:fixed;right:18px;bottom:18px;z-index:9999;display:flex;gap:8px;align-items:end;font-family:Arial,sans-serif}
.uhud-btn{border:0;border-radius:25px;padding:13px 16px;background:#d9a62e;color:#101827;font-weight:700;cursor:pointer;box-shadow:0 6px 18px #0003}
#uhud-panel{display:none;position:absolute;bottom:58px;right:0;width:min(380px,calc(100vw - 30px));height:480px;max-height:75vh;background:var(--card,#fff);color:var(--text,#111);border:1px solid var(--line,#ddd);border-radius:15px;box-shadow:0 10px 40px #0005;overflow:hidden;flex-direction:column}
#uhud-panel.open{display:flex}#uhud-log{flex:1;overflow:auto;padding:14px;font-size:14px;line-height:1.5}#uhud-log p{margin:7px 0}#uhud-log .answer{background:var(--bg,#f2f4f8);border-radius:10px;padding:10px;white-space:pre-wrap}#uhud-form{display:flex;padding:10px;border-top:1px solid var(--line,#ddd);gap:6px}#uhud-question{flex:1;min-width:0;padding:9px;border:1px solid #aaa;border-radius:8px;background:var(--card,#fff);color:var(--text,#111)}

/* Mobile viewport and keyboard safety */
#uhud-controls{max-width:calc(100vw - 24px);padding-bottom:env(safe-area-inset-bottom,0px)}
#uhud-panel{box-sizing:border-box;max-height:min(75dvh,600px)}
#uhud-panel *{box-sizing:border-box}
#uhud-form .uhud-btn{flex-shrink:0;padding:10px 12px}
#uhud-log{min-height:0;overscroll-behavior:contain;overflow-wrap:anywhere}
#uhud-open,#uhud-theme{touch-action:manipulation}
@media(max-width:600px){
 #uhud-controls{right:12px;bottom:12px;gap:6px}
 #uhud-panel{position:fixed;right:8px;left:8px;bottom:calc(72px + env(safe-area-inset-bottom,0px));width:auto;height:min(520px,calc(100dvh - 100px));max-height:calc(100dvh - 100px)}
 #uhud-panel.uhud-keyboard{bottom:8px;height:calc(100dvh - 16px);max-height:calc(100dvh - 16px)}
 .uhud-btn{padding:11px 13px}
}
@media(max-width:350px){#uhud-open{font-size:12px}#uhud-form{padding:7px}#uhud-question{font-size:16px}}
@media(prefers-reduced-motion:reduce){#uhud-panel{scroll-behavior:auto}}
:root[data-uhud-theme="dark"]{--surface:#172338;--surface2:#1d2c43}
:root[data-uhud-theme="dark"] :is(main,article,section,.card,.panel,.stat-card,.table-container){border-color:var(--line)}
:root[data-uhud-theme="dark"] :is(table,thead,tbody,tr,td,th){border-color:var(--line);color:var(--text)}
:root[data-uhud-theme="dark"] :is(button,input,select,textarea){color-scheme:dark}


/* === Dark theme v3: all active page layouts; scoped to dark mode only === */
:root[data-uhud-theme="dark"] {
 --bg:#0b1220; --card:#172338; --surface:#1d2c43; --surface-hover:#263953;
 --text:#eef3fb; --muted:#b5c4d9; --line:#394b66;
 --green:#86efac; --orange:#fdba74; --blue:#93c5fd;
 --gold:#e7b948; --gold2:#f8d475;
 --green-bg:#173f32; --green-text:#a7f3d0;
 --orange-bg:#46351d; --blue-bg:#1b3653;
}
:root[data-uhud-theme="dark"] :is(
 .coupon-card,.content-card,.filters,.analysis-tab:not(.active),.match-card,.team-card,
 .results-panel,.summary-card:not(.primary),.metric-card,.notice,.card,.panel,
 .league-title,.prediction-column,.health-card,.analysis-card,.profile-card,
 .match-hero,.venue,.filter-card,.metric-tab:not(.active),.results-head,
 .table-card,.statistics-card,.profile-history,.tab-content
){background:var(--card)!important;color:var(--text)!important;border-color:var(--line)!important;box-shadow:none!important}
:root[data-uhud-theme="dark"] :is(
 .coupon-item,.match,.prediction-column-header,.prediction-head,.coupon-note,.card-head,
 .panel-head,.results-head,.health-section,.team-top,.profile-row,.summary-row
){border-color:var(--line)!important}
:root[data-uhud-theme="dark"] :is(
 .stat-box,.prob,.mobile-box,.expected-box,.team-box,.profile-box,
 .coupon-rank,.match-rank,.rank-badge,.position-badge,.health-detail,
 .summary-box,.health-metric,.score-box,.league-stats
){background:var(--surface)!important;color:var(--text)!important;border-color:var(--line)!important}
:root[data-uhud-theme="dark"] :is(.coupon-rank,.match-rank,.rank,.position-badge){color:#f8fbff!important}
:root[data-uhud-theme="dark"] :is(
 .coupon-match a,.match-link,.match-title,.team-name,.team-card-name,
 .name,.expected-value,.stat-value,.mobile-value,.coupon-value,
 .summary-value,.metric-accuracy,.metric-name,.coupon-title,.league-title h2,
 .health-card h2,.health-card h3,.analysis-card h2,.profile-card h2
){color:#f8fbff!important}
:root[data-uhud-theme="dark"] :is(
 .coupon-meta,.coupon-profile,.coupon-more,.count,.league,.league-name,.date,
 .team-card-meta,.mobile-label,.stat-label,.results-head span,.summary-label,
 .summary-sub,.metric-meta,.empty,.dash,.expected-label,.health-meta,
 .team-box-label,.profile-label,.coupon-empty,.coupon-note,.prediction-subtitle
){color:var(--muted)!important}
:root[data-uhud-theme="dark"] :is(.metric-tab.active,.analysis-tab.active){background:linear-gradient(135deg,#f8d475,#d8a329)!important;color:#111827!important;border-color:#f8d475!important}
:root[data-uhud-theme="dark"] :is(.metric-tab.active *, .analysis-tab.active *){color:#111827!important}
:root[data-uhud-theme="dark"] .league-logo-wrap{background:#fff!important;color:#111827!important}
:root[data-uhud-theme="dark"] table{background:var(--card)!important;color:var(--text)!important}
:root[data-uhud-theme="dark"] :is(thead,tbody,tr,td,th){border-color:var(--line)!important}
:root[data-uhud-theme="dark"] :is(td,td a,td strong,td b){color:var(--text)!important}
:root[data-uhud-theme="dark"] th{color:var(--muted)!important}
:root[data-uhud-theme="dark"] tbody tr:hover{background:var(--surface-hover)!important}
:root[data-uhud-theme="dark"] :is(.filters select,.filters input,select,input,textarea){background:var(--surface)!important;color:var(--text)!important;border-color:var(--line)!important}
:root[data-uhud-theme="dark"] :is(.score-high,.score-mid,.score-low,.status-hit,.status-miss,.status-pending,.health-badge,.metric-pill,.value-highlight,.main-value,.probability-badge){border-color:transparent}
/* Semantic status chips keep strong contrast instead of pale-on-pale text */
:root[data-uhud-theme="dark"] :is(.score-high,.status-hit,.health-badge.healthy,.health-badge.success){background:#14532d!important;color:#bbf7d0!important}
:root[data-uhud-theme="dark"] :is(.score-mid,.status-pending,.health-badge.partial,.health-badge.running,.health-badge.stale){background:#563f17!important;color:#fde68a!important}
:root[data-uhud-theme="dark"] :is(.score-low,.status-miss,.health-badge.failed){background:#651f28!important;color:#fecdd3!important}
:root[data-uhud-theme="dark"] .probability-badge{background:#4b391d!important;color:#fde68a!important;border:1px solid #8f692b!important}
:root[data-uhud-theme="dark"] .probability-badge.very-high{background:#154b32!important;color:#bbf7d0!important;border-color:#247b50!important}
:root[data-uhud-theme="dark"] .probability-badge.high{background:#4b391d!important;color:#fde68a!important}
:root[data-uhud-theme="dark"] .probability-badge.normal{background:#29384e!important;color:#dbeafe!important}
:root[data-uhud-theme="dark"] .notice{color:var(--muted)!important}
:root[data-uhud-theme="dark"] :is(.coupon-card-header,.league-title,.results-head,.card-head){border-color:var(--line)!important}
:root[data-uhud-theme="dark"] :is(.coupon-item:hover,.match:hover,.match-card:hover,.team-card:hover){background:var(--surface-hover)!important}
/* The top-right chatbot retains its own panel colors and controls */
:root[data-uhud-theme="dark"] #uhud-panel{background:var(--card)!important;color:var(--text)!important}
:root[data-uhud-theme="dark"] #uhud-log .answer{background:var(--surface)!important;color:var(--text)!important}

/* Mobile horizontal stability — keep wide data tables scrollable INSIDE their containers. */
@media (max-width: 900px) {
  html { width: 100%; max-width: 100%; overflow-x: clip; }
  body { width: 100%; max-width: 100%; min-width: 0; overflow-x: clip; }
  /* Layout grids must be allowed to shrink without pushing the document. */
  :is(.page, main, .content, .content-card, .coupon-grid, .coupon-card,
      .filters, .filter-card, .results-panel, .summary-grid,
      .team-card, .match-card, .prediction-card, .prediction-column,
      .league-section, .app-header, .app-menu, .app-brand,
      .stats-grid, .metric-grid) { max-width: 100%; min-width: 0; box-sizing: border-box; }
  :is(.page, main, .content, .content-card, .coupon-grid, .coupon-card,
      .filters, .filter-card, .summary-grid, .team-card, .match-card,
      .prediction-card, .prediction-column, .league-section) { overflow-wrap: break-word; }
  /* Leave table-scrolling enabled and do not force narrow columns. */
  :is(.desktop-table, .table-container, .table-wrap, .results-panel) {
    max-width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  /* The panel is already viewport anchored; keep floating controls within it. */
  #uhud-controls { box-sizing: border-box; right: max(12px, env(safe-area-inset-right, 0px)); }
  #uhud-panel { box-sizing: border-box; max-width: calc(100vw - 16px); }
}
@supports not (overflow: clip) {
  @media (max-width: 900px) { html, body { overflow-x: hidden; } }
}

/* Mobile vertical overscroll containment (keeps normal page scrolling). */
@media (max-width: 900px) {
  html {
    overscroll-behavior-y: none;
  }
  body {
    overscroll-behavior-y: none;
  }
  /* Nested lists and dialogs should not drag the page at their boundaries. */
  #uhud-log, #uhud-panel {
    overscroll-behavior-y: contain;
  }
}
