:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1c2430; --muted: #5d6b7a; --line: #e3e7ec;
  --accent: #1f6feb; --accent-ink: #fff; --warn: #9a3412; --warn-bg: #fff4e5;
  --good: #1e7a4f; --bad: #b42318; --radius: 10px;
  --l1: #1e7a4f; --l2: #1f6feb; --l3: #8a5a00; --l4: #6941c6; --l5: #5d6b7a; --syn: #9a3412;
  /* Thai-capable system fonts: Windows (Leelawadee UI, Tahoma), Apple (Thonburi via -apple-system), Android/Linux */
  font-family: -apple-system, BlinkMacSystemFont, "Leelawadee UI", "Segoe UI", "Noto Sans Thai", "Sarabun",
               Thonburi, Tahoma, "Loma", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 15px; line-height: 1.6; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1 { font-size: 1.45rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.12rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: .6rem 0 .4rem; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.muted, .meta { color: var(--muted); font-size: .85rem; }
.lead { color: var(--muted); margin-top: 0; max-width: 72ch; }

.demo-banner { background: var(--warn-bg); color: var(--warn); border-bottom: 2px solid #f3b27a;
  padding: 8px 16px; text-align: center; font-size: .9rem; }
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center;
  gap: 12px; padding: 10px 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; }
.brand span { color: var(--accent); }
.navcb, .navbtn { display: none; }
.nav { display: flex; flex-wrap: wrap; gap: 4px 14px; order: 3; flex-basis: 100%; min-width: 0;
  border-top: 1px solid var(--line); padding-top: 6px; }
