/* สไตล์พื้นฐานของแอพ — เพิ่มทีละหน้าที่ต่อไป (task นี้มีแค่หน้าล็อกอินกับโครงเปล่า) */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  background: #f4f5f7;
  color: #1f2430;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  padding: 32px 28px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 24px;
  text-align: center;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: #555;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  font-size: 15px;
}

.btn-primary {
  width: 100%;
  padding: 11px 12px;
  border: none;
  border-radius: 8px;
  background: #2f6feb;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.error-text {
  color: #c62828;
  font-size: 13px;
  margin: 12px 0 0;
  min-height: 16px;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
}

/* หน้าคิว/รายละเอียดออเดอร์แทนที่ .app-shell (ไม่ใช่ flex-center อีกต่อไป) — ดู queue.js/order.js:render() */
.app-view {
  min-height: 100vh;
}

/* ---------- ปุ่มและสไตล์ร่วม (มือถือก่อน จอแตะขั้นต่ำ 48px สเปก §8) ---------- */
.btn-secondary {
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  background: #fff;
  color: #1f2430;
  font-size: 15px;
  cursor: pointer;
}
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn-danger {
  background: #fff;
  border: 1px solid #e57373;
  color: #c62828;
}
.btn-big {
  width: 100%;
  min-height: 56px;
  font-size: 17px;
  font-weight: 600;
}
button.btn-primary { /* index.html เดิมมี .btn-primary width:100% จากฟอร์มล็อกอิน — คงไว้ ใช้ร่วมกันได้ */
  min-height: 48px;
}
/* ขั้นต่ำ 48px ตามสเปก §8 (ผู้ใช้แตะจอด้วยถุงมือ) — เดิม 40px เตี้ยเกินไป ตอนนี้ centering เนื้อหาด้วย flex
   แทนที่จะพึ่ง padding ให้กล่องสูงขึ้นเฉยๆ */
