
:root{
  --bg:#f7f8fa;
  --card:#fff;
  --text:#17181a;
  --muted:#626a75;
  --border:#e5e7eb;
  --grid:#e7eaee;
  --accent:#15803d;
}
*{box-sizing:border-box}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,system-ui,-apple-system,"Segoe UI",sans-serif
}
.page{
  width:min(980px,calc(100% - 20px));
  margin:auto;
  padding:20px 0 50px
}
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:17px;
  padding:18px;
  box-shadow:0 5px 20px rgba(20,25,35,.04)
}
.header{
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:12px;
  flex-wrap:wrap;
  margin-bottom:14px
}
h1{margin:0;font-size:21px}
.header p{margin:4px 0 0;color:var(--muted);font-size:13px}
.ranges{display:flex;gap:6px}
.range{
  border:1px solid var(--border);
  background:#fff;
  color:var(--muted);
  border-radius:9px;
  padding:8px 11px;
  cursor:pointer;
  font-size:12px
}
.range.active{
  color:#fff;
  background:#17181a;
  border-color:#17181a
}
.stats{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:8px;
  margin-bottom:14px
}
.stat{
  border:1px solid var(--border);
  border-radius:10px;
  padding:8px 10px
}
.stat span{
  display:block;
  color:var(--muted);
  font-size:11px;
  margin-bottom:3px
}
.stat strong{font-size:14px}

/* Chart */
.chart{
  position:relative;
  height:390px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff
  /* ไม่มี overflow:hidden — tooltip ต้องลอยทะลุขอบบนกราฟขึ้นไปโซนหัวการ์ดได้ (แบบ mockup 1/9/69) */
}
.chart-svg{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  display:block
}
.price-line{
  fill:none;
  stroke:var(--accent);
  stroke-width:2.8;
  stroke-linecap:round;
  stroke-linejoin:round
}
/* จอแคบ: เส้นหนาขึ้นให้อ่านชัดบนมือถือ (สั่ง 1/9/69) */
@media (max-width:520px){
  .price-line{stroke-width:4}
}
.price-point{
  fill:#fff;
  stroke:var(--accent);
  stroke-width:2
}
.chart-grid{
  position:absolute;
  left:58px;
  right:14px;
  top:18px;
  bottom:46px;
  pointer-events:none
}
.grid-line{
  position:absolute;
  left:0;
  right:0;
  border-top:1px dashed var(--grid)
}
.grid-line.average{
  border-top:1.5px dashed #8f969e
}

/* Independent HTML labels: they never get squeezed by SVG */
.y-axis{
  position:absolute;
  left:8px;
  top:18px;
  bottom:46px;
  width:40px;
  pointer-events:none
}
.y-label{
  position:absolute;
  left:0;
  width:40px;
  transform:translateY(-50%);
  text-align:right;
  white-space:nowrap;
  color:#555d67;
  font-size:14px;
  font-weight:500;
  line-height:1
}
.x-axis{
  position:absolute;
  left:58px;
  right:14px;
  bottom:10px;
  height:20px;
  pointer-events:none
}
.x-label{
  position:absolute;
  transform:translateX(-50%);
  white-space:nowrap;
  font-size:13px;
  color:#555d67
}
.x-label.start{transform:none}
.x-label.end{transform:translateX(-100%)}

.average-label{
  position:absolute;
  right:10px;
  transform:translateY(-100%);
  z-index:4;
  padding:3px 7px;
  border-radius:6px;
  background:#fff;
  box-shadow:0 1px 2px rgba(0,0,0,.06);
  color:#4f5862;
  font-size:13px;
  font-weight:700;
  white-space:nowrap;
  pointer-events:none
}

.tooltip{
  position:fixed;
  display:none;
  z-index:20;
  width:150px;
  transform:translate(-50%,-118%);
  background:#17181a;
  color:#fff;
  border-radius:11px;
  padding:10px 12px 12px;
  text-align:center;
  box-shadow:0 12px 30px rgba(0,0,0,.22);
  pointer-events:none;
  will-change:left,top
}
/* โหมดพลิกลงล่าง — ใช้เมื่อเหนือจุดไม่มีที่พอ (กันโดนขอบบนกราฟตัด): กล่องโผล่ใต้จุดแทน */
.tooltip.below{
  transform:translate(-50%,16px)
}
.tooltip-shop{font-size:14px;font-weight:700}
.tooltip-price{margin-top:5px;font-size:22px;font-weight:850;line-height:1}
.tooltip-date{margin-top:5px;font-size:13px;color:#d5d8dd}

.chart-footer{
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-top:8px;
  color:var(--muted);
  font-size:12px
}

/* Empty state เมื่อยังไม่มีประวัติราคา */
.chart-empty{
  position:absolute;
  inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:6px;
  text-align:center;
  color:#8a929c
}
.chart-empty strong{font-size:15px;color:#555d67}
.chart-empty span{font-size:13px}

@media(max-width:620px){
  .card{padding:14px}
  .chart{height:350px}
  .chart-grid{left:60px;right:10px;top:20px;bottom:46px}
  .y-axis{left:8px;top:20px;bottom:46px;width:45px}
  /* มือถือ: ตัวเลขแกนต้องใหญ่พออ่านได้ (หัวหน้าสั่ง 1/9/69 — เดิม 14/13px เล็กเกิน) */
  .y-label{font-size:16px;font-weight:600}
  .x-axis{left:60px;right:10px}
  .x-label{font-size:15px}
}
@media(max-width:430px){
  .chart{height:340px}
  .stats{grid-template-columns:repeat(2,1fr)}
  .y-label{font-size:16px}
  .x-label{font-size:14px}
}

/* ── PDP redesign (sketches/003-pdp-ux H): แท็บแพลตฟอร์ม + ป้าย HTML overlay + กราฟส่วนต่าง ── */
/* แท็บแพลตฟอร์ม (G1) */
.ptabBtn{
  display:inline-flex;align-items:center;gap:7px;
  padding:7px 14px;border-radius:999px;border:1px solid var(--border);
  background:#fff;font-size:12.5px;font-weight:700;color:#52525b;cursor:pointer;
  font-family:inherit;transition:all .13s;
}
.ptabBtn:hover{border-color:#18181b;color:#18181b}
.ptabBtn.ptabAct{background:#18181b;color:#fff;border-color:#18181b}
.ptabDot{width:9px;height:9px;border-radius:50%;display:inline-block}
.ptabPrice{font-size:11px;font-weight:800;color:#059669}
.ptabBtn.ptabAct .ptabPrice{color:#6ee7b7}
/* ป้าย HTML overlay บนกราฟ (ชื่อเส้น/เฉลี่ย/ส่วนต่าง) — วางด้วย % ไม่ย่อหายตาม SVG */
#slabs{position:absolute;inset:0;pointer-events:none;z-index:3}
.slab{
  position:absolute;transform:translateY(-50%);
  font-size:11.5px;font-weight:700;white-space:nowrap;line-height:1;
}
.slab-avg{font-size:11px;color:#71717a;background:#fff;padding:2px 5px;border-radius:5px;transform:translateY(-120%)}
/* จอแคบ: ป้ายเฉลี่ยยังโชว์ (หัวหน้าขอคืน 1/9/69) — ย้ายไปฝั่งซ้ายกันชนกับป้ายชื่อเส้น/โดนัทปลายเส้นทางขวา
   (ตำแหน่งซ้าย/ขวาถูกตั้ง inline ใน JS ผ่าน isNarrow() — กฎนี้แค่จัดขนาด) */
@media(max-width:480px){
  .slab-avg{font-size:10.5px}
}

rect.hit{cursor:crosshair}
