/* =========================================================
   stats.css — ป๊อปอัปสถิติแบบละเอียด (js/stats.js)
   ========================================================= */
.modal-stats .modal-card { max-width: 460px; }
/* ชิดด้านบนจอ: ตอนสลับแท็บ ป๊อปอัปจะยืด/หดแค่ด้านล่าง ปุ่มแท็บไม่ขยับหนีนิ้ว */
.modal-stats { align-items: flex-start; padding-top: max(60px, 8vh); }

/* ---------- แท็บ ตามช่วงเวลา / ตามหมวดหมู่ ---------- */
.st-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--c-blue-soft);
  border-radius: 12px;
}
.st-tab {
  height: 36px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--c-text);
  transition: background 0.15s;
}
.st-tab:hover { background: rgba(255, 255, 255, 0.5); }
.st-tab[aria-selected="true"] { background: #fff; font-weight: 500; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
.st-tab:focus-visible { outline: 2px solid var(--c-blue-strong); outline-offset: 1px; }

/* ---------- ตัวเลข 4 กล่อง ---------- */
.st-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.st-box {
  min-width: 0;
  padding: 8px 12px 10px;
  background: #fff;
  border: 1px solid var(--c-blue-pale);
  border-radius: 12px;
}
.st-box span { display: block; font-size: 13px; line-height: 1.4; color: var(--c-blue); }
.st-box strong { display: block; font-size: 24px; font-weight: 500; line-height: 1.3; color: var(--c-text); overflow-wrap: anywhere; }
.st-box small { margin-left: 5px; font-size: 12px; font-weight: 400; color: var(--c-blue); }
/* ช่องยอดรวม (ทั้งหมด / คงเหลือตอนนี้) */
.st-box.is-total { background: var(--c-blue-soft); border-color: var(--c-blue); }

/* ---------- กราฟแท่ง ---------- */
.st-heading { margin: 18px 0 6px; font-size: 15px; font-weight: 500; color: var(--c-text); }
.st-heading-top { margin-top: 0; margin-bottom: 12px; }
.st-chart { min-height: 200px; }
.st-svg { display: block; overflow: visible; }
.st-svg text { font-family: inherit; }
.st-grid { stroke: var(--c-blue-soft); stroke-width: 1; stroke-dasharray: 3 3; }
.st-grid.is-base { stroke: var(--c-blue); stroke-dasharray: none; }
.st-ylabel { font-size: 10px; fill: var(--c-blue); }
.st-xlabel { font-size: 11px; fill: var(--c-text); }
.st-xlabel.is-today { font-weight: 600; fill: var(--c-blue-strong); }
.st-today { font-size: 10px; font-weight: 500; fill: var(--c-blue-strong); }
.st-bar { fill: var(--c-blue); }
.st-bar.is-today { fill: var(--c-blue-strong); }
.st-val { font-size: 12px; font-weight: 500; fill: var(--c-text); }
.st-val.is-today { fill: var(--c-blue-strong); }
.st-val.is-zero { font-weight: 400; fill: var(--c-muted); }

/* แท่งค่อยๆ โตขึ้นตอนเปิดป๊อปอัป */
.is-animated .st-bar {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: st-grow 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i) * 45ms);
}
.is-animated .st-val { animation: st-fade 0.3s ease-out both; animation-delay: calc(var(--i) * 45ms + 0.3s); }
@keyframes st-grow { from { transform: scaleY(0); } }
@keyframes st-fade { from { opacity: 0; } }

/* กราฟว่าง: แสดงข้อความแทน */
.st-chart-empty {
  height: 200px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  background: #fff;
  border: 1px dashed var(--c-blue);
  border-radius: 12px;
  color: var(--c-blue);
  font-size: 14px;
}
.st-chart-empty svg { width: 34px; height: 34px; color: var(--c-blue-pale); }
.st-note { margin-top: 4px; font-size: 12px; color: var(--c-blue); text-align: center; }

/* ---------- ตามหมวดหมู่ ---------- */
.st-cats { display: grid; gap: 14px; list-style: none; }
.st-cat-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; }
.st-cat-name { min-width: 0; font-weight: 500; color: var(--c-text); overflow-wrap: anywhere; }
.st-cat-num { flex-shrink: 0; white-space: nowrap; color: var(--c-text); }
.st-cat-num small { font-size: 12px; color: var(--c-blue); }
.st-cat-bar { height: 10px; margin-top: 5px; border-radius: 999px; background: var(--c-blue-soft); overflow: hidden; }
.st-cat-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--c-blue-strong);
  transform-origin: left center;
  animation: st-fill 0.6s ease-out both;
}
@keyframes st-fill { from { transform: scaleX(0); } }
.st-cat-total {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px dashed var(--c-blue-pale);
  font-size: 14px;
  color: var(--c-blue);
}
.st-cat-total strong { font-weight: 500; color: var(--c-text); }
.st-cat-empty { height: 140px; }

/* โหลดไม่สำเร็จ */
.st-error { padding: 24px 0 8px; text-align: center; color: var(--c-blue); font-size: 14px; }
.st-error .btn-secondary { width: 140px; margin: 12px auto 0; }

@media (min-width: 640px) {
  .modal-stats .modal-inner { padding: 22px 20px 20px; }
  .st-box strong { font-size: 26px; }
}

/* คนที่ตั้งค่าเครื่องให้ลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
  .is-animated .st-bar,
  .is-animated .st-val,
  .st-cat-bar span { animation: none; }
}
