/* Mobile Sticky Table Enhancement for Stream Command */
/* Separate file to keep changes organized and maintainable */

/* =========================
   CSS Custom Properties
   ========================= */
:root {
  --pitcher-width: 140px;   /* measured reference */
  --pitcher-max: 128px;     /* actual mobile width used */
  --fintel-width: 64px;     /* LOCKED width for FINTEL */
  --group-header-h: 42px;   /* category header row height */
}

/* =========================
   Mobile (≤900px)
   ========================= */
@media (max-width: 900px) {

  /* iOS sticky requirements + stability */
  .streaming-table {
    border-collapse: separate !important;
    border-spacing: 0 !important;
    table-layout: fixed;             /* reduces elastic reflow during sorts */
  }
  #tableBody { position: relative; } /* sticky context */
  .streaming-table th,
  .streaming-table td {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Remove transforms only where sticky relies on them */
  .table-container,
  .streaming-table,
  .streaming-table thead,
  .streaming-table tbody,
  .streaming-table [data-sticky] {
    transform: none !important;
    -webkit-transform: none !important;
  }

  /* =========================
     Black Header Row (category headers)
     ========================= */
  .streaming-table .category-header th {
    position: sticky !important;
    top: 0 !important;
    z-index: 30 !important;
    background: #1a1a1a !important;
    color: #fff !important;
    padding: 8px !important;
    height: 42px !important;
    border: none !important;
    vertical-align: middle !important;
  }
  /* DATE (1st) */
  .streaming-table .category-header th:nth-child(1) {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    font-size: 0 !important;
    color: transparent !important;
  }
  /* BASIC INFO (2nd) — above pitcher */
  .streaming-table .category-header th:nth-child(2) {
    position: -webkit-sticky !important;
    position: sticky !important;
    left: 0 !important;
    top: 0 !important;
    z-index: 35 !important;
    width: var(--pitcher-max) !important;
    min-width: var(--pitcher-max) !important;
    max-width: var(--pitcher-max) !important;
    background: #1a1a1a !important;
    color: #fff !important;
    text-align: center !important;
    font-weight: 700 !important;
    font-size: 11px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    box-shadow: 2px 0 4px rgba(0,0,0,0.15);
  }
  /* TEAM (3rd) */
  .streaming-table .category-header th:nth-child(3) {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    font-size: 0 !important;
    color: transparent !important;
  }
  /* OPP (4th) */
  .streaming-table .category-header th:nth-child(4) {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    font-size: 0 !important;
    color: transparent !important;
  }
  /* FINTEL (5th) — black row */
  .streaming-table .category-header th:nth-child(5) {
    position: -webkit-sticky !important;
    position: sticky !important;
    left: var(--pitcher-max) !important;
    top: 0 !important;
    z-index: 36 !important;
    width: var(--fintel-width) !important;
    min-width: var(--fintel-width) !important;
    max-width: var(--fintel-width) !important;
    background: #1a1a1a !important;
    color: #fff !important;
    text-align: center !important;
    font-weight: 700 !important;
    box-shadow: 2px 0 4px rgba(0,0,0,0.15);
  }
  /* remaining headers (6+) */
  .streaming-table .category-header th:nth-child(n+6) {
    position: sticky !important;
    top: 0 !important;
    z-index: 30 !important;
    background: #1a1a1a !important;
    color: #fff !important;
  }

  /* =========================
     Column Header Row - All Headers Sticky Vertically
     ========================= */
  .streaming-table .column-header th {
    position: sticky !important;
    top: var(--group-header-h, 42px) !important;
    z-index: 29 !important;
    background: #f8f8f8 !important;
  }

  /* =========================
     PITCHER Column (Index 2)
     ========================= */
  .streaming-table .column-header th[data-sticky="pitcher"] {
    position: sticky !important;
    left: 0 !important;
    z-index: 31 !important;
    top: var(--group-header-h, 42px) !important;
    background: #f8f8f8;
    box-shadow: 2px 0 4px rgba(0,0,0,0.1);
    width: var(--pitcher-max);
    min-width: var(--pitcher-max);
    max-width: var(--pitcher-max);
  }
  .streaming-table #tableBody td[data-sticky="pitcher"] {
    position: sticky !important;
    left: 0 !important;
    z-index: 20;
    background: #fff !important;
    box-shadow: 2px 0 4px rgba(0,0,0,0.08);
    width: var(--pitcher-max);
    min-width: var(--pitcher-max);
    max-width: var(--pitcher-max);
    padding: 8px 10px !important;
    white-space: nowrap;
  }
  .streaming-table #tableBody tr:nth-child(even) td[data-sticky="pitcher"] {
    background: #fafbfc !important;
  }

  /* =========================
     FINTEL Column (Index 5) — LOCKED
     ========================= */
  /* Purple sticky header */
  .streaming-table .column-header th[data-sticky="fintel"] {
    position: sticky !important;
    left: var(--pitcher-max) !important;
    z-index: 31 !important;
    top: var(--group-header-h, 42px) !important;

    width: var(--fintel-width) !important;
    min-width: var(--fintel-width) !important;
    max-width: var(--fintel-width) !important;

    background: #8B5CF6 !important;
    color: #fff;
    box-shadow: 2px 0 4px rgba(0,0,0,0.1);
    border-radius: 0 !important;
    opacity: 1 !important;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
  }
  /* keep label+icon from forcing growth */
  .streaming-table .column-header th[data-sticky="fintel"] > * {
    flex: 0 0 auto;
    max-width: calc(var(--fintel-width) - 8px);
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .streaming-table .column-header th[data-sticky="fintel"] .sort-icon,
  .streaming-table .column-header th[data-sticky="fintel"] .arrow,
  .streaming-table .column-header th[data-sticky="fintel"] svg {
    width: 12px; height: 12px; flex: 0 0 12px;
  }

  /* Body cells */
  .streaming-table #tableBody td[data-sticky="fintel"] {
    position: sticky !important;
    left: var(--pitcher-max) !important;
    z-index: 20;

    width: var(--fintel-width) !important;
    min-width: var(--fintel-width) !important;
    max-width: var(--fintel-width) !important;

    box-shadow: 2px 0 4px rgba(0,0,0,0.08);
    opacity: 1 !important;
    border-radius: 0 !important;
    box-sizing: border-box;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
  }

  /* --- MOBILE: FINTEL column colors (match desktop, no transparency) --- */
  .streaming-table #tableBody td[data-sticky="fintel"] {
    width: var(--fintel-width, 64px) !important;
    min-width: var(--fintel-width, 64px) !important;
    max-width: var(--fintel-width, 64px) !important;
    box-sizing: border-box;
    background-image: none !important;      /* kill zebra overlays */
    background-color: transparent !important;/* baseline; ranges set solid */
    color: #111;                              /* default; ranges override */
    text-align: center !important;
    font-weight: 600;
    letter-spacing: 0.1px;
  }

  /* Map the same ranges used on desktop via data-score */
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="9"],
  .streaming-table #tableBody td[data-sticky="fintel"][data-score="100"] {
    /* Desktop: rgba(0,168,107,0.1) + #008856 -> solid tint + same text */
    background-color: #cfeee4 !important;
    color: #008856 !important;
  }
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="8"] {
    /* Desktop: rgba(76,175,80,0.1) + #388E3C */
    background-color: #e0f3e0 !important;
    color: #388E3C !important;
  }
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="7"] {
    /* Desktop: rgba(255,193,7,0.1) + #F57C00 */
    background-color: #fff1cf !important;
    color: #F57C00 !important;
  }
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="6"] {
    /* Desktop: rgba(255,152,0,0.1) + #E65100 */
    background-color: #ffe8cc !important;
    color: #E65100 !important;
  }
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="5"] {
    /* Desktop: rgba(255,87,34,0.1) + #E64A19 */
    background-color: #ffe1d6 !important;
    color: #E64A19 !important;
  }
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="4"] {
    /* Desktop: rgba(214,48,49,0.1) + #B71C1C */
    background-color: #ffd9db !important;
    color: #B71C1C !important;
  }
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="0"],
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="1"],
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="2"],
  .streaming-table #tableBody td[data-sticky="fintel"][data-score^="3"] {
    /* Desktop low end: text #d63031 */
    background-color: #ffd4d6 !important;
    color: #d63031 !important;
  }

  /* Keep FINTEL opaque even on zebra rows */
  .streaming-table #tableBody tr:nth-child(even) td[data-sticky="fintel"] {
    background-image: none !important;
  }

  /* =========================
     Info (Question-Mark) Button — pixel-matched pill twin of Expand
     ========================= */
  .fi-info-btn {
    position: fixed;
    bottom: 16px;          /* align with Expand */
    left: 16px;            /* mirror Expand */
    padding: 10px 14px;    /* MATCH Expand exactly - creates pill shape */
    border-radius: 9999px;
    background: #4a90e2;
    color: #fff;
    border: none;
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
    z-index: 9998;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .18s ease, box-shadow .18s ease;
  }
  .fi-info-btn:active { transform: scale(.98); }

  /* The "?" glyph — proportional & perfectly centered */
  .fi-info-btn .fi-info-glyph {
    display: block;
    font-weight: 700;
    font-size: 16px;       /* proportional to Expand's 13px text */
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    transform: translateY(-0.5px);  /* nudge up for perfect optical center */
  }

  /* =========================
     Misc mobile optimizations
     ========================= */
  .streaming-table .table-container { position: relative; z-index: 1; }

  /* prevent selection "stickiness" on drag */
  .streaming-table [data-sticky] { -webkit-user-select: none; user-select: none; }
  .streaming-table td[data-sticky="pitcher"] .pitcher-name { -webkit-user-select: text; user-select: text; }

  /* smooth position nudge if layout shifts slightly */
  .streaming-table [data-sticky] { transition: left 0.2s ease-out; }

  /* nice hover (when applicable) */
  .streaming-table tbody tr:hover td[data-sticky="pitcher"] {
    background: linear-gradient(90deg,#f8f9fa 0%,#ffffff 10%,#ffffff 90%,#f8f9fa 100%);
  }
  .streaming-table tbody tr:nth-child(even):hover td[data-sticky="pitcher"] {
    background: linear-gradient(90deg,#f0f2f5 0%,#fafbfc 10%,#fafbfc 90%,#f0f2f5 100%);
  }

  /* =========================
     Fullscreen Button (Mobile Only)
     ========================= */
  .fi-fullscreen-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
    padding: 10px 14px;
    border-radius: 9999px;
    background: #4a90e2;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    border: none;
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
    z-index: 9998;
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease;
  }
  .fi-fullscreen-btn:active { transform: scale(.98); }

  /* =========================
     Smooth Fade Behavior for Mobile FABs
     ========================= */
  .fi-fullscreen-btn,
  .fi-info-btn {
    opacity: 1;
    transition: opacity 0.6s ease-in-out, transform 0.3s ease;
  }

  /* Temporary hidden state when scrolling */
  .fab-hidden {
    opacity: 0.25;              /* still visible but faded */
    pointer-events: none;       /* avoid blocking touches */
    transform: translateY(4px); /* slight motion for polish */
  }
}