.btn-del, .btn-flag {
  min-height: 48px;
  min-width: 48px;
  padding: 6px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- แถบ/ป้าย ---------- */
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  margin-left: 6px;
  color: #fff;
}
.badge-gold { background: #b8860b; }
.badge-ack { background: #c62828; }
.badge-flag { background: #ef6c00; }

.stale-badge {
  background: #fff3cd;
  color: #7a5c00;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin: 8px 16px 0;
}

.needs-ack-bar {
  background: #fdecea;
  border-left: 4px solid #c62828;
  padding: 12px 16px;
  margin: 8px 16px 0;
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.needs-ack-text { font-size: 14px; color: #7a1f1f; flex: 1 1 200px; }

/* ---------- คิว ---------- */
.tabs {
  display: flex;
  overflow-x: auto;
  gap: 6px;
  padding: 12px 16px 8px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}
.tab {
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid #d7dae0;
  border-radius: 999px;
  background: #f4f5f7;
  color: #1f2430;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.tab.active {
  background: #2f6feb;
  border-color: #2f6feb;
  color: #fff;
}

.queue-list {
  padding: 12px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.queue-card {
  display: block;
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  text-decoration: none;
  color: #1f2430;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.queue-card-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-weight: 600;
}
.queue-card-dealer { font-size: 13px; color: #666; margin-top: 4px; }
.queue-card-recipient { font-size: 14px; margin-top: 2px; }
.queue-card-lines { font-size: 13px; color: #555; margin-top: 4px; }
.queue-card-by { font-size: 12px; color: #888; margin-top: 6px; }

.empty {
  color: #888;
  font-size: 14px;
  padding: 24px 16px;
  text-align: center;
}

/* ---------- รายละเอียดออเดอร์ ---------- */
.order-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  margin-bottom: 4px;
  color: #2f6feb;
  text-decoration: none;
  font-size: 14px;
}
.order-code {
  font-size: 20px;
  margin: 0 0 12px;
}
.status-plain {
  font-size: 15px;
  color: #555;
  padding: 12px 0;
}
.primary-reason {
  color: #c62828;
  font-size: 13px;
  margin-top: 6px;
  text-align: center;
}
.load-error {
  color: #c62828;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recipient-block, .lines-block, .photos-block, .trackings-block, .delivery-block, .actions-block, .history-block {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.recipient-block > button { margin-top: 10px; }
.recipient-address, .recipient-phone { font-size: 14px; margin-top: 2px; color: #444; }
.recipient-name { font-weight: 600; font-size: 16px; }

h2 { font-size: 15px; margin: 0 0 10px; }

.lines-list, .tracking-list, .photo-list, .history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.line-row {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.line-row:last-child { border-bottom: none; }
.line-check {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 48px;
}
.line-check input[type="checkbox"] {
  width: 24px;
  height: 24px;
}
.line-flag {
  flex-basis: 100%;
  background: #fff8e1;
  color: #7a5c00;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
}

.photo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.photo-thumb {
  position: relative;
  width: 88px;
}
.photo-thumb img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}
.photo-thumb .btn-del { margin-top: 4px; width: 100%; }

.file-btn {
  display: block;
  text-align: center;
  cursor: pointer;
}
.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tracking-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}
.tracking-row:last-child { border-bottom: none; }
.tracking-src { color: #888; font-size: 12px; }
.tracking-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.tracking-add input {
  flex: 1 1 160px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  font-size: 15px;
}

.delivery-block select {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  font-size: 15px;
}

.actions-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-list li {
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 13px;
}
.history-list li:last-child { border-bottom: none; }
.hist-meta { color: #888; display: block; font-size: 11px; margin-top: 2px; }

/* ---------- กล่องยืนยันส่งแล้ว (สเปก §8 — ปุ่มส่งแล้วต้องผ่านกล่องยืนยันเสมอ) ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal-card {
  background: #fff;
  border-radius: 14px 14px 0 0;
  padding: 20px 20px 28px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ship-confirm-text {
  white-space: pre-line;
  font-size: 15px;
  background: #f4f5f7;
  padding: 12px;
  border-radius: 8px;
}
.ship-confirm-warn {
  color: #c62828;
  font-size: 13px;
  margin: 0;
}

/* ---------- สแกนเลขพัสดุ (สเปก §5.5, Task 11) ---------- */
.scan-pending {
  background: #eef6ff;
  border: 1px solid #bcdcff;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.scan-pending-label { font-size: 14px; }
.scanner-hint { font-size: 13px; color: #666; margin: 0; }
.scanner-engine-label { font-size: 12px; color: #888; margin: 0; }
.scanner-video, .scanner-vendor-region {
  width: 100%;
  min-height: 240px;
  background: #000;
  border-radius: 8px;
  object-fit: cover;
}
.scanner-error {
  color: #c62828;
  font-size: 13px;
  margin: 0;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: -120px;
  transform: translateX(-50%);
  background: #1f2430;
  color: #fff;
  padding: 10px 10px 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 90vw;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: bottom 0.2s ease;
  z-index: 100;
}
.toast-show { bottom: 24px; }
.toast-error { background: #c62828; }
.toast-text { flex: 1 1 auto; }
/* ปุ่ม "ลองใหม่" ในตัว toast เอง (สเปก §8) — ขั้นต่ำ 48px เหมือนปุ่มอื่นทุกตัว */
.toast-retry-btn {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #1f2430;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- หน้าบังคับเปลี่ยนรหัสผ่าน (must_change_password) ---------- */
.gate-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  padding: 32px 28px;
}
.gate-card h1 { font-size: 18px; margin: 0 0 8px; }
.gate-hint { font-size: 13px; color: #666; margin: 0 0 20px; }

/* ================== หน้าแอดมิน (task 10) ================== */

/* ---------- เมนูแอดมิน (เห็นเฉพาะ role admin) — อยู่นอก #app เพื่อไม่ให้ถูกล้างทุกครั้งที่หน้าเปลี่ยน ---------- */
/* :not([hidden]) เจาะจงเฉพาะตอนไม่ซ่อน — กัน display:flex (author stylesheet) ชนะ [hidden]{display:none}
   ของ UA stylesheet เสมอไม่ว่า attribute hidden จะตั้งไว้หรือไม่ (เจอจากการเดินจริง: ทีมแพ็คเห็นแถบดำเปล่า
   ค้างอยู่บนสุดจอทั้งที่ core.js ตั้ง nav.hidden = true ให้แล้วตอน role !== 'admin') */
.admin-nav:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  background: #1f2430;
  padding: 6px 10px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.admin-nav a {
  color: #cfd6e4;
  text-decoration: none;
  font-size: 13px;
  padding: 10px 10px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
}
.admin-nav a:hover, .admin-nav a:focus { background: rgba(255, 255, 255, 0.1); color: #fff; }

/* ---------- โครงหน้าแอดมินร่วม ---------- */
.admin-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}
.admin-title { font-size: 19px; margin: 0 0 12px; }
.admin-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.admin-card h2 { font-size: 15px; margin: 0 0 10px; }
.admin-hint { font-size: 13px; color: #7a5c00; background: #fff8e1; padding: 8px 10px; border-radius: 6px; margin: 8px 0; }

.admin-denied {
  padding: 32px 16px;
  text-align: center;
}
.admin-denied p { color: #c62828; font-size: 15px; margin-bottom: 16px; }

.admin-error-banner {
  background: #fdecea;
  color: #7a1f1f;
  border-left: 4px solid #c62828;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 14px;
}
.admin-warn-banner {
  background: #fdecea;
  color: #7a1f1f;
  border-left: 4px solid #c62828;
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 14px;
}
.admin-warn-banner ul { margin: 0; padding-left: 18px; }

/* ---------- อินพุตของฟอร์มแอดมิน (ขั้นต่ำ 48px เหมือนปุ่ม สเปก §8) ---------- */
.admin-input {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 8px;
  background: #fff;
  font-family: inherit;
}
.admin-input:disabled { background: #f4f5f7; color: #888; }
.admin-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 8px;
}
.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field { flex: 1 1 0; }
.admin-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  font-size: 14px;
}

/* ---------- ฟอร์มสร้าง/แก้ไขออเดอร์: สองคอลัมน์ (ฟอร์ม + ข้อความต้นฉบับ) ---------- */
.admin-two-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (min-width: 860px) {
  .admin-two-col { flex-direction: row; align-items: flex-start; }
  .admin-col-form { flex: 1 1 60%; min-width: 0; }
  .admin-col-raw { flex: 1 1 40%; min-width: 0; position: sticky; top: 12px; }
}

.addr-suggest-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.addr-suggest {
  text-align: left;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  background: #f4f5f7;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- ตารางบรรทัดในฟอร์มร่าง/แก้ไข ---------- */
.line-edit-list { list-style: none; margin: 0 0 10px; padding: 0; }
.line-edit-row {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.line-attention-row { background: #fff8e1; border-color: #f0c14b; }
.line-name-unit { display: flex; gap: 6px; flex: 1 1 180px; min-width: 140px; }
.line-fixed-name { font-size: 14px; padding: 8px 0; }
.line-unit-hint { color: #888; font-size: 12px; }
.line-qty { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.line-qty label { font-size: 12px; color: #666; }
.qty-input { width: 72px; min-width: 72px; }
.qty-disabled { color: #888; padding: 0 8px; }
.line-freebie { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; min-height: 48px; }
.line-freebie-badge {
  background: #fce4ec;
  color: #ad1457;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
}
.line-attention-text { flex-basis: 100%; color: #7a5c00; font-size: 13px; }
.line-add-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---------- รายการออเดอร์ (แอดมิน) ---------- */
.admin-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.admin-filter-bar .admin-input { width: auto; flex: 1 1 160px; margin-bottom: 0; }
.admin-order-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.admin-order-row {
  display: block;
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  text-decoration: none;
  color: #1f2430;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.admin-order-row-top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; }
.admin-order-code { font-weight: 700; }
.admin-order-status { font-size: 12px; color: #666; background: #f4f5f7; padding: 2px 8px; border-radius: 999px; }
.admin-order-row-dealer { font-size: 13px; color: #666; margin-top: 4px; }
.admin-order-row-recipient { font-size: 14px; margin-top: 2px; }
.admin-order-row-lines { font-size: 13px; color: #555; margin-top: 4px; }
.admin-order-row-time { font-size: 12px; color: #888; margin-top: 4px; }

.admin-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-top: 8px;
}

.admin-subnav { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.admin-subnav a {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  color: #1f2430;
  text-decoration: none;
  font-size: 14px;
  border: 1px solid #d7dae0;
}
.admin-subnav a.active { background: #2f6feb; border-color: #2f6feb; color: #fff; }

/* ---------- เครื่องมือแอดมินบนหน้ารายละเอียดออเดอร์ ---------- */
.admin-order-extras { border: 1px dashed #d7dae0; }
.admin-btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-gold-short-badge {
  background: #fdecea;
  color: #c62828;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 14px;
}
.admin-flag-list { margin-top: 12px; }
.admin-flag-list h3 { font-size: 13px; margin: 0 0 6px; color: #7a5c00; }
.admin-flag-list ul { list-style: none; margin: 0; padding: 0; }
.admin-flag-list li {
  background: #fff8e1;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.badge-gold-short { background: #c62828; }

/* ---------- ตารางทั่วไป (สต็อค/ของแถม/สินค้า/ตัวแทน/ผู้ใช้) ---------- */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 10px;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}
.admin-table th { color: #666; font-weight: 600; }
.admin-row-inactive { opacity: 0.5; }
.admin-edit-row input, .admin-edit-row select { min-height: 40px; }
.stock-negative { color: #c62828; font-weight: 700; }

/* ---------- ภาพรวม ---------- */
.admin-dash-counts .admin-stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.admin-stat {
  flex: 1 1 100px;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  background: #f4f5f7;
  text-decoration: none;
  color: #1f2430;
  display: flex;
  flex-direction: column;
  min-height: 48px;
  justify-content: center;
}
.admin-stat-n { font-size: 22px; font-weight: 700; }
.admin-stat-label { font-size: 12px; color: #666; }
.admin-dash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
  text-decoration: none;
  color: #1f2430;
  font-size: 13px;
  min-height: 48px;
}
.admin-dash-row:last-child { border-bottom: none; }