.ngroup { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.nlabel { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; margin-right: 2px; }
.nav a { padding: 5px 9px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-size: .92rem; }
.nav a.on, .nav a:hover { background: #eef3fd; color: var(--accent); text-decoration: none; }
.logout { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.who { color: var(--muted); font-size: .85rem; }
.pill { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; font-size: .75rem; }

.btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 8px 14px;
  font: inherit; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 5px 10px; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; max-width: 100%; }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: .4rem 0; }
form.stack { display: flex; flex-direction: column; gap: 6px; margin: .8rem 0; max-width: 360px; }
form.stack label { font-size: .85rem; color: var(--muted); }
form.stack .btn { align-self: flex-start; }
.small { font-size: .85rem; }

.flash { background: #e8f5ee; border: 1px solid #b7e1c8; padding: 8px 12px; border-radius: 8px; }
.empty { color: var(--muted); background: var(--panel); border: 1px dashed var(--line); padding: 16px;
  border-radius: var(--radius); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: .4rem 0 1rem; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px;
  color: var(--ink); font-size: .9rem; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi b { display: block; font-size: 1.5rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.product .thumb { display: block; aspect-ratio: 244 / 170; background: #eef0f3; }
.product .thumb img { width: 100%; height: 100%; object-fit: cover; }
.product .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.product .title { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.product .price { font-weight: 700; }
.rank { font-weight: 700; color: var(--accent); font-size: .9rem; }
.noimg { aspect-ratio: 244 / 170; display: grid; place-items: center; color: var(--muted); }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.srclink { font-size: .85rem; }
.delta.up { color: var(--good); font-weight: 700; }
.delta.down { color: var(--bad); font-weight: 700; }

.badge { display: inline-block; font-size: .72rem; border-radius: 6px; padding: 1px 7px; border: 1px solid;
  white-space: normal; }
.b-l1 { color: var(--l1); border-color: var(--l1); }
.b-l2 { color: var(--l2); border-color: var(--l2); }
.b-l3 { color: var(--l3); border-color: var(--l3); }
.b-l4 { color: var(--l4); border-color: var(--l4); }
.b-l5, .b-na { color: var(--l5); border-color: var(--l5); }
.b-synthetic { color: var(--syn); border-color: var(--syn); background: var(--warn-bg); font-weight: 600; }

.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f9fafb; color: var(--muted); font-weight: 600; white-space: nowrap; }
.status-feasible, .f-fresh { color: var(--good); font-weight: 600; }
.status-conditional, .f-stale { color: var(--l3); font-weight: 600; }
.status-blocked, .status-not_recommended, .f-expired { color: var(--bad); font-weight: 600; }
.f-never, .f-not_scheduled { color: var(--muted); }

.chart { width: 100%; height: auto; background: #fff; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick, .bars .tick { fill: var(--muted); font-size: 11px; }
.chart .line { stroke: var(--accent); stroke-width: 2.5; }
.chart .line.alt { stroke: var(--l4); }
.chart .dot { fill: var(--accent); }
.bars { width: 100%; max-width: 420px; height: auto; }
.bars .bar { fill: var(--accent); }

.detail { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 20px; }
.detail .hero { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.board { display: grid; grid-template-columns: repeat(7, minmax(190px, 1fr)); gap: 12px; overflow-x: auto;
  padding-bottom: 8px; }
.lane { background: #eef1f5; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.lane h3 { margin-top: 0; font-size: .95rem; }
.ticket { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.ticket select, .ticket input { width: 100%; margin: 4px 0; font-size: .85rem; }

.login-box { max-width: 380px; margin: 8vh auto; }
.login-box label { display: block; margin: .6rem 0 .2rem; }
.login-box input { width: 100%; }
.error { color: var(--bad); }
.foot { color: var(--muted); font-size: .8rem; padding: 24px 16px 32px; }
.note { font-size: .82rem; color: var(--muted); }

@media (max-width: 860px) {
  .cols2, .detail { grid-template-columns: 1fr; }
  .detail .hero { max-width: 360px; }  /* keep product data above the fold on tablet/phone */

  /* touch targets: >= 40px tall on phones/tablets (WCAG 2.5.8 minimum is 24px) */
  button, .btn, .btn.small, select, input:not([type=hidden]):not([type=checkbox]) { min-height: 40px; }
  .chip, .navbtn { min-height: 36px; display: inline-flex; align-items: center; }
  .navbtn { display: inline-block; cursor: pointer; padding: 6px 10px; border: 1px solid var(--line);
    border-radius: 8px; margin-left: auto; }
  .nav { display: none; flex-direction: column; order: 3; flex-basis: 100%; gap: 8px; }
  .ngroup { flex-direction: column; align-items: stretch; }
  .nlabel { margin: 4px 0 0; }
  .nav a { min-height: 40px; display: flex; align-items: center; }
  .logout { margin-left: 0; }
  .navcb:checked ~ .nav { display: flex; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .board { grid-template-columns: repeat(7, minmax(170px, 80vw)); }
  .who { display: none; }
}

/* ---------- V0.4 ---------- */
.tag { display: inline-block; font-size: .72rem; border-radius: 6px; padding: 1px 7px; font-weight: 600; }
.tag.ev { background: #e8f0fe; color: var(--l2); }
.tag.hyp { background: #f4ecff; color: var(--l4); }
.rec { display: inline-block; font-size: .78rem; font-weight: 700; border-radius: 6px; padding: 2px 8px; }
.rec-high-priority { background: #e3f4ea; color: var(--good); }
.rec-watchlist { background: #e8f0fe; color: var(--l2); }
.rec-experiment { background: #fff4e5; color: var(--l3); }
.rec-low-priority, .rec-none { background: #f0f2f5; color: var(--muted); }
.meter { display: inline-block; width: 90px; height: 8px; background: #e9edf2; border-radius: 4px; overflow: hidden;
  vertical-align: middle; }
.meter .fill { display: block; height: 100%; background: var(--accent); }
.w0{width:0}.w5{width:5%}.w10{width:10%}.w15{width:15%}.w20{width:20%}.w25{width:25%}.w30{width:30%}.w35{width:35%}
.w40{width:40%}.w45{width:45%}.w50{width:50%}.w55{width:55%}.w60{width:60%}.w65{width:65%}.w70{width:70%}
.w75{width:75%}.w80{width:80%}.w85{width:85%}.w90{width:90%}.w95{width:95%}.w100{width:100%}
.opp-list { display: grid; gap: 12px; }
.opp { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; }
.opp .thumb img { width: 120px; height: 84px; object-fit: cover; border-radius: 8px; background: #eef0f3; }
.opp .num { font-size: 1.3rem; font-weight: 800; color: var(--accent); margin-right: 6px; }
.opp h2, .opp h3 { margin: 0 0 4px; }
.score { font-size: 1.05rem; }
.score b { font-size: 1.35rem; }
.reasons { margin: .4rem 0 0; padding-left: 0; list-style: none; display: grid; gap: 4px; }
.reasons li { overflow-wrap: anywhere; }
.comp { display: grid; grid-template-columns: max-content max-content minmax(0, 1fr); gap: 2px 10px; align-items: center;
  font-size: .85rem; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 12px; margin-top: 8px; }
.fgrid label { display: flex; flex-direction: column; gap: 3px; font-size: .85rem; color: var(--muted); }
.cmpbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: .4rem 0 1rem; }
.cmp { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.cmp input { width: 20px; height: 20px; }
.gallery { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.gallery img { width: 84px; height: 60px; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; }
.review { border-bottom: 1px solid var(--line); padding: 8px 0; }
.review:last-child { border-bottom: 0; }
.review .orig { color: var(--muted); font-size: .88rem; }
.stars { color: #b7791f; letter-spacing: 1px; }
.hist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
@media (max-width: 860px) {
  .opp { grid-template-columns: 1fr; }
  .opp .thumb img { width: 100%; height: 140px; }
  .comp { grid-template-columns: minmax(0, 1fr) max-content; }
  .comp .basis { grid-column: 1 / -1; }
}
.comp .basis, td, .reasons li { overflow-wrap: anywhere; }
.mwrap { white-space: nowrap; }
[data-testid=compare-table] img { width: 160px; max-width: 160px; } [data-testid=compare-table] th, [data-testid=compare-table] td { min-width: 140px; white-space: normal; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.real-banner { background: #eef4ff; color: #1d3b6b; padding: 8px 16px; font-size: .88rem; border-bottom: 1px solid #c9d8f2; }
.real-banner a { color: inherit; text-decoration: underline; }
.stale { color: #b45309; font-weight: 600; }

/* iPhone Safari zooms into inputs below 16px on focus */
@media (max-width: 860px) { input, select, textarea { font-size: 16px; } }
.onboard { border-left: 4px solid var(--accent); }
.onboard ol { margin: .4rem 0 0; padding-left: 1.2rem; display: grid; gap: 6px; }
.onboard .done { color: var(--good); font-weight: 600; }
.srclink { display: inline-block; padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: .85rem;
  background: #fff; }
select { max-width: 100%; } form.inline { flex-wrap: wrap; max-width: 100%; } form.inline label { max-width: 100%; display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
[data-testid=cost-lines] td:nth-child(2), [data-testid=cost-lines] td:nth-child(3) { white-space: nowrap; }