/* =========================
   (Legacy) In-page Modal Styles
   ========================= */
@media (max-width: 900px) {
  .fi-fs-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 9999;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0 !important;
  }
  .fi-fs-modal.is-open { display: block; }

  .fi-fs-close {
    position: fixed;
    top: 10px; right: 10px;
    width: 40px; height: 40px;
    border: none; border-radius: 9999px;
    background: #111; color: #fff;
    font-size: 22px; line-height: 40px; text-align: center;
    z-index: 10000; cursor: pointer;
  }

  .fi-fs-iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: 0;
    background: #fff;
  }
}

/* =========================
   Fullscreen Table Mode (?fs=1)
   ========================= */
.is-fullscreen-table { background: #fff; }

/* Hide site chrome in fullscreen */
.is-fullscreen-table header,
.is-fullscreen-table nav,
.is-fullscreen-table .topbar,
.is-fullscreen-table .sidebar,
.is-fullscreen-table footer { display: none !important; }

/* Table container breathing room */
.is-fullscreen-table .table-container { margin: 12px auto; }

/* Neutralize outer wrappers (if any) */
.is-fullscreen-table #app,
.is-fullscreen-table main,
.is-fullscreen-table .page,
.is-fullscreen-table .content {
  margin: 0 !important;
  padding: 0 !important;
}

/* Never show Expand button in fs view */
.is-fullscreen-table .fi-fullscreen-btn { display: none !important; }
