/* ระบบเบิกคืนซิมโคราช — mobile first */
:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1f2933; --muted: #6b7785; --line: #e3e8ee;
  --primary: #0f766e; --primary-ink: #fff; --primary-soft: #e6f4f2;
  --green: #15803d; --green-bg: #e8f7ee; --green-line: #9fdcb5;
  --yellow: #a16207; --yellow-bg: #fff7db; --yellow-line: #f3d27a;
  --red: #b91c1c; --red-bg: #fdecec; --red-line: #f3aaaa;
  --grey-bg: #eef1f4; --info: #1d4ed8; --info-bg: #e8efff;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Thonburi", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--bg); }
body.has-nav { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: 0 0 .15rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; letter-spacing: .01em; }
.nowrap { white-space: nowrap; } .num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- top / bottom nav ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .55rem .9rem; background: var(--primary); color: #fff; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 700; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .04em; }
.brand-text { font-size: 1rem; }
.topnav { display: none; }
.menu { margin-left: auto; position: relative; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .4rem; padding: .3rem .5rem; border-radius: 10px; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: rgba(255,255,255,.12); }
.who { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.role-chip { font-size: .72rem; padding: .05rem .45rem; border-radius: 99px; background: rgba(255,255,255,.2); }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: #fff; color: var(--ink); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: .35rem; display: grid; }
.menu-pop a, .menu-pop .linklike { display: block; padding: .6rem .75rem; border-radius: 8px; color: var(--ink); text-decoration: none; text-align: left; width: 100%; font-size: .95rem; }
.menu-pop a:hover, .menu-pop .linklike:hover { background: var(--bg); }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { flex: 1; display: grid; justify-items: center; gap: 1px; padding: .45rem .1rem .5rem; font-size: .72rem; color: var(--muted); text-decoration: none; }
.bottomnav a .ic { font-size: 1.15rem; line-height: 1.2; }
.bottomnav a.active { color: var(--primary); font-weight: 700; }

.wrap { max-width: 1180px; margin: 0 auto; padding: .9rem; }
.page-head { margin: .2rem 0 .9rem; }
.page-head p { margin: .1rem 0 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }

/* ---------- cards / forms ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: .9rem; }
.card.center { text-align: center; } .card.narrow { max-width: 460px; }
.grid2 { display: grid; gap: .9rem; } .grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: .9rem; }
label { display: grid; gap: .3rem; font-size: .92rem; color: #3a4654; margin-bottom: .75rem; }
label.check { display: flex; align-items: flex-start; gap: .5rem; }
label.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); width: 100%; padding: .62rem .75rem; border: 1px solid #cfd7e0; border-radius: 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(15,118,110,.22); border-color: var(--primary); }
textarea { resize: vertical; }
.form-grid { display: grid; gap: 0 .9rem; grid-template-columns: 1fr; }
.field { display: grid; gap: .3rem; margin-bottom: .75rem; align-content: end; } .field .lbl { font-size: .92rem; color: #3a4654; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; padding: .62rem 1rem; min-height: 44px; border-radius: 10px; border: 1px solid #cfd7e0; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f7f9fb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; } .btn-primary:hover { background: #0c625b; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; } .btn-sm { min-height: 34px; padding: .3rem .65rem; font-size: .88rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding: .7rem 1.3rem; } .btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }

.flash, .notice { padding: .75rem .9rem; border-radius: 12px; margin-bottom: .9rem; border: 1px solid; }
.flash-ok { background: var(--green-bg); border-color: var(--green-line); color: #14532d; }
.flash-error { background: var(--red-bg); border-color: var(--red-line); color: #7f1d1d; }
.flash-info, .notice { background: var(--info-bg); border-color: #bfd0ff; color: #1e3a8a; }
.notice-warn { background: var(--yellow-bg); border-color: var(--yellow-line); color: #713f12; }
.ok-note { color: var(--green); font-weight: 600; margin: .3rem 0; }
.warn-note { color: #854d0e; background: var(--yellow-bg); border-radius: 10px; padding: .55rem .75rem; margin: .5rem 0; }

.pill { display: inline-block; min-width: 1.6em; padding: 0 .45em; border-radius: 99px; background: var(--grey-bg); font-size: .8rem; text-align: center; font-weight: 600; color: #3a4654; }
.chip { display: inline-block; padding: .08rem .55rem; border-radius: 99px; background: var(--grey-bg); font-size: .8rem; color: #3a4654; white-space: nowrap; }
.chip-warn { background: var(--yellow-bg); color: #854d0e; } .chip-info { background: var(--info-bg); color: var(--info); } .chip-busy { background: #f1e8ff; color: #6b21a8; }
.chips { list-style: none; padding: 0; margin: .3rem 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.st-available { background: var(--primary-soft); color: var(--primary); } .st-issued { background: var(--info-bg); color: var(--info); }
.st-returned_complete { background: var(--green-bg); color: var(--green); } .st-returned_mixed { background: var(--yellow-bg); color: var(--yellow); }
.st-returned_incomplete { background: var(--red-bg); color: var(--red); } .st-closed { background: var(--grey-bg); }
.sim-available { background: var(--primary-soft); color: var(--primary); } .sim-out { background: var(--info-bg); color: var(--info); } .sim-used { background: var(--grey-bg); } .sim-missing { background: var(--red-bg); color: var(--red); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1rem; padding: 0 1rem; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl-sm td, .tbl-sm th { padding: .4rem .4rem; }
.row-warn td { background: #fffbeb; } .row-off td { opacity: .5; }
.tbl .json code { font-size: .75rem; word-break: break-all; color: #475569; }
.actions { display: flex; flex-wrap: wrap; gap: .3rem; } .pinform input { width: 7.5rem; padding: .3rem .5rem; }
.pager { display: flex; gap: .5rem; justify-content: center; margin-top: .6rem; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem .9rem; margin: 0; } .dl dt { color: var(--muted); } .dl dd { margin: 0; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: .9rem; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem .9rem; display: grid; gap: .1rem; border-top: 4px solid var(--line); }
.stat b { font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; } .stat span { font-size: .84rem; color: var(--muted); }
.stat-warn { border-top-color: #f59e0b; } .stat-yellow { border-top-color: var(--yellow-line); } .stat-green { border-top-color: var(--green-line); } .stat-red { border-top-color: var(--red-line); }
.stats-sm .stat b { font-size: 1.35rem; }
.stat-carrier .carrier-name { font-weight: 800; color: var(--primary); font-size: .95rem; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: .4rem; align-items: end; height: 170px; }
.bar-col { display: grid; grid-template-rows: 1fr auto auto; height: 100%; text-align: center; }
.bar { position: relative; background: var(--bg); border-radius: 8px; overflow: hidden; }
.bar span { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 8px 8px 0 0; }
.bar-all { background: #99d5cf; } .bar-mixed { background: #f2c94c; left: 25% !important; right: 25% !important; }
.bar-lbl { font-size: .8rem; color: var(--muted); } .bar-val { font-size: .75rem; font-weight: 700; color: var(--yellow); }
.legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 .25rem 0 .6rem; } .lg-all { background: #99d5cf; } .lg-mixed { background: #f2c94c; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #0f766e 0%, #115e59 45%, #f4f6f8 45.2%); }
.no-nav .wrap { padding: 0; max-width: none; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.15); padding: 1.6rem 1.3rem; }
.login-logo { width: 54px; height: 54px; border-radius: 14px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; margin-bottom: .7rem; }

/* ---------- return-check ---------- */
.scanbar { display: flex; gap: .5rem; margin-bottom: .7rem; }
.scan-input { font-size: 1.2rem !important; padding: .75rem .9rem !important; border-width: 2px !important; border-color: var(--primary) !important; min-width: 0; }
.scanbar .btn { min-height: 52px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin: 1rem 0 .5rem; }
.list-head h2 { margin: 0; } .filter { max-width: 11rem; padding: .45rem .6rem; }
.bundle-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.bundle-list .empty, .scan-list .empty { padding: 1rem; text-align: center; color: var(--muted); background: #fff; border-radius: 12px; }
.bundle-item { width: 100%; text-align: left; font: inherit; color: inherit; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .75rem .9rem; display: grid; gap: .15rem; cursor: pointer; box-shadow: var(--shadow); }
.bundle-item:hover { border-color: var(--primary); }
.bi-main b { font-size: 1.1rem; } .bi-sub { font-size: .85rem; color: var(--muted); }

.bundle-head { position: sticky; top: 50px; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .65rem .9rem; margin-bottom: .6rem; border-left: 6px solid var(--primary); }
.bh-label { font-size: 1.35rem; font-weight: 800; letter-spacing: .01em; } .bh-meta { font-size: .85rem; color: var(--muted); }
.counters { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin-bottom: .5rem; }
.ctr { font: inherit; border: 0; border-radius: 12px; padding: .55rem .2rem; display: grid; justify-items: center; cursor: pointer; }
.ctr b { font-size: 1.65rem; line-height: 1.1; font-variant-numeric: tabular-nums; } .ctr span { font-size: .74rem; font-weight: 600; }
.ctr-green { background: var(--green-bg); color: var(--green); } .ctr-yellow { background: var(--yellow-bg); color: var(--yellow); }
.ctr-red { background: var(--red-bg); color: var(--red); } .ctr-missing { background: #e9edf2; color: #334155; }
.progress { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; } .progress span { display: block; height: 100%; width: 0; background: var(--green); transition: width .25s; }
.progress-text { margin: .25rem 0 .7rem; }
.paste { margin: -.2rem 0 .7rem; } .paste summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: .3rem 0; } .paste textarea { margin: .4rem 0; }
.last { display: flex; gap: .7rem; align-items: center; padding: .75rem .9rem; border-radius: 12px; margin-bottom: .7rem; font-size: 1.02rem; border: 2px solid; animation: pop .18s ease-out; }
.last-ic { font-size: 1.7rem; font-weight: 800; width: 2rem; text-align: center; }
@keyframes pop { from { transform: scale(.97); opacity: .6; } to { transform: none; opacity: 1; } }
.r-green { background: var(--green-bg); border-color: var(--green-line); color: #14532d; }
.r-yellow { background: var(--yellow-bg); border-color: var(--yellow-line); color: #713f12; }
.r-red { background: var(--red-bg); border-color: var(--red-line); color: #7f1d1d; }
.r-grey { background: var(--grey-bg); border-color: #d5dbe2; color: #334155; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: .6rem; overflow-x: auto; }
.tab { font: inherit; border: 0; background: none; padding: .55rem .75rem; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.scan-list { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .35rem; }
.scan { display: grid; grid-template-columns: 2rem 1fr auto auto; gap: .5rem; align-items: center; padding: .5rem .6rem; border-radius: 10px; border: 1px solid; }
.sc-ic { font-weight: 800; font-size: 1.15rem; text-align: center; } .sc-body { display: grid; } .sc-body b { font-size: 1.02rem; } .sc-msg { font-size: .84rem; }
.sc-at { font-size: .75rem; } .sc-del { border: 0; background: rgba(0,0,0,.06); width: 30px; height: 30px; border-radius: 8px; font-size: 1.1rem; cursor: pointer; color: inherit; }
.filter-note { font-size: .85rem; color: var(--muted); padding: .2rem; }
.num-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }
.num-list li { display: flex; justify-content: space-between; gap: .5rem; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .45rem .7rem; }
.og { background: var(--yellow-bg); border: 1px solid var(--yellow-line); border-radius: 12px; padding: .65rem .8rem; margin-bottom: .5rem; }
.og-codes { font-size: .88rem; margin-top: .3rem; word-break: break-word; }
.confirm-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 9; display: flex; align-items: center; justify-content: space-between; gap: .6rem; background: #fff; border-radius: var(--radius); box-shadow: 0 -2px 16px rgba(16,24,40,.12); padding: .6rem .7rem .6rem .9rem; margin-top: .6rem; }
.cb-text { display: grid; line-height: 1.25; } .cb-text b { font-size: .95rem; }
.pred-returned_complete { color: var(--green); } .pred-returned_mixed { color: var(--yellow); } .pred-returned_incomplete { color: var(--red); }
.dlg { border: 0; border-radius: 16px; padding: 1.1rem; width: min(520px, calc(100vw - 1.5rem)); box-shadow: 0 25px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(15,23,42,.45); }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; }
.sum { list-style: none; padding: 0; margin: .3rem 0; display: grid; gap: .3rem; } .sum li { padding: .45rem .7rem; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- checkout / mine / intake ---------- */
.blocked { display: flex; gap: .9rem; background: #fff1f1; border: 2px solid var(--red); border-radius: var(--radius); padding: 1rem; margin-bottom: .9rem; color: #7f1d1d; }
.blocked h2 { color: var(--red); margin-bottom: .3rem; font-size: 1.2rem; } .blocked p { margin: .2rem 0 .5rem; } .blocked-ic { font-size: 2rem; line-height: 1; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; margin-bottom: .8rem; }
.pick { display: flex; gap: .5rem; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; margin: 0; cursor: pointer; color: var(--ink); }
.pick input { width: 20px; height: 20px; flex: none; } .pick span { display: grid; } .pick:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.override { background: var(--yellow-bg); border-radius: 12px; padding: .7rem .8rem .1rem; margin-bottom: .8rem; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .35rem; margin: .5rem 0; }
.sim { display: flex; align-items: center; gap: .45rem; margin: 0; padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); }
.sim input { width: 18px; height: 18px; flex: none; } .sim-used { background: var(--grey-bg); }
.lotcode { font-size: 1.6rem; color: var(--primary); letter-spacing: .02em; }
.issue-list { list-style: none; padding: 0; margin: .4rem 0 .8rem; display: grid; gap: .25rem; font-size: .9rem; } .issue-list li { padding: .35rem .6rem; border-radius: 8px; border: 1px solid; }
.preview details summary { cursor: pointer; font-weight: 600; margin: .4rem 0; }
.export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .5rem; } .export-grid form { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; } .timeline li { border-left: 3px solid var(--line); padding: .1rem 0 .1rem .7rem; }

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  body.has-nav { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; gap: .2rem; margin-left: 1rem; }
  .topnav a { color: rgba(255,255,255,.85); text-decoration: none; padding: .45rem .75rem; border-radius: 9px; font-weight: 600; font-size: .95rem; }
  .topnav a:hover { background: rgba(255,255,255,.12); color: #fff; } .topnav a.active { background: rgba(255,255,255,.2); color: #fff; }
  .wrap { padding: 1.3rem 1.2rem; }
  h1 { font-size: 1.7rem; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stats-sm { grid-template-columns: repeat(5, 1fr); }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .confirm-bar { bottom: .8rem; }
  .return-page { max-width: 860px; margin: 0 auto; }
  .bundle-head { top: 56px; }
}
@media (min-width: 1000px) { .form-grid { grid-template-columns: repeat(4, 1fr); } }
