:root {
  --bg: #070b1f; --panel: #0f1738; --panel2: #141e48; --line: rgba(140, 170, 255, .18); --text: #e8ecff; --muted: #96a2cf;
  --gold: #f3c969; --blue: #4f7cff; --red: #ff6b7d; --green: #5fe0a0;
  --bar1: #7d9ae0; --bar2: #3e5fb8;
  --font: 'Sarabun', 'Kanit', system-ui, sans-serif; --display: 'Kanit', system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55;
  background-image: radial-gradient(900px 500px at 100% 0, rgba(79, 124, 255, .14), transparent 60%); min-height: 100vh; }
body.noscroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.ico { width: 1.1em; height: 1.1em; vertical-align: -.18em; }

/* buttons */
.b { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px; padding: 10px 16px; font: 600 .92rem var(--display); color: #fff; cursor: pointer;
  background: rgba(255, 255, 255, .08); transition: transform .15s, filter .15s; white-space: nowrap; }
.b:hover { filter: brightness(1.15); transform: translateY(-1px); }
.b:active { transform: none; }
.b-gold { background: linear-gradient(180deg, #ffd77a, #c8902f); color: #2a1900; box-shadow: 0 8px 20px -8px rgba(243, 201, 105, .7); }
.b-blue { background: linear-gradient(180deg, #4f7cff, #2c4fc4); }
.b-red { background: rgba(255, 107, 125, .16); color: #ffb3bd; box-shadow: inset 0 0 0 1px rgba(255, 107, 125, .4); }
.b-ghost { background: rgba(255, 255, 255, .05); box-shadow: inset 0 0 0 1px var(--line); }
.b-sm { padding: 6px 10px; font-size: .82rem; border-radius: 8px; }
.b-block { width: 100%; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.login video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: brightness(.45) saturate(1.2); }
.login-box { position: relative; width: min(400px, 100%); border-radius: 12px; overflow: hidden; background: linear-gradient(180deg, rgba(232, 238, 255, .97), rgba(205, 216, 245, .97)); color: #1c2340;
  border: 1px solid #8ea6e6; box-shadow: 0 0 0 1px #1d2c66, 0 30px 80px rgba(0, 0, 0, .7); animation: pop .5s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.login-box.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.win-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: linear-gradient(180deg, var(--bar1), var(--bar2)); color: #fff; font: 600 .88rem var(--display); border-bottom: 1px solid #1d2c66; }
.win-bar span { margin-right: auto; }
.win-bar i { width: 12px; height: 12px; border-radius: 3px; background: linear-gradient(180deg, #e8eeff, #9fb3ea); border: 1px solid #1d2c66; }
.login-body { padding: 24px 26px 22px; text-align: center; }
.login-logo { width: 150px; margin: -6px auto 4px; display: block; }
.login-body h1 { font-family: 'Cinzel', serif; color: #2c4fc4; font-size: 1.5rem; }
.login-body p { color: #4b5a8f; margin: 4px 0 18px; }
.login-body .fld span { color: #2c3a70; }
.login-body input { background: #fff !important; color: #1c2340 !important; border-color: #8ea6e6 !important; text-align: center; font-size: 1.2rem !important; letter-spacing: .2em; }
.err { color: #c4283c !important; min-height: 1.4em; margin: 6px 0 !important; font-weight: 600; }
.back { display: inline-block; margin-top: 14px; color: #3e5fb8; font-size: .9rem; }

/* layout */
.panel { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 10px; padding: 18px 14px; background: rgba(8, 12, 32, .95); border-right: 1px solid var(--line); }
.side-brand { display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 6px 6px 16px; border-bottom: 1px solid var(--line); }
.side-brand img { grid-row: span 2; width: 52px; height: 52px; object-fit: contain; }
.side-brand b { font: 700 1rem 'Cinzel', serif; color: var(--gold); line-height: 1.1; }
.side-brand small { color: var(--muted); font-size: .75rem; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side-nav button { all: unset; cursor: pointer; padding: 11px 14px; border-radius: 10px; font: 500 .95rem var(--display); color: #c6cff5; transition: .2s; }
.side-nav button:hover { background: rgba(79, 124, 255, .12); color: #fff; }
.side-nav button.on { background: linear-gradient(90deg, rgba(243, 201, 105, .2), transparent); color: var(--gold); box-shadow: inset 3px 0 0 var(--gold); }
.side-foot { display: grid; gap: 8px; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; padding: 16px 28px; background: rgba(7, 11, 31, .85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.35rem; margin-right: auto; }
.menu-btn { display: none; width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: #fff; font-size: 1.2rem; cursor: pointer; }
.content { padding: 24px 28px 60px; display: grid; gap: 18px; align-content: start; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card h3 { font-size: 1.05rem; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.hint { color: var(--muted); font-size: .88rem; margin: 10px 0 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { padding: 18px; border-radius: 14px; background: linear-gradient(160deg, var(--panel2), var(--panel)); border: 1px solid var(--line); }
.stat span { color: var(--muted); font-size: .85rem; }
.stat b { display: block; font: 700 2rem 'Cinzel', serif; color: var(--gold); }
.stat.warn b { color: var(--red); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.mini { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mini li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; background: rgba(255, 255, 255, .03); }
.mini img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #0a1030; }
.mini span { flex: 1; font-size: .9rem; }

/* forms */
.form { display: grid; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > span { font-size: .85rem; color: #b9c3ea; font-weight: 600; }
.fld small, .media-ctl small { color: var(--muted); font-size: .78rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: 0; transition: border-color .2s; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
select option { background: #111a40; }
textarea { resize: vertical; line-height: 1.6; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
.chk { display: flex; align-items: center; gap: 10px; font-size: .92rem; cursor: pointer; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.narrow { max-width: 480px; }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span2 { grid-column: span 2; }
.sticky-save { position: sticky; bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: 14px; background: rgba(15, 23, 56, .95); border: 1px solid rgba(243, 201, 105, .4); box-shadow: 0 20px 40px -10px rgba(0, 0, 0, .7); backdrop-filter: blur(8px); }
.sticky-save span { color: var(--muted); font-size: .85rem; }

.media-row { display: flex; gap: 14px; align-items: flex-start; }
.media-prev { width: 120px; height: 120px; flex: none; border-radius: 12px; overflow: hidden; background: repeating-conic-gradient(#1a2350 0 25%, #121a40 0 50%) 0 0/16px 16px; border: 1px solid var(--line); display: grid; place-items: center; }
.media-prev img, .media-prev video { width: 100%; height: 100%; object-fit: contain; }
.media-prev em { color: var(--muted); font-size: .78rem; font-style: normal; text-align: center; padding: 6px; }
.media-ctl { flex: 1; display: grid; gap: 8px; justify-items: start; }
.file-btn { cursor: pointer; }

/* table */
.toolbar { display: flex; gap: 10px; }
.toolbar input { flex: 1; }
.toolbar select { width: 220px; }
.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font: 500 .8rem var(--display); color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px 14px; border-bottom: 1px solid rgba(255, 255, 255, .05); vertical-align: middle; }
.tbl td small { display: block; color: var(--muted); font-size: .76rem; }
.tbl tr:hover td { background: rgba(79, 124, 255, .05); }
.tbl tr.out .cell-item img { filter: grayscale(1) brightness(.6); }
.tbl tr.out .qty-ctl input { color: var(--red); }
.cell-item { display: flex; gap: 10px; align-items: center; min-width: 220px; }
.cell-item img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; background: #0a1030; flex: none; }
.tag { font-size: .7rem; padding: 1px 7px; border-radius: 999px; background: rgba(243, 201, 105, .18); color: var(--gold); }
.qty-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.qty-ctl button { width: 30px; border: 0; background: rgba(255, 255, 255, .06); color: #fff; cursor: pointer; font-size: 1rem; }
.qty-ctl button:hover { background: rgba(79, 124, 255, .3); }
.qty-ctl input { width: 56px; border: 0; border-radius: 0; text-align: center; padding: 6px 4px; -moz-appearance: textfield; }
.qty-ctl input::-webkit-inner-spin-button { -webkit-appearance: none; }
.acts { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }

/* credits */
.cred-head { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.cred-head img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: #0a1030; }
.cred-head div { flex: 1; }
.cred-head small { display: block; color: var(--muted); }
.cred-layout { align-items: start; }
.cred-list { display: grid; gap: 10px; max-height: 620px; overflow-y: auto; }
.cred { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; background: rgba(255, 255, 255, .03); border: 1px solid rgba(255, 255, 255, .05); }
.cred-img { width: 64px; height: 80px; flex: none; border-radius: 8px; overflow: hidden; background: #0a1030; display: grid; place-items: center; }
.cred-img img { width: 100%; height: 100%; object-fit: cover; }
.cred-img em { font-size: .7rem; color: var(--muted); font-style: normal; }
.cred-info { flex: 1; font-size: .88rem; }
.cred-info small { display: block; color: var(--muted); }
.cred-acts { display: flex; flex-direction: column; gap: 4px; }

/* categories */
.cat-row { display: grid; grid-template-columns: 40px 1fr 140px 80px auto auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.cat-row small { color: var(--muted); white-space: nowrap; }
.cat-ico { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--gold); background: radial-gradient(circle at 35% 30%, #3b57b8, #121a45); }

/* articles */
.art-list { display: grid; gap: 12px; }
.art-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 16px; align-items: center; padding: 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.art-row img { width: 140px; height: 84px; object-fit: cover; border-radius: 10px; background: #0a1030; }
.art-row small { display: block; color: var(--muted); }
.art-row p { margin: 4px 0 0; color: #b9c3ea; font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ok { color: var(--green); } .no { color: var(--red); }
.md-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.md-tools button, .md-tools label { font: 500 .8rem var(--display); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); color: #dfe5ff; cursor: pointer; }
.md-tools button:hover, .md-tools label:hover { border-color: var(--gold); }
.md-tools .prev-btn { margin-left: auto; color: var(--gold); }
.md-preview { padding: 16px 20px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .2); max-height: 480px; overflow-y: auto; }
.md-preview img { border-radius: 10px; }
.md-preview h2 { margin: 18px 0 8px; color: var(--gold); }
.md-preview blockquote { margin: 10px 0; padding: 10px 14px; border-left: 3px solid var(--gold); background: rgba(243, 201, 105, .08); }
.md-preview figure { margin: 10px 0; }
.md-preview figcaption { color: var(--muted); font-size: .85rem; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(3, 5, 15, .75); backdrop-filter: blur(4px); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal-box { width: min(860px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; border-radius: 14px; overflow: hidden; background: var(--panel); border: 1px solid #5b77c9; box-shadow: 0 40px 100px rgba(0, 0, 0, .7); animation: pop .35s cubic-bezier(.2, .9, .3, 1.2); }
.modal-box .win-bar { padding: 10px 14px; font-size: .95rem; }
.x { width: 28px; height: 28px; border-radius: 6px; border: 1px solid #1d2c66; background: linear-gradient(180deg, #e8eeff, #9fb3ea); color: #1c2340; font-size: 1.1rem; line-height: 1; cursor: pointer; }
.modal-body { padding: 20px; overflow-y: auto; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; padding: 12px 18px; border-radius: 12px; background: #0f1738; border: 1px solid var(--green); color: #fff; box-shadow: 0 20px 40px rgba(0, 0, 0, .5); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .3s; }
.toast.show { transform: none; opacity: 1; }
.toast.bad { border-color: var(--red); }

/* responsive */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px) {
  .panel { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .3s; box-shadow: 20px 0 60px rgba(0, 0, 0, .6); }
  body.side-open .side { transform: none; }
  .menu-btn { display: block; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px 14px 60px; }
  .grid2, .set-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}
@media (max-width: 640px) {
  .row2, .row3 { grid-template-columns: 1fr; }
  .stats { gap: 10px; } .stat { padding: 14px; } .stat b { font-size: 1.6rem; }
  .toolbar { flex-direction: column; } .toolbar select { width: 100%; }
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .tbl td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  .tbl td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: .8rem; }
  .tbl td[data-l="สินค้า"]::before { display: none; }
  .tbl td small { display: inline; margin-left: 4px; }
  .acts { justify-content: flex-start; padding-top: 8px !important; }
  .art-row { grid-template-columns: 90px 1fr; }
  .art-row img { width: 90px; height: 64px; }
  .art-row .acts { grid-column: span 2; }
  .cat-row { grid-template-columns: 40px 1fr 1fr; }
  .cat-row input[type=number] { grid-column: span 1; }
  .media-prev { width: 90px; height: 90px; }
  .sticky-save { flex-direction: column; align-items: stretch; }
  .modal { padding: 0; }
  .modal-box { max-height: 100vh; height: 100%; border-radius: 0; }
}

/* per-piece listings */
.stat.ok b { color: var(--green); }
.code { font-family: 'Cinzel', serif; color: var(--gold); letter-spacing: .04em; }
.st { border: 0; cursor: pointer; font: 600 .8rem var(--display); padding: 6px 12px; border-radius: 999px; white-space: nowrap; transition: .15s; }
.st-ok { color: #0b3a24; background: linear-gradient(180deg, #8ff0bf, #3fbf80); }
.st-sold { color: #ffd0d6; background: rgba(255, 107, 125, .18); box-shadow: inset 0 0 0 1px rgba(255, 107, 125, .5); }
.st:hover { filter: brightness(1.12); transform: translateY(-1px); }
.tbl tr.out td { opacity: .78; }
.tbl tr.out td.acts, .tbl tr.out td[data-l="สถานะ"] { opacity: 1; }
.multi { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.multi-list { display: flex; flex-wrap: wrap; gap: 8px; }
.multi-list:empty { display: none; }
.multi-th { position: relative; width: 84px; height: 104px; border-radius: 10px; overflow: hidden; background: #0a1030; border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); }
.multi-th img { width: 100%; height: 100%; object-fit: cover; }
.multi-th button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .7); color: #fff; cursor: pointer; line-height: 1; }
.toolbar select { width: 200px; }
@media (max-width: 640px) { .toolbar select { width: 100%; } }

/* bulk select & delete */
.tbl th.sel, .tbl td.sel { width: 36px; padding-right: 0; }
.tbl .sel input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--red); }
.tbl tr.picked td { background: rgba(255, 107, 125, .08); }
.bulk-bar { position: sticky; top: 8px; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px;
  background: rgba(40, 12, 24, .95); border: 1px solid rgba(255, 107, 125, .45); box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .7); }
.bulk-bar[hidden] { display: none; }
.bulk-bar span { margin-right: auto; font-weight: 600; color: #ffb3bd; }
@media (max-width: 760px) { .tbl td.sel { position: absolute; right: 12px; width: auto; } .tbl tr { position: relative; } .tbl td.sel::before { display: none; } }

/* หัวกลุ่มในรายการเลือก (ขายแล้ว / พร้อมขาย) แถบขาว ตัวหนังสือสีดำ */
select optgroup { background: #fff; color: #000; font-weight: 700; font-style: normal; }
select optgroup option { background: #111a40; color: #e8ecff; font-weight: 400; }
