@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f4f9;
  --line: #e4eaf1;
  --text: #18263d;
  --muted: #718096;
  --mint: #087e76;
  --cyan: #235da8;
  --amber: #ad6c16;
  --red: #bc4755;
  --violet: #6955a6;
  --shadow: 0 10px 30px rgba(26, 43, 73, .045);
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font: 15px/1.6 "IBM Plex Sans Thai", system-ui, sans-serif; }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid #8bb7ef; outline-offset: 2px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 20; height: 100vh; display: flex; flex-direction: column; padding: 30px 17px 22px; background: #fff; border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 11px; }
.brand-mark { display: grid; place-items: center; flex: 0 0 42px; width: 42px; height: 42px; border-radius: 13px; background: #1b3b69; color: #fff; font: 800 14px Manrope, sans-serif; letter-spacing: -.08em; }
.brand-name { display: block; font: 700 15px/1.25 Manrope, "IBM Plex Sans Thai", sans-serif; letter-spacing: -.04em; }
.brand-name strong { display: block; color: #1b3b69; }
.brand-name small { display: block; margin-top: 4px; color: #9aa7b8; font: 700 9px/1.2 Manrope, sans-serif; letter-spacing: .12em; }
.nav-heading, .sidebar-caption { margin: 45px 14px 13px; color: #8a97a8; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
#main-nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 13px; width: 100%; padding: 11px 13px; border: 0; border-radius: 10px; background: transparent; color: #69788f; text-align: left; cursor: pointer; font-weight: 600; transition: background .18s, color .18s; }
.nav-item:hover { background: #f3f6fa; color: #193a68; }
.nav-item.active { background: #eaf1fb; color: #1c4f8f; }
.nav-symbol { display: inline-grid; place-items: center; width: 22px; color: #90a0b5; font: 700 22px/1 Manrope, sans-serif; }
.nav-item.active .nav-symbol { color: #2b66aa; }
.sidebar-bottom { margin-top: auto; }
.sidebar-caption { margin-top: 0; }
.data-note { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #f9fbfe; }
.data-note > span { flex: 0 0 8px; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: #d29a3d; }
.data-note b, .data-note small { display: block; }
.data-note b { font-size: 12px; }
.data-note small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.sidebar-foot { margin: 10px 13px 0; color: #a2adba; font-size: 11px; line-height: 1.5; }
.live-source.ready > span { background: var(--mint); }
.live-source.error > span { background: var(--red); }

.workspace { min-width: 0; width: 100%; max-width: 1600px; padding: 39px clamp(22px, 3.4vw, 58px) 36px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 27px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 4px 0 1px; font: 700 clamp(28px, 3vw, 38px)/1.3 "IBM Plex Sans Thai", sans-serif; letter-spacing: -.035em; }
.eyebrow { margin: 0; color: #50719b; font: 800 10px/1.3 Manrope, sans-serif; letter-spacing: .13em; }
.page-subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.top-actions { flex: 0 0 auto; }
.menu-btn { display: none; border: 0; background: transparent; font-size: 22px; cursor: pointer; }
.ghost-btn, .icon-btn, .primary-btn, .secondary-btn, .chip, .compare-toggle { border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 9px 13px; cursor: pointer; transition: background .18s, border-color .18s, transform .18s; }
.ghost-btn, .secondary-btn { color: #35577d; font-size: 12px; font-weight: 700; }
.ghost-btn:hover, .secondary-btn:hover, .chip:hover, .compare-toggle:hover { background: #eff5fb; border-color: #b7cce5; }
.primary-btn { min-height: 42px; border-color: #1d538e; background: #1d538e; color: #fff; font-weight: 700; }
.primary-btn:hover { background: #174678; transform: translateY(-1px); }
.secondary-btn:disabled { opacity: .6; cursor: wait; }

.live-bar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 24px 0 18px; padding: 14px 18px; border: 1px solid #d6e5f2; border-radius: 12px; background: #edf5fc; }
.live-state { display: flex; align-items: center; gap: 12px; min-width: 0; }
.live-state b, .live-state small { display: block; }
.live-state b { font-size: 13px; }
.live-state small { color: #667e99; font-size: 12px; }
.pulse { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: #d29a3d; box-shadow: 0 0 0 4px rgba(210,154,61,.13); }
.live-bar.ready .pulse { background: var(--mint); box-shadow: 0 0 0 4px rgba(8,126,118,.12); }
.live-bar.fallback { border-color: #efddbf; background: #fff9ee; }
.live-bar.fallback .pulse { background: var(--amber); }
.live-bar.error { border-color: #f1d5d7; background: #fff4f4; }
.live-bar.error .pulse { background: var(--red); }
.live-bar.loading .pulse { background: var(--cyan); }

.filters { display: grid; grid-template-columns: 1.15fr repeat(4, minmax(120px, 1fr)); align-items: end; gap: 14px; margin-bottom: 20px; padding: 17px 19px; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: var(--shadow); }
.filter-heading { display: flex; align-items: center; justify-content: space-between; align-self: center; gap: 8px; }
.filter-heading b, .filter-heading small { display: block; }
.filter-heading b { font-size: 13px; }
.filter-heading small { color: var(--muted); font-size: 11px; }
.filter-icon { color: #a3b3c7; font-size: 19px; }
.filters label, .form-field { display: grid; gap: 6px; color: #5d6e84; font-size: 11px; font-weight: 600; }
select, input[type="text"], input[type="number"] { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #dbe3ec; border-radius: 8px; background: #fff; color: var(--text); }
select:hover, input[type="text"]:hover, input[type="number"]:hover { border-color: #acbfd5; }
.price-filter { min-width: 0; }
.price-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
input[type="range"] { display: block; width: 100%; min-width: 0; min-height: 40px; accent-color: #235da8; cursor: pointer; }
output { color: #233f65; font: 700 11px Manrope, sans-serif; white-space: nowrap; }

.grid { display: grid; gap: 17px; }
.kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1.55fr) minmax(270px, .9fr); }
.equal-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.card-pad { padding: 21px 23px; }
.kpi { position: relative; min-height: 127px; padding: 19px 21px; }
.kpi::before { content: ""; position: absolute; top: 0; left: 20px; width: 32px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent, var(--cyan)); }
.kpi-label { color: #68798f; font-size: 12px; }
.kpi-value { margin-top: 11px; font: 800 clamp(21px, 2.5vw, 30px)/1.25 Manrope, "IBM Plex Sans Thai", sans-serif; letter-spacing: -.04em; }
.kpi-meta { margin-top: 7px; color: var(--muted); font-size: 11px; }
.section-row { margin: 18px 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.card-head h2, .card-head h3 { margin: 0; font-size: 17px; line-height: 1.4; font-weight: 700; }
.card-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 99px; color: #72839a; font-size: 11px; white-space: nowrap; }
.pill.positive { border-color: #d5eae5; background: #eff8f5; color: var(--mint); }
.pill.negative { border-color: #f1d9dc; background: #fff3f4; color: var(--red); }
.positive { color: var(--mint); }
.negative { color: var(--red); }

.chart { display: flex; align-items: flex-end; gap: 12px; min-height: 245px; padding: 12px 8px 3px; border-bottom: 1px solid #e4eaf1; background-image: linear-gradient(#edf1f5 1px, transparent 1px); background-size: 100% 25%; }
.bar-col { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; min-width: 35px; height: 216px; }
.bar { width: min(46px, 72%); min-height: 3px; height: var(--h); border-radius: 5px 5px 0 0; background: linear-gradient(180deg, #76a7dc, #2866ad); transition: height .35s ease; }
.bar:hover { filter: brightness(1.07); }
.bar-value { color: #3c5270; font: 700 10px Manrope, sans-serif; }
.bar-label { color: #697a91; font: 700 10px Manrope, sans-serif; }
.line-chart { width: 100%; min-height: 250px; }
.line-chart svg { width: 100%; height: 250px; overflow: visible; }
.line-chart text { fill: #8996a7; font-size: 11px; font-family: Manrope, sans-serif; }
.line-chart .grid-line { stroke: #e6ebf2; stroke-width: 1; }
.line-chart .price-line { fill: none; stroke: #2866ad; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.line-chart .area { fill: url(#areaGradient); opacity: .25; }
.line-chart circle { fill: #fff; stroke: #2866ad; stroke-width: 3; }

.deal-list { display: grid; }
.deal-item { display: grid; grid-template-columns: 39px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid #edf1f5; }
.deal-item:last-child { border-bottom: 0; }
.product-icon { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 9px; background: #eaf2fa; color: #2a639e; font: 800 10px Manrope, sans-serif; }
.deal-item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.deal-item small { color: var(--muted); font-size: 11px; }
.deal-price { text-align: right; font: 800 12px Manrope, sans-serif; }
.deal-price span { display: block; margin-top: 2px; color: var(--mint); font: 600 11px "IBM Plex Sans Thai", sans-serif; }

.insight { padding: 22px; border: 1px solid #d9e7f4; border-radius: 13px; background: #edf5fc; }
.insight-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: #dcecfb; color: #245a96; font: 800 13px Manrope, sans-serif; }
.insight h3 { margin: 17px 0 6px; font-size: 17px; }
.insight p { margin: 0; color: #506985; font-size: 13px; }
.insight strong { color: #203b5b; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 740px; border-collapse: collapse; }
th { padding: 11px 12px; border-bottom: 1px solid var(--line); color: #7e8fa3; background: #f8fafc; font-size: 10px; font-weight: 700; text-align: left; }
td { padding: 13px 12px; border-bottom: 1px solid #edf1f5; font-size: 12px; }
tbody tr:hover { background: #f9fbfd; }
tbody tr:last-child td { border-bottom: 0; }
.product-cell b, .product-cell small { display: block; }
.product-cell small { color: var(--muted); font-size: 11px; }
.stock { color: var(--mint); font-size: 11px; }
.price { font: 800 12px Manrope, sans-serif; white-space: nowrap; }
.discount { color: var(--mint); font: 800 11px Manrope, sans-serif; }
.compare-toggle { padding: 5px 8px; color: #365c86; font-size: 11px; font-weight: 700; white-space: nowrap; }
.compare-toggle.selected { border-color: #bfd7ef; background: #e7f1fb; color: #1d538e; }
.source-link { color: #245d9f; text-decoration: none; }
.source-link:hover { text-decoration: underline; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.search { min-width: min(310px, 100%); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 11px; color: #64758a; font-size: 11px; font-weight: 700; }
.chip.active { border-color: #b8d3ee; background: #eaf3fc; color: #235da8; }
.empty { padding: 50px 20px; color: var(--muted); text-align: center; }
.empty b { display: block; margin-bottom: 4px; color: var(--text); }

.compare-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.compare-card { position: relative; padding: 18px; box-shadow: none; }
.compare-card h3 { margin: 12px 0 2px; font-size: 15px; }
.compare-card .remove { position: absolute; top: 12px; right: 12px; width: 29px; height: 29px; border: 1px solid var(--line); border-radius: 50%; background: #fff; cursor: pointer; }
.spec-list { display: grid; gap: 9px; margin-top: 16px; }
.spec-row { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.spec-row b { color: var(--text); text-align: right; }

.trend-list { display: grid; gap: 13px; }
.trend-row { display: grid; grid-template-columns: minmax(140px, 1fr) 1.4fr 60px; align-items: center; gap: 12px; }
.trend-row b, .trend-row small { display: block; }
.trend-row b { font-size: 12px; }
.trend-row small { color: var(--muted); font-size: 11px; }
.track { height: 7px; overflow: hidden; border-radius: 99px; background: #eaf0f5; }
.fill { width: var(--w); height: 100%; border-radius: inherit; background: var(--mint); }
.fill.up { background: var(--red); }
.trend-pct { color: var(--mint); font: 800 11px Manrope, sans-serif; text-align: right; }
.trend-pct.up { color: var(--red); }

.ai-layout { grid-template-columns: minmax(270px, .78fr) minmax(0, 1.22fr); }
.analyzer-form { display: grid; gap: 14px; }
.score-ring { position: relative; display: grid; place-items: center; width: 122px; height: 122px; margin: 6px auto 17px; border-radius: 50%; background: conic-gradient(#2a6bb3 calc(var(--score)*1%), #e8edf3 0); }
.score-ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: #fff; }
.score-ring span { position: relative; font: 800 29px/1 Manrope, sans-serif; text-align: center; }
.score-ring small { display: block; margin-top: 4px; color: var(--muted); font: 700 9px/1.3 Manrope, sans-serif; }
.ai-result h2 { margin: 0; font-size: 21px; text-align: center; }
.ai-result > p { max-width: 520px; margin: 6px auto 20px; color: var(--muted); text-align: center; }
.reason-grid { grid-template-columns: repeat(3, 1fr); }
.reason { padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.reason span { display: block; color: var(--muted); font-size: 11px; }
.reason b { display: block; margin-top: 5px; font: 800 13px Manrope, "IBM Plex Sans Thai", sans-serif; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 360px; padding: 13px 16px; border: 1px solid #cfe0ee; border-radius: 11px; background: #fff; box-shadow: 0 18px 45px rgba(25, 45, 75, .15); opacity: 0; pointer-events: none; transform: translateY(20px); transition: .25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast b, .toast span { display: block; }
.toast b { color: #235da8; font-size: 12px; }
.toast span { color: var(--muted); font-size: 11px; }
.muted { color: var(--muted); }
.mt-16 { margin-top: 16px; }
.site-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 30px; padding-top: 19px; border-top: 1px solid var(--line); color: #97a4b4; font-size: 11px; }

@media (max-width: 1250px) {
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-heading { grid-column: 1 / -1; }
}
@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col, .ai-layout { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 252px; box-shadow: 20px 0 55px rgba(20, 40, 70, .15); transform: translateX(-105%); transition: transform .24s; }
  body.menu-open .sidebar { transform: translateX(0); }
  .workspace { padding: 23px 16px 35px; }
  .topbar { align-items: flex-start; justify-content: flex-start; gap: 12px; }
  .menu-btn { display: block; margin-top: 18px; }
  .topbar-title { flex: 1; }
  .topbar h1 { font-size: 27px; }
  .top-actions { margin-top: 18px; }
  .top-actions .ghost-btn { padding: 7px 9px; white-space: nowrap; }
  .live-bar { align-items: stretch; flex-direction: column; }
  .live-bar button { align-self: flex-start; }
  .filters, .equal-col { grid-template-columns: 1fr 1fr; }
  .reason-grid { grid-template-columns: 1fr; }
  .trend-row { grid-template-columns: 1fr 1.2fr 58px; }
}
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; }
  .topbar-title { flex: 1 1 0; min-width: 0; }
  .top-actions { flex: 0 0 100%; margin: 0 0 0 36px; }
  .page-subtitle { font-size: 11px; }
  .top-actions .ghost-btn { padding: 5px 9px; font-size: 11px; }
  .filters, .equal-col, .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi { min-height: 105px; }
  .card-pad { padding: 17px; }
  .card-head { flex-wrap: wrap; }
  .chart { gap: 6px; }
  .bar-col { min-width: 27px; }
  .site-footer { display: block; }
  .site-footer span { display: block; margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
