:root {
  --bg: #f4f6fa; --panel: #fff; --line: #e3e7ef; --text: #1d2433; --muted: #6b7486;
  --brand: #1f5fbf; --brand-soft: #e8f0fc;
  --green: #1f9d55; --green-soft: #e3f5ea; --yellow: #d99a00; --yellow-soft: #fff4d6;
  --red: #d33a2c; --red-row: #fde4e1; --orange: #e5780b; --orange-row: #ffe9d2; --grey-soft: #eef0f4;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 6px 12px; color: var(--text); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: #14223b; color: #c9d3e6; flex-shrink: 0; display: flex; flex-direction: column; }
.side .logo { padding: 18px 16px 14px; font-weight: 700; color: #fff; font-size: 16px; line-height: 1.3; }
.side .logo small { display: block; font-weight: 400; color: #8fa0bf; font-size: 12px; }
.side nav a { display: flex; align-items: center; gap: 8px; padding: 9px 16px; color: inherit; text-decoration: none; border-left: 3px solid transparent; }
.side nav a:hover { background: rgba(255,255,255,.05); }
.side nav a.on { background: rgba(255,255,255,.09); color: #fff; border-left-color: #5b9bff; }
.side nav .sec { padding: 14px 16px 4px; font-size: 11px; color: #71809c; text-transform: uppercase; letter-spacing: .04em; }
.side nav .cnt { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.side .me { margin-top: auto; padding: 14px 16px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.side .me button { margin-top: 6px; background: transparent; color: #c9d3e6; border-color: rgba(255,255,255,.2); padding: 3px 10px; }
.main { flex: 1; min-width: 0; padding: 18px 22px 40px; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.top h1 { font-size: 20px; margin: 0; }
.top .sync { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12.5px; }
.err { color: var(--red); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 12px; min-width: 110px; text-align: left; }
.chip b { display: block; font-size: 20px; line-height: 1.2; }
.chip span { color: var(--muted); font-size: 12px; }
.chip.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.chip.late b { color: var(--red); } .chip.wait b { color: var(--yellow); } .chip.done b { color: var(--green); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }

.tablewrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; max-height: calc(100vh - 290px); }
table.list { border-collapse: collapse; width: 100%; font-size: 13px; }
table.list th { position: sticky; top: 0; background: #f7f9fc; text-align: left; font-weight: 600; padding: 8px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; cursor: pointer; user-select: none; }
table.list td { padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.red td { background: var(--red-row); }
table.list tr.orange td { background: var(--orange-row); }
table.list td.n { color: var(--muted); text-align: right; }
.nowrap { white-space: nowrap; }
.prod { min-width: 220px; }
.sub { color: var(--muted); font-size: 12px; }

.st { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500; }
.dot { width: 18px; height: 18px; border-radius: 5px; display: inline-grid; place-items: center; font-size: 11px; color: #fff; flex-shrink: 0; }
.dot.y { background: var(--yellow); } .dot.g { background: var(--green); } .dot.x { background: #9aa3b2; } .dot.r { background: var(--red); }
.late { color: var(--red); font-weight: 600; } .today { color: var(--orange); font-weight: 600; } .soon { color: var(--yellow); font-weight: 600; }
.tag { display: inline-block; border-radius: 5px; padding: 1px 7px; font-size: 12px; margin: 0 4px 3px 0; white-space: nowrap; font-weight: 500; }
.tag.clear, .tag.saleerr { background: var(--red); color: #fff; }
.tag.disc { background: var(--orange); color: #fff; }
.tag.urgent { background: #7b3fe4; color: #fff; }
.pill { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: 12px; background: var(--grey-soft); white-space: nowrap; }
.pill.cancel { background: #fde4e1; color: var(--red); } .pill.post { background: #fff4d6; color: #9a6b00; } .pill.ok { background: var(--green-soft); color: var(--green); }
.who { font-size: 11px; color: var(--muted); }
td select.act { min-width: 150px; }

.login { max-width: 360px; margin: 12vh auto; }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
table.plain { border-collapse: collapse; width: 100%; }
table.plain th, table.plain td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.plain input[type=number] { width: 70px; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #14223b; color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 9; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .side { width: auto; }
  .side nav { display: flex; overflow-x: auto; }
  .side nav .sec { display: none; }
  .side nav a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; }
  .side nav a.on { border-bottom-color: #5b9bff; }
  .side .me { display: none; }
  .main { padding: 14px 16px 30px; }
  .tablewrap { max-height: none; }
}
td .sub.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 260px; }
.tag.wrongtick { background: var(--red); color: #fff; }
.tag.clearance { background: #1f7fbf; color: #fff; }
.tick { display: inline-block; border: 1px solid var(--line); color: #b3b9c5; border-radius: 5px; padding: 0 6px; font-size: 11.5px; margin-right: 3px; }
.tick.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.tick.miss { border: 1px dashed var(--red); color: var(--red); }
