/* เช็คราคาผัก — mobile first, ไม่มี framework, ไม่โหลดฟอนต์จากเน็ต (ใช้ฟอนต์ในเครื่อง) */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #1f6f43;
  --up: #c0392b;
  --up-bg: #fdecea;
  --down: #1565c0;
  --down-bg: #e8f1fb;
  --warn: #b45309;
  --warn-bg: #fff7e6;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --card: #1c2126; --line: #2c333a; --text: #e8eaed; --muted: #9aa4b0;
    --accent: #4ade80; --up: #ff7b6b; --up-bg: #3a1f1c; --down: #7cb8ff; --down-bg: #16283d;
    --warn: #fbbf24; --warn-bg: #33280d;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Sarabun", "Leelawadee UI", "Noto Sans Thai", "Segoe UI", system-ui, sans-serif;
  font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }

header {
  position: sticky; top: 0; z-index: 20; background: var(--card);
  border-bottom: 1px solid var(--line); padding: 10px 12px 8px;
}
.title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.title h1 { font-size: 17px; margin: 0; font-weight: 700; }
.title .date { font-size: 12px; color: var(--muted); }
nav { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
nav a {
  font-size: 13px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
nav a.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

main { padding: 12px; max-width: 1100px; margin: 0 auto; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  display: inline-flex; align-items: center; gap: 5px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: #22c55e; } .dot.warn { background: #f59e0b; } .dot.bad { background: #ef4444; }

.controls { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
input[type="search"] {
  flex: 1 1 180px; min-width: 0; padding: 9px 12px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
}
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button {
  padding: 8px 12px; font-size: 13px; font-family: inherit; border: 0; cursor: pointer;
  background: var(--card); color: var(--muted);
}
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }

.list { display: flex; flex-direction: column; gap: 7px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px;
}
.row:active { border-color: var(--accent); }
.row .nm { font-weight: 600; font-size: 15px; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .prices { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
.p { font-size: 13px; white-space: nowrap; }
.p b { font-weight: 600; font-variant-numeric: tabular-nums; }
.p .lbl { color: var(--muted); font-size: 11.5px; }
.p.old b { color: var(--muted); font-weight: 500; }

.delta {
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 3px 8px; border-radius: 7px; white-space: nowrap; align-self: start;
}
.delta.up1, .delta.up2 { color: var(--up); background: var(--up-bg); }
.delta.down1, .delta.down2 { color: var(--down); background: var(--down-bg); }
.delta.up2, .delta.down2 { box-shadow: inset 0 0 0 1.5px currentColor; }
.delta.flat { color: var(--muted); background: transparent; font-weight: 500; }

.badge {
  font-size: 10.5px; padding: 1px 6px; border-radius: 5px;
  background: var(--warn-bg); color: var(--warn); font-weight: 600; margin-left: 5px;
}

.empty { text-align: center; color: var(--muted); padding: 36px 12px; font-size: 14px; }
.note {
  background: var(--warn-bg); color: var(--warn); border-radius: var(--radius);
  padding: 9px 12px; font-size: 12.5px; margin-bottom: 10px;
}

/* ---- หน้ารายสินค้า ---- */
.chart-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
svg.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
table.data th, table.data td { padding: 7px 9px; text-align: right; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.data td { font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 3px 0; }
.kv span:last-child { font-variant-numeric: tabular-nums; }

footer { text-align: center; color: var(--muted); font-size: 11.5px; padding: 22px 12px 32px; }

@media (min-width: 720px) {
  .row { grid-template-columns: minmax(150px, 1.4fr) repeat(3, minmax(90px, 1fr)) auto; align-items: center; }
  .row .sub { grid-row: 2; grid-column: 1; }
  .row .prices { grid-column: 2 / 5; grid-row: 1 / 3; display: grid;
    grid-template-columns: repeat(3, 1fr); gap: 2px 10px; margin-top: 0; }
  .row .delta { grid-column: 5; grid-row: 1 / 3; }
}
