
:root{
  --bg:#f7f8fa;
  --card:#fff;
  --text:#17181a;
  --muted:#626a75;
  --border:#e5e7eb;
  --grid:#e7eaee;
  --accent:#ff5a36;
}
*{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;
  overflow:hidden;
  background:#fff
}
.chart-svg{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  display:block
}
.price-area{
  fill:var(--accent);
  opacity:.10
}
.price-line{
  fill:none;
  stroke:var(--accent);
  stroke-width:2.8;
  stroke-linecap:round;
  stroke-linejoin:round
}
.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:absolute;
  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
}
.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}
  .y-label{font-size:14px}
  .x-axis{left:60px;right:10px}
  .x-label{font-size:13px}
}
@media(max-width:430px){
  .chart{height:340px}
  .stats{grid-template-columns:repeat(2,1fr)}
  .x-label{font-size:12px}
}

rect.hit{cursor:crosshair}
