/* RFSX — Papers stats (papers_stats.php)
   Purpose: bring the legacy stats dashboard into the RFSX theme while keeping
   the chart interactions intact.
*/

/* This page should match the standard RFSX width by default.
   (Full-screen mode below expands the chart when requested.) */

/* ===============================
   Full-screen chart mode
   - Hide both side rails
   - Expand the center column to the full viewport width
   - Use the mobile header controls (hamburger + info) even on desktop
   =============================== */

body.rfsx-papers-stats-page.pst-fullscreen main.wrap{
  max-width: 100%;
}

body.rfsx-papers-stats-page.pst-fullscreen .rfsx-layout{
  grid-template-columns: 1fr;
  gap: 0;
}

body.rfsx-papers-stats-page.pst-fullscreen .rfsx-nav,
body.rfsx-papers-stats-page.pst-fullscreen .rfsx-side{
  display: none !important;
}

body.rfsx-papers-stats-page.pst-fullscreen .rfsx-feedcol{
  border-left: none !important;
  border-right: none !important;
}

/* In full-screen, force the hamburger + Info affordance visible,
   and hide the desktop mini-link to reduce clutter. */
body.rfsx-papers-stats-page.pst-fullscreen .rfsx-iconbtn,
body.rfsx-papers-stats-page.pst-fullscreen .rfsx-filterlink{
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

body.rfsx-papers-stats-page.pst-fullscreen .rfsx-mini{
  display: none !important;
}

/* IMPORTANT: In full-screen mode we intentionally reuse the mobile modal
   (Menu / Info) on desktop too. The base rfsx.css hides .rfsx-modal on
   desktop via:
     @media (min-width: 761px){ .rfsx-modal { display:none !important; } }
   So we override that rule only when the page is in full-screen mode and
   the modal is actually open. */
@media (min-width: 761px){
  body.rfsx-papers-stats-page.pst-fullscreen .rfsx-modal.open{
    display: block !important;
  }
}

/* Hide non-chart content to maximize chart space */
body.rfsx-papers-stats-page.pst-fullscreen .pst-content > .pst-card:not(#pstChartCard){
  display: none;
}

body.rfsx-papers-stats-page.pst-fullscreen #pstChartCard{
  margin: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  background: transparent;
}

body.rfsx-papers-stats-page.pst-fullscreen .om-chart-wrap{
  /* Fill most of the viewport while keeping room for the topbar + controls */
  height: calc(100vh - 240px);
  min-height: 340px;
}

/* ===============================
   Page content
   =============================== */

.pst-wrap{
  padding: 16px;
}

@media (max-width: 760px){
  .pst-wrap{ padding: 12px 12px 18px; }
}

.pst-card{
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 14px;
}

.pst-card h2{
  margin: 0;
  font-size: 1.35rem;
  font-weight: 950;
}

.pst-card h3{
  margin: 0;
  font-size: 1.15rem;
  font-weight: 950;
}

.pst-lede{
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.5;
}

.pst-smallnote{
  color: var(--muted);
  margin-top: 8px;
  font-size: 0.92rem;
}

/* ===============================
   Chart controls (ported from old page, tuned for RFSX)
   =============================== */

.om-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}

.om-controls{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.om-mode-toggle{ display:flex; gap:8px; }

.om-mode-btn{
  appearance:none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font-weight: 900;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
}

.om-mode-btn:hover{
  background: rgba(255,255,255,0.06);
}

.om-mode-btn.is-active{
  border-color: rgba(255,208,112,0.55);
  background: rgba(255,208,112,0.10);
}

.om-actions{ display:flex; gap:8px; }

.om-action{
  appearance:none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-weight: 900;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
}

.om-action:hover{
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,208,112,0.35);
  color: var(--text);
}

/* Full screen toggle (active state) */
#pstFullscreenToggle[aria-pressed="true"]{
  border-color: rgba(255,208,112,0.55);
  background: rgba(255,208,112,0.10);
  color: var(--text);
}

.om-chip-row{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top: 12px;
}

.om-chip{
  appearance:none;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font-weight: 900;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  display:inline-flex;
  align-items:center;
  gap:8px;
  user-select:none;
}

.om-chip:hover{
  background: rgba(255,255,255,0.06);
}

.om-chip.is-off{ opacity: 0.45; }

.om-dot{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display:inline-block;
}

.om-chip-count{
  color: var(--muted);
  font-weight: 900;
}

/* ===============================
   Chart viewport
   =============================== */

.om-chart-wrap{
  height: 420px;
  margin-top: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.25);
  border-radius: 16px;
  padding: 10px;
}

.om-chart-scroll{
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(255,255,255,0.25) transparent;
}

.om-chart-inner{
  height: 100%;
  width: 100%;
  min-width: 100%;
}

/* Mobile: keep the chart readable by allowing horizontal scroll within the card */
@media (max-width: 760px){
  .om-chart-wrap{ height: 360px; }
  .om-chart-inner{ min-width: 980px; }
}

.om-chart-inner canvas{
  width: 100% !important;
  height: 100% !important;
}

/* ===============================
   Stat cards
   =============================== */

.stat-grid{
  display:flex;
  flex-wrap:wrap;
  gap:12px;
}

.stat-card{
  display:block;
  min-width: 210px;
  flex: 1 1 210px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.02);
  position: relative;
  overflow: hidden;

  /* accent defaults */
  --stat-accent:#2b3a52;
  --stat-accent-bg: rgba(43,58,82,0.20);
}

.stat-card::before{
  content:"";
  position:absolute;
  inset:0;
  background: linear-gradient(135deg, var(--stat-accent-bg), transparent 62%);
  pointer-events:none;
}

.stat-card::after{
  content:"";
  position:absolute;
  left:0;
  top:0;
  bottom:0;
  width:4px;
  background: var(--stat-accent);
  opacity: 0.9;
  pointer-events:none;
}

.stat-card:hover{
  border-color: color-mix(in srgb, var(--stat-accent) 60%, rgba(255,255,255,0.18));
  text-decoration: none;
}

.stat-top{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  gap:10px;
  position:relative;
  z-index:1;
}

.stat-title{
  font-weight: 950;
  font-size: 1.02rem;
  color: var(--text);
}

.stat-count{
  color: var(--stat-accent);
  font-weight: 950;
}

.stat-pct{
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  position:relative;
  z-index:1;
}

/* ===============================
   Table
   =============================== */

.pst-table-wrap{
  overflow: auto;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
}

.pst-table{
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.pst-table th,
.pst-table td{
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.pst-table th{
  text-align: left;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 950;
}

.pst-table td{ color: var(--text); }

.pst-table td.num,
.pst-table th.num{
  text-align: right;
}

.pst-table a{ font-weight: 950; }

/* ===============================
   Share block (match paper.php)
   =============================== */

.rfsx-papers-stats-page .rfsx-share{
  margin-top: 10px;
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.rfsx-papers-stats-page .rfsx-share a{
  color: var(--link);
  text-decoration: none;
  font-weight: 650;
}

.rfsx-papers-stats-page .rfsx-share a:hover{
  text-decoration: underline;
}

.rfsx-papers-stats-page .rfsx-share-copy{
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}

.rfsx-papers-stats-page .rfsx-share-copy:hover{
  background: rgba(255,255,255,0.09);
}

.rfsx-papers-stats-page .rfsx-share-copy:disabled{
  opacity: .75;
  cursor: default;
}
