:root {
  --bg: #EEF1F5; --panel: #FFFFFF; --ink: #1B2433; --muted: #5D6B7E; --line: #D6DCE4;
  --live: #E5383B; --gold: #F2A900; --teal: #0F8B8D; --navy: #18233A;
  --order: #F2A900; --price: #0F8B8D; --question: #4C6EF5; --greeting: #8E9AAF; --chat: #C5CCD6;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Anuphan', 'Leelawadee UI', Tahoma, sans-serif; line-height: 1.55; }
h2 { font-size: 1.07rem; margin: 0; font-weight: 600; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; font-weight: 600; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal) 55%, transparent); outline-offset: 2px; }

/* ---------- แถบบน ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.2rem; padding: .6rem 1.4rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; display: flex; align-items: center; gap: .55rem; font-size: 1.05rem; }
.mark { width: 22px; height: 22px; border-radius: 6px; background: var(--navy); position: relative; }
.mark::after { content: ''; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--live); right: 4px; top: 4px; }
.tabs { display: flex; gap: .2rem; flex-wrap: wrap; }
.tab { border: 0; background: none; padding: .5rem .85rem; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--navy); color: #fff; }
.count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 999px; background: var(--gold); color: var(--ink); font-size: .8rem; text-align: center; }
.chips { margin-left: auto; display: flex; gap: .4rem; }
.chip { font-size: .8rem; padding: .15rem .6rem; border-radius: 999px; background: var(--bg); color: var(--muted); }
.chip.on { background: color-mix(in srgb, var(--teal) 15%, #fff); color: var(--teal); }
.chip.error { background: #fde8e8; color: var(--live); }

main { max-width: 1440px; margin: 0 auto; padding: 1.2rem 1.4rem 4rem; }
.pane { display: none; }
.pane.active { display: block; }

/* ---------- แถบออกอากาศ ---------- */
.onair { background: var(--navy); color: #fff; border-radius: 14px; padding: 1.2rem 1.4rem; display: grid; grid-template-columns: auto 1fr auto; gap: .6rem 1.4rem; align-items: center; margin-bottom: 1.2rem; }
.onair-state { display: flex; align-items: center; gap: .55rem; font-size: .95rem; }
.onair .dot { width: 12px; height: 12px; border-radius: 50%; background: #56627a; }
.onair.is-live .dot { background: var(--live); box-shadow: 0 0 0 0 rgba(229,56,59,.6); animation: ring 1.6s infinite; }
@keyframes ring { 70% { box-shadow: 0 0 0 10px rgba(229,56,59,0); } 100% { box-shadow: 0 0 0 0 rgba(229,56,59,0); } }
.timer { color: #a9b4c8; font-variant-numeric: tabular-nums; }
.onair-text { margin: 0; font-size: 1.35rem; line-height: 1.5; font-weight: 500; min-height: 2.1em; max-width: 70ch; }
.onair-text .kind { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; background: rgba(255,255,255,.12); margin-right: .5rem; vertical-align: middle; }
.onair-actions { display: flex; gap: .5rem; }
.stats { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .3rem 2rem; margin: .4rem 0 0; padding-top: .8rem; border-top: 1px solid rgba(255,255,255,.12); }
.stats div { display: flex; gap: .5rem; align-items: baseline; }
.stats dt { color: #a9b4c8; font-size: .85rem; }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- ปุ่ม / ฟอร์ม ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); padding: .5rem .95rem; border-radius: 8px; cursor: pointer; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); }
.btn.danger { color: var(--live); }
.btn.live { background: var(--live); border-color: var(--live); color: #fff; padding: .7rem 1.4rem; font-size: 1.05rem; font-weight: 600; }
.onair:not(.is-live) .btn.live { background: #fff; color: var(--navy); border-color: #fff; }
.btn.ghost-light { background: transparent; color: #cfd6e3; border-color: rgba(255,255,255,.25); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--teal); cursor: pointer; text-decoration: none; font-size: .9rem; }
label { display: block; font-size: .87rem; color: var(--muted); margin-bottom: .8rem; }
input:not([type=checkbox]):not([type=file]):not([type=color]), select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
input[type=color] { display: block; margin-top: .25rem; width: 64px; height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
input[type=file] { display: block; margin-top: .3rem; font-size: .85rem; }
label.check { display: flex; gap: .5rem; align-items: center; color: var(--ink); }
label.mini { margin: 0; }
.row { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 140px; margin-top: 0; }
.row.tight { gap: .4rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.hint { color: var(--muted); font-size: .83rem; font-weight: 400; }

/* ---------- แผง ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .9rem; }
.grid3 { display: grid; grid-template-columns: minmax(220px, 300px) 1fr 1fr; gap: 1.2rem; }
.grid3 .panel { margin-bottom: 1.2rem; }
.split { display: grid; grid-template-columns: minmax(320px, 1fr) 1fr; gap: 1.2rem; align-items: start; }
.preview { aspect-ratio: 9/16; border-radius: 10px; overflow: hidden; background: var(--bg); }
.preview iframe { width: 100%; height: 100%; border: 0; }

.current { display: grid; grid-template-columns: 88px 1fr; gap: .9rem; align-items: center; margin-bottom: .9rem; }
.current .pimg { width: 88px; height: 88px; border-radius: 10px; background: var(--bg) center/cover; display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.current .pname { font-weight: 600; font-size: 1.05rem; }
.current .pprice { font-size: 1.4rem; font-weight: 700; color: var(--teal); }
.current .pmeta { color: var(--muted); font-size: .85rem; }
.flash-on { color: var(--ink); background: var(--gold); padding: 0 .4rem; border-radius: 4px; font-size: .8rem; font-weight: 600; }

.feed { list-style: none; margin: 0 0 .8rem; padding: 0; height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; }
.feed li { padding: .4rem .6rem .4rem .7rem; border-left: 4px solid var(--chat); background: var(--bg); border-radius: 0 8px 8px 0; font-size: .92rem; }
.feed li b { margin-right: .35rem; }
.feed li .tag { float: right; font-size: .75rem; color: var(--muted); }
.feed li.order { border-color: var(--order); background: #fff7e0; }
.feed li.price { border-color: var(--price); }
.feed li.question { border-color: var(--question); }
.feed li.greeting { border-color: var(--greeting); }
.feed li.event { border-color: #d63384; background: #fdeef5; }
.feed li.empty { border: 0; background: none; color: var(--muted); }
.sim input:first-child { flex: 0 0 110px; min-width: 0; }

.log { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; font-size: .9rem; }
.log li { display: grid; grid-template-columns: 64px 92px 1fr; gap: .6rem; padding: .35rem 0; border-bottom: 1px solid var(--bg); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .k { font-size: .78rem; color: var(--muted); }
.log li.error { color: var(--live); }
.log li.order { color: #8a6100; }

/* ---------- สินค้า ---------- */
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: grid; grid-template-columns: 56px 1fr auto; gap: .8rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--bg); }
.plist li.off { opacity: .5; }
.plist .pimg { width: 56px; height: 56px; border-radius: 8px; background: var(--bg) center/cover; display: grid; place-items: center; font-size: .8rem; color: var(--muted); font-weight: 600; }
.plist .meta { color: var(--muted); font-size: .85rem; }
.plist .acts { display: flex; gap: .25rem; }
.plist .acts button { padding: .3rem .55rem; }
.img-preview img { max-height: 120px; border-radius: 8px; margin-bottom: .8rem; }

/* ---------- ออเดอร์ ---------- */
.table-wrap { overflow-x: auto; }
table.orders { width: 100%; border-collapse: collapse; font-size: .92rem; }
.orders th { text-align: left; color: var(--muted); font-weight: 500; padding: .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.orders td { padding: .5rem; border-bottom: 1px solid var(--bg); vertical-align: top; }
.orders .num { text-align: right; font-variant-numeric: tabular-nums; }
.orders select { width: auto; margin: 0; padding: .25rem .4rem; }
.orders input { width: 64px; margin: 0; padding: .25rem .4rem; text-align: right; display: inline-block; }

/* ---------- ตั้งค่า ---------- */
.settings { max-width: 960px; }
.prov { display: none; }
.savebar { position: sticky; bottom: 0; background: var(--bg); padding: .8rem 0; display: flex; gap: 1rem; align-items: center; }
.pstate { font-size: .85rem; color: var(--muted); }
.pstate.on { color: var(--teal); }
.pstate.error { color: var(--live); }
.steps { margin: 0 0 1rem; padding-left: 1.3rem; }
.url-row { display: flex; gap: .6rem; align-items: center; margin-bottom: .5rem; flex-wrap: wrap; }
.url-row code, pre.code { background: var(--bg); padding: .45rem .7rem; border-radius: 8px; font-size: .88rem; }
pre.code { overflow-x: auto; white-space: pre; }

.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%) translateY(150%); background: var(--navy); color: #fff; padding: .7rem 1.2rem; border-radius: 10px; transition: transform .25s; z-index: 50; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--live); }

@media (max-width: 1100px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .preview-panel { grid-column: 1 / -1; max-width: 320px; }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .onair { grid-template-columns: 1fr; }
  .grid3, .two, .three { grid-template-columns: 1fr; }
  .chips { margin-left: 0; }
  .log li { grid-template-columns: 56px 1fr; }
  .log .k { display: none; }
}
@media (prefers-reduced-motion: reduce) { .onair.is-live .dot { animation: none; } .toast { transition: none; } }
