/* =====================================================================
   มิตรไมตรี — Design System "ลากูน" (3/11/69) · โคลนจาก AEorder แล้วเปลี่ยนเป็นโทนฟ้าน้ำทะเล
   ทิศทาง: ทางการ องค์กร / พื้นหลังขาวสะอาด / ฟ้าเป็นสี action
   ===================================================================== */
:root {
  /* palette */
  --ink:        #123a44;   /* ตัวอักษรหลัก น้ำเงินเข้มเกือบดำ */
  --ink-soft:   #5f8792;
  --line:       #d6eef1;   /* เส้นแบ่ง */
  --line-soft:  #eaf7f8;
  --paper:      #ffffff;
  --paper-2:    #f2fbfc;   /* พื้นรองอ่อนๆ */
  --blue:       #0891b2;   /* ฟ้าหลัก action */
  --blue-700:   #0b7285;
  --blue-50:    #e0f7f8;
  --green:      #1f9d5c;
  --amber:      #c9810b;
  --red:        #d23b3b;
  --shadow:     0 1px 2px rgba(8,74,92,.05), 0 4px 16px rgba(8,74,92,.07);

  --r:   10px;
  --r-sm: 7px;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;  /* ฟอนต์เดียวทั้งไทย/อังกฤษ/ตัวเลข */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper-2);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
h1,h2,h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

/* ---------- layout shell ---------- */
.topbar {
  height: 56px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; letter-spacing: .02em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: linear-gradient(135deg, var(--blue), var(--blue-700));
  color: #fff; display: grid; place-items: center;
  font-size: 13px; font-weight: 800;
}
.brand-sub { color: var(--ink-soft); font-weight: 500; font-size: 12px; }
/* โลโก้ Asado */
.brand-logo-sm { height: 44px; width: auto; display: block; }
.brand-sub-text { color: var(--ink-soft); font-weight: 500; font-size: 12px; letter-spacing: .01em; }
.brand-login { justify-content: center; margin-bottom: 4px; }
.brand-logo { height: 78px; width: auto; display: block; margin: 4px auto 0; }
.topbar-spacer { flex: 1; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-soft);
}
.user-chip b { color: var(--ink); font-weight: 600; }
.role-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--blue-50); color: var(--blue-700); font-weight: 600;
}

.shell { display: flex; min-height: calc(100vh - 56px); }
.side {
  width: 210px; background: var(--paper);
  border-right: 1px solid var(--line); padding: 14px 10px;
  flex-shrink: 0;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink-soft); font-weight: 550; font-size: 13.5px;
  cursor: pointer; margin-bottom: 2px;
}
.nav-item:hover { background: var(--line-soft); color: var(--ink); }
.nav-item.active { background: var(--blue-50); color: var(--blue-700); }
.nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: #9aa7b8; padding: 14px 12px 6px; font-weight: 600;
}
.main { flex: 1; padding: 24px 28px; max-width: 1200px; }

/* ---------- page header ---------- */
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 22px; }
.page-head p { color: var(--ink-soft); margin: 4px 0 0; font-size: 13.5px; }

/* ---------- card ---------- */
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head {
  /* ★ แถบหัวการ์ด — ฟ้าเต็มแถบ (นิยามนี้ถูกทับด้วยบล็อกล่างอีกที ตั้งให้ตรงกันไว้) */
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--blue-700);
  background: var(--blue);
}
.card-head h3 { font-size: 15px; color: #ffffff; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-sm);
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-700); }
.btn-ghost { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper-2); border-color: #cfd8e3; }
.btn-danger { background: #fff; color: var(--red); border-color: #f3cccc; }
.btn-danger:hover { background: #fdf2f2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- table ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--ink-soft);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); }
.tbl tr:hover td { background: var(--paper-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- status badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 999px;
}
.badge-lg {
  font-size: 14px; padding: 6px 16px; letter-spacing: 0.2px;
}
.badge::before { content:""; width:7px; height:7px; border-radius:50%; background: currentColor; }
.badge-lg::before { width:9px; height:9px; }
.b-draft     { background:#dfe5ec; color:#475569; }
.b-submitted { background:#cfe1fb; color:#1257c4; }
.b-confirmed { background:#c9edd8; color:#127c46; }
.b-edited    { background:#ffe7bd; color:#a86708; }
.b-invoiced  { background:#dde0fb; color:#3f49c0; }
.b-shipping  { background:#c7ecf6; color:#0d7796; }
.b-delivered { background:#c9edd8; color:#127c46; }
.b-cancelled { background:#fbd7d7; color:#b52222; }
.b-completed { background:#cbecd0; color:#1f6b25; }

/* ---------- ปุ่มสีกรองด่วน (color filter) ---------- */
.cfilter-row {
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:center;
  margin-top:10px;
  padding-top:10px;
  border-top:1px dashed var(--line-soft, #e2e8f0);
}
.cfilter {
  border:1.5px solid var(--cf, #cbd5e1);
  color:var(--cf, #475569);
  background:#fff;
  border-radius:22px;
  padding:8px 16px;
  font-size:13.5px;
  font-weight:600;
  line-height:1.2;
  cursor:pointer;
  transition:all .12s;
  white-space:nowrap;
}
.cfilter:hover { filter:brightness(0.96); background:#f8fafc; }
.cfilter.active {
  background:var(--cf, #475569);
  color:#fff;
  border-color:var(--cf, #475569);
  box-shadow:0 2px 8px rgba(0,0,0,0.18);
}

/* ---------- inputs ---------- */
.field { margin-bottom: 14px; }
.field label { display:block; font-size:12.5px; font-weight:600; color:var(--ink-soft); margin-bottom:6px; }
.input, select.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--r-sm); font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--paper);
}
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-50); }
.qty-input { width: 72px; text-align: right; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 22px; }
.stat { background:var(--paper); border:1px solid var(--line); border-radius:var(--r); padding:16px 18px; box-shadow:var(--shadow); }
.stat .k { font-size:12px; color:var(--ink-soft); font-weight:600; text-transform:uppercase; letter-spacing:.03em; }
.stat .v { font-size:26px; font-weight:700; margin-top:6px; font-variant-numeric:tabular-nums; }
.stat .v small { font-size:13px; color:var(--ink-soft); font-weight:500; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--paper-2); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background:var(--paper); border:1px solid var(--line); border-radius:14px; box-shadow:var(--shadow); padding: 32px 30px; }
.login-card .brand { justify-content:center; margin-bottom:6px; font-size:18px; }
.login-card .sub { text-align:center; color:var(--ink-soft); font-size:13px; margin-bottom:24px; }
.login-card .btn { width:100%; justify-content:center; margin-top:6px; }
.login-err { background:#fdeeee; color:var(--red); font-size:13px; padding:9px 12px; border-radius:var(--r-sm); margin-bottom:14px; }

/* ---------- misc ---------- */
.empty { text-align:center; padding:48px 20px; color:var(--ink-soft); }
.empty .big { font-size:15px; font-weight:600; color:var(--ink); margin-bottom:4px; }
.toast { position:fixed; bottom:22px; right:22px; background:var(--ink); color:#fff; padding:12px 18px; border-radius:var(--r-sm); font-size:13.5px; box-shadow:0 8px 24px rgba(0,0,0,.18); z-index:100; }
.row { display:flex; gap:10px; align-items:center; }
.spacer { flex:1; }
.muted { color:var(--ink-soft); }
.hide { display:none !important; }

/* Notification Popup */
.notif-popup {
  position: fixed; top: 70px; right: 20px; z-index: 1000;
  background: #fff; border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(200, 30, 30, 0.15);
  min-width: 300px; max-width: 380px;
  animation: notifSlideIn 0.3s ease-out;
  overflow: hidden;
}
.notif-popup-out { animation: notifSlideOut 0.4s ease-in forwards; }
.notif-popup-head {
  padding: 12px 16px;
  background: linear-gradient(135deg, #c62828, #8b0000);
  color: #fff;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: 14px;
}
.notif-popup-head button {
  background: transparent; border: none; color: #fff; font-size: 16px;
  cursor: pointer; padding: 0 6px; opacity: 0.8;
}
.notif-popup-head button:hover { opacity: 1; }
.notif-popup-body {
  padding: 14px 16px; font-size: 13.5px; color: #333;
  display: flex; align-items: center; gap: 14px;
}
.notif-count {
  font-size: 34px; font-weight: 800; color: #c62828;
  min-width: 44px; text-align: center;
}
@keyframes notifSlideIn {
  from { transform: translateX(420px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes notifSlideOut {
  to { transform: translateX(420px); opacity: 0; }
}

/* Table polish (accent red/black) */
.tbl { border-collapse: separate; border-spacing: 0; width: 100%; }
.tbl thead th {
  background: linear-gradient(180deg, #2c2c2c, #1a1a1a);
  color: #fff; font-weight: 600; font-size: 12.5px;
  padding: 10px 12px; text-align: left;
  border-bottom: 2px solid #c62828;
}
.tbl tbody tr {
  transition: background 0.15s;
}
.tbl tbody tr:nth-child(even) { background: #fafbfc; }
.tbl tbody tr:hover { background: #fff5f5; }
.tbl tbody td {
  padding: 9px 12px; font-size: 13px;
  border-bottom: 1px solid #eef1f5;
}

/* Cards polish */
.card {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}
.card-head {
  /* ★ แถบหัวการ์ด (รายการสินค้า / ออกเอกสาร ฯลฯ) — ฟ้าเต็มแถบ */
  background: var(--blue);
  padding: 12px 16px;
  border-bottom: 1px solid var(--blue-700);
}
.card-head h3 {
  font-size: 14.5px; font-weight: 700; color: #ffffff;
  margin: 0; letter-spacing: 0.2px;
}
.card-head .muted, .card-head small { color: rgba(255,255,255,.85) !important; }
.menu-btn {
  display: none;
  font-size: 20px;
  padding: 6px 10px;
  margin-right: 4px;
}
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
  animation: modalFadeIn 0.15s ease-out;
}

@media (max-width: 860px) {
  .menu-btn { display: inline-block; }
  .side {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 80vw;
    background: #fff;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    padding-top: 16px;
  }
  .side.open { transform: translateX(0); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 18px 14px; }
}

/* ==================== Modal (confirm/prompt/custom) ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  animation: modalFadeIn 0.15s ease-out;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-overlay .modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn 0.2s ease-out;
}
@keyframes modalSlideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-overlay .modal-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-overlay .modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.modal-overlay .modal-body {
  padding: 20px;
}
.modal-overlay .modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
@media (max-width: 480px) {
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal-overlay .modal { max-width: 100%; border-radius: 12px 12px 0 0; }
}

/* nav badge (notification count) */
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-label { flex: 1; }
.nav-badge {
  display: none;
  background: #e30613; color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 10px;
  min-width: 20px; text-align: center;
  line-height: 1.4;
  animation: pulseNotif 2s ease-in-out infinite;
}
@keyframes pulseNotif {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}


/* ═══════ ปรับสี UI (7/8/69) ═══════ */

/* ★ ปุ่ม "← กลับ" — เทา #6B7280 */
.btn.btn-back {
  border-color: #6B7280;
  color: #6B7280;
  background: #ffffff;
}
.btn.btn-back:hover { background: #6B7280; color: #ffffff; border-color: #6B7280; }

/* ★ ปุ่ม "ประวัติ" — น้ำเงิน #2563EB */
.btn.btn-history {
  border-color: #2563EB;
  color: #2563EB;
  background: #ffffff;
}
.btn.btn-history:hover { background: #2563EB; color: #ffffff; border-color: #2563EB; }

/* ★ การ์ดสถิติ "รายการ" — เขียว #16A34A */
.stat-green { border-color: #16A34A; }
.stat-green .stat-num { color: #16A34A; }


/* ★ เมนูฝั่งสาขา — ทาสีเฉพาะ role franchisee (ของ staff ไม่โดน) */
#sideNav[data-role="franchisee"] .nav-item[data-page="order-new"] {
  border: 1px solid #2563EB;
  color: #2563EB;
}
#sideNav[data-role="franchisee"] .nav-item[data-page="order-new"]:hover {
  background: #eaf1fe;
}
#sideNav[data-role="franchisee"] .nav-item[data-page="order-new"].active {
  background: #2563EB;
  color: #ffffff;
}
#sideNav[data-role="franchisee"] .nav-item[data-page="order-list"] {
  border: 1px solid #16A34A;
  color: #16A34A;
}
#sideNav[data-role="franchisee"] .nav-item[data-page="order-list"]:hover {
  background: #eafaf0;
}
#sideNav[data-role="franchisee"] .nav-item[data-page="order-list"].active {
  background: #16A34A;
  color: #ffffff;
}


/* ═══════════════ Mobile friendly — ชุด ก (11/8/69) ═══════════════ */

/* ตารางเลื่อนแนวนอนได้ (ตัวห่อสร้างจาก JS ให้ทุกตารางอัตโนมัติ) */
.tbl-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.tbl-scroll > table { min-width: max-content; }

/* เอกสาร (ใบ PO / ใบกำกับ) ต้องคงความกว้างจริงไว้ ห้ามให้กฎมือถือไปย่อ */
#doc-render, #doc-render * { max-width: none !important; }

@media (max-width: 860px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .main { padding: 14px 10px; }

  /* ความกว้างตายตัวที่ฝังใน inline style ให้ยืดตามจอแทน */
  .card, .card-pad, .modal-overlay .modal { max-width: 100% !important; }
  .row { flex-wrap: wrap; }
  .row > * { min-width: 0; }
  input, select, textarea, .input { max-width: 100% !important; }

  /* ปุ่มให้นิ้วโป้งกดติด */
  .btn { min-height: 40px; }
  .btn.btn-sm { min-height: 34px; }

  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  /* ฟอนต์ช่องกรอกต้อง >= 16px ไม่งั้น iOS ซูมเข้าเองทุกครั้งที่แตะ */
  input, select, textarea, .input { font-size: 16px !important; }

  .main { padding: 12px 8px; }
  .stats { grid-template-columns: 1fr; }
  .btn { padding: 10px 14px; }
  .card-head { padding: 11px 13px; }
  .card-head h3 { font-size: 14px; }
  .tbl th, .tbl td { padding: 9px 10px; font-size: 12.5px; }
  h2 { font-size: 18px; }
}


/* ═══════ Mobile ชุด ข+ค — ตารางกลายเป็นการ์ดบนจอมือถือ (11/8/69) ═══════ */
/* ทุกตารางที่มีหัวคอลัมน์จะได้คลาส .tbl-stack จาก JS อัตโนมัติ
   บนจอ <=560px แต่ละแถวกลายเป็นการ์ด แต่ละช่องขึ้นเป็น "ชื่อคอลัมน์ : ค่า"
   จอใหญ่กว่านั้นยังเป็นตารางปกติทุกอย่าง */
@media (max-width: 560px) {
  .tbl-stack { overflow-x: visible; }
  .tbl-stack > table.tbl { min-width: 0; width: 100%; }
  .tbl-stack thead { display: none; }

  .tbl-stack tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #fff;
  }
  .tbl-stack tbody tr:last-child { margin-bottom: 0; }

  .tbl-stack tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: none !important;
    padding: 6px 0;
    text-align: right;
    font-size: 13px;
  }
  .tbl-stack tbody td + td { border-top: 1px solid var(--line-soft) !important; }
  .tbl-stack tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    text-align: left;
    color: var(--ink-soft);
    font-size: 11.5px;
    font-weight: 500;
  }
  /* ช่องที่ไม่มีชื่อคอลัมน์ (ปุ่มแก้/ลบ) และแถวสรุปที่ใช้ colspan */
  .tbl-stack tbody td[data-label=""]::before { content: none; }
  .tbl-stack tbody td[data-label=""] { justify-content: flex-end; }
  .tbl-stack tbody td[colspan] { display: block; text-align: right; }
  .tbl-stack tbody td[colspan]::before { content: none; }

  /* ช่องกรอกในตารางให้เต็มความกว้างที่เหลือ กดง่ายขึ้น */
  .tbl-stack tbody td input,
  .tbl-stack tbody td select { width: auto !important; min-width: 110px; }

  /* แถวซัพในการ์ดคำสั่งซื้อ: กรอบกับปุ่มซ้อนกันแทนเรียงข้าง */
  .doc-row-wrap { flex-direction: column; align-items: stretch !important; }
  .doc-row-wrap > div:first-child { width: 100%; }
  .doc-actions { justify-content: flex-end; }
  .doc-actions .btn { flex: 1; justify-content: center; }
}


/* ═══════ แก้ผลข้างเคียงของกฎมือถือ (11/8/69 ค่ำ) ═══════ */
/* ปัญหา: กฎ `input{max-width:100%!important}` ทำให้ทุกช่องยืดเต็มจอ
   → แถบกรองกลายเป็นแถวละช่อง สูงเป็นพืด กว่าจะเห็นตัวเลขจริงต้องเลื่อนยาว
   แก้: ให้แถบกรองเป็นตาราง 2 ช่องต่อแถว และการ์ดสรุปเล็กลง */

@media (max-width: 560px) {
  /* แถบกรอง (วันที่ / สาขา / หมวด / ซัพ) — 2 ช่องต่อแถว */
  .filter-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: stretch;
  }
  .filter-row > * { max-width: none !important; width: 100% !important; min-width: 0; }
  /* ช่องค้นหาและปุ่มรีเฟรชกินเต็มแถว */
  .filter-row > input[type="search"],
  .filter-row > input[type="text"],
  .filter-row > .filter-wide { grid-column: 1 / -1; }
  .filter-row > .btn { grid-column: 1 / -1; justify-content: center; }

  /* ช่องวันที่: บังคับให้ข้อความอยู่ชิดซ้ายและเล็กลง (iOS จัดกลางเองโดยปริยาย) */
  .filter-row input[type="date"] {
    text-align: left;
    font-size: 15px !important;
    padding-left: 10px;
    -webkit-appearance: none;
    appearance: none;
  }

  /* การ์ดสรุปตัวเลข — 2 ใบต่อแถว ตัวเลขเล็กลงให้พอดีจอ */
  .stats { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .stats .card-pad { padding: 10px 12px !important; }
  .stats .stat-value,
  .stats .card-pad > div:nth-child(2) {
    font-size: 17px !important;
    line-height: 1.25;
    word-break: break-all;
  }
  .stats .muted { font-size: 11px !important; }
}


/* ═══════ การ์ดคำสั่งซื้อบนมือถือ — ลดความสูง (12/8/69) ═══════ */
@media (max-width: 560px) {
  /* ปุ่ม "ยังไม่ชำระ / แนบใบกำกับ" อยู่แถวเดียวกัน แบ่งครึ่ง ไม่กินทีละแถว */
  .doc-actions { display: flex !important; gap: 8px; margin-top: 6px; }
  .doc-actions .btn { flex: 1 1 0; min-width: 0; padding: 8px 6px !important; font-size: 12px !important; }

  /* ทุน/ขาย วางคู่กันเสมอ ไม่ตกบรรทัด */
  .doc-row-wrap > div:first-child { width: 100%; }

  /* ชิปสถานะกับวันที่บนหัวการ์ด — เล็กลง ไม่ตัดบรรทัดถี่ */
  .order-card .badge { font-size: 11px !important; padding: 3px 8px !important; }
  .order-card h3, .order-card .card-title { font-size: 15px !important; }
}


/* ═══════ แถวซัพบนมือถือ: ปุ่มอยู่ในกรอบเดียวกับข้อมูล (12/8/69) ═══════ */
/* ปัญหา: ปุ่มลอยอยู่นอกกรอบขาว บนพื้นการ์ด ทำให้กรอบดูเหมือนถูกตัด
   แก้: ให้ตัวห่อ (.doc-row-wrap) เป็นกรอบขาวแทน แล้วกล่องข้างในโปร่งใส
        ปุ่มจึงอยู่ในกรอบเดียวกับชื่อซัพและตัวเลข */
@media (max-width: 560px) {
  .doc-row-wrap {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px 12px;
    box-shadow: 0 1px 2px rgba(16,24,40,.04);
  }
  /* กล่องเดิมข้างในไม่ต้องมีพื้น/ขอบ/ระยะซ้อนอีก */
  .doc-row-wrap .doc-row {
    background: transparent !important;
    border-radius: 0 !important;
    padding: 0 !important;
  }
  /* แถบสีซ้ายของใบที่รับของแล้ว ย้ายมาไว้ที่กรอบนอกแทน */
  .doc-row-wrap:has(.doc-row[style*="border-left"]) { border-left: 3px solid #2e7d32; }
  .doc-row-wrap .doc-row[style*="border-left"] { border-left: none !important; }

  /* ปุ่มอยู่ในกรอบ เว้นจากตัวเลขด้านบนพอดี */
  .doc-actions {
    display: flex !important;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line-soft);
  }
  .doc-actions .btn { flex: 1 1 0; min-width: 0; padding: 9px 6px !important; font-size: 12.5px !important; }
}


/* ═══════ การ์ดคำสั่งซื้อ: ให้กรอบซัพเต็มความกว้าง (12/8/69) ═══════ */
/* ต้นเหตุที่กรอบขาวไม่เต็มจอ: โครงการ์ดเป็น
     .card > .row > [flex:1 → ชื่อ/ยอด/รายการซัพ] + [ปุ่มรายละเอียด]
   บนมือถือ ปุ่ม "รายละเอียด" กินความกว้างไปเกือบ 1 ใน 3 กล่อง flex:1
   จึงเหลือแค่ 2 ใน 3 → กรอบซัพทุกอันแคบตาม
   แก้: บนจอเล็กให้ .row ในการ์ดออเดอร์ตัดขึ้นบรรทัดใหม่ ปุ่มลอยไปบรรทัดของตัวเอง */
@media (max-width: 560px) {
  .card.card-pad > .row {
    flex-wrap: wrap;
    position: relative;
  }
  .card.card-pad > .row > div[style*="flex:1"] {
    flex: 1 1 100% !important;
    min-width: 0;
    width: 100%;
  }
  /* ปุ่ม "รายละเอียด" ปักมุมขวาบน ไม่เบียดความกว้างของเนื้อหา
     หมายเหตุ: ในโค้ดปุ่มถูกห่อด้วย <div> อีกชั้น จึงต้องจับที่ตัวห่อ ไม่ใช่ตัวปุ่ม */
  .card.card-pad > .row > div:not([style*="flex:1"]) {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
    width: auto;
  }
  /* เว้นที่ให้ปุ่มไม่ทับหัวข้อ */
  .card.card-pad > .row > div[style*="flex:1"] > div:first-child { padding-right: 92px; }

  /* ลดขอบในการ์ดให้เนื้อหากว้างขึ้นอีก */
  .card.card-pad { padding: 12px 10px !important; }
}


/* ═══════ ลายน้ำ "รับแล้ว" บนมือถือ (13/8/69) ═══════ */
/* บนจอเล็ก กรอบขาวย้ายไปอยู่ที่ .doc-row-wrap และ .doc-row กลายเป็นโปร่งใส
   ทำให้ (1) พื้นเขียวของแถวที่รับแล้วหายไป (2) ลายน้ำครอบแค่ส่วนบน ไม่ถึงปุ่ม
   แก้: ยกพื้นเขียวขึ้นไปที่กรอบนอก และให้ลายน้ำคลุมทั้งกรอบรวมปุ่ม */
@media (max-width: 560px) {
  /* กรอบที่มีลายน้ำ = แถวที่รับของแล้ว → คืนพื้นเขียวอ่อน */
  .doc-row-wrap:has(.doc-stamp) {
    background: #eafaf0;
    border-color: #bfe6cd;
  }
  /* ลายน้ำหลุดออกจากกล่องบน ไปคลุมทั้งกรอบ (รวมแถวปุ่ม) */
  .doc-row-wrap:has(.doc-stamp) { position: relative; }
  .doc-row-wrap .doc-stamp {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
  }
  /* จอแคบมาก ย่อตราลงหน่อยไม่ให้ล้นขอบ */
  .doc-row-wrap .doc-stamp span {
    font-size: 24px;
    padding: 4px 18px;
    letter-spacing: 2px;
  }
}
@media (max-width: 380px) {
  .doc-row-wrap .doc-stamp span {
    font-size: 20px;
    padding: 3px 14px;
    letter-spacing: 1px;
    border-width: 2px;
  }
}


/* ═══════ ตารางสินค้าให้พอดีหน้าจอ ไม่ต้องเลื่อนซ้ายขวา (19/8/69) ═══════ */
/* เดิมช่องซัพล็อก min-width 150px + ช่องราคา 90px สองช่อง = ตารางกว้างเกินจอ
   แก้: ให้ตารางกางเต็มความกว้างที่มี แล้วแบ่งสัดส่วนคอลัมน์เอง
   คอลัมน์ชื่อยืดหยุ่นได้ ที่เหลือกำหนดสัดส่วนตายตัวพอดีเนื้อหา */
.tbl-prod { width: 100%; table-layout: fixed; }
/* ★ 26/9/69 — ตารางนี้ถูก JS ห่อ .tbl-scroll อัตโนมัติ (เหมือนทุกตาราง กันจอมือถือ)
   แต่ .tbl-scroll > table { min-width:max-content } ไปทับ width:100% ด้านบน
   ทำให้ตารางกว้างเกิน .card ที่ overflow:hidden ไว้ → ส่วนเกินถูกตัดหายไปเงียบๆ (คอลัมน์ขวาหลุดขอบ)
   แก้เฉพาะจุด: บนจอปกติให้ยึด width:100% ตามเดิม ไม่แตะโหมดมือถือ (ยังเป็นการ์ดเหมือนเดิม) */
.tbl-scroll > table.tbl-prod { min-width: 0; }

.tbl-prod th, .tbl-prod td {
  overflow: hidden;
  text-overflow: ellipsis;
}
/* ชื่อสินค้า — ยาวได้ ตัดบรรทัดแทนดันตาราง */
.tbl-prod th:nth-child(1), .tbl-prod td:nth-child(1) { width: auto; white-space: normal; word-break: break-word; }
.tbl-prod th:nth-child(2), .tbl-prod td:nth-child(2) { width: 11%; white-space: normal; }
.tbl-prod th:nth-child(3), .tbl-prod td:nth-child(3) { width: 17%; }
.tbl-prod th:nth-child(4), .tbl-prod td:nth-child(4) { width: 10%; }
.tbl-prod th:nth-child(5), .tbl-prod td:nth-child(5) { width: 10%; }
.tbl-prod th:nth-child(6), .tbl-prod td:nth-child(6) { width: 10%; white-space: nowrap; }
.tbl-prod th:nth-child(7), .tbl-prod td:nth-child(7) { width: 8%;  white-space: nowrap; }
.tbl-prod th:nth-child(8), .tbl-prod td:nth-child(8) { width: 5.5%; text-align: center; }
.tbl-prod th:nth-child(9), .tbl-prod td:nth-child(9) { width: 6%;  text-align: right; }

/* ช่องกรอกในตารางกางเต็มคอลัมน์ ไม่ล็อกความกว้างเป็นพิกเซล */
.tbl-prod .prod-sup,
.tbl-prod .inline-price {
  width: 100%;
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
}
.tbl-prod .prod-sup { font-size: 12.5px; }

/* จอแคบลงหน่อย — ลดขนาดตัวอักษรและระยะห่างก่อน แล้วค่อยยอมให้เลื่อน */
@media (max-width: 1280px) {
  .tbl-prod { font-size: 12.5px; }
  .tbl-prod th, .tbl-prod td { padding-left: 6px; padding-right: 6px; }
  .tbl-prod .prod-sup { font-size: 12px; }
}
/* มือถือ/แท็บเล็ต — ปล่อยให้ระบบการ์ด (.tbl-stack) ทำงานตามเดิม ไม่บังคับ fixed */
@media (max-width: 900px) {
  .tbl-prod { table-layout: auto; }
  .tbl-prod th, .tbl-prod td { width: auto !important; }
  .tbl-prod .prod-sup, .tbl-prod .inline-price { width: auto; }
}

/* ==================== 🔔 กระดิ่งแจ้งเตือน (1/10/69) ==================== */
.bell-wrap { position: relative; margin-right: 10px; }
.bell-btn { position: relative; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line, #e5e7eb);
  background: #fff; font-size: 19px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.bell-btn:hover { background: #f5f7fa; }
.bell-badge { position: absolute; top: -4px; right: -4px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: #e53935; color: #fff; font-size: 11px; font-weight: 700; line-height: 19px; text-align: center;
  box-shadow: 0 0 0 2px #fff; }
.bell-btn.ring { animation: bellRing 0.9s ease-in-out 2; }
@keyframes bellRing {
  0%,100% { transform: rotate(0); } 15% { transform: rotate(16deg); } 30% { transform: rotate(-14deg); }
  45% { transform: rotate(10deg); } 60% { transform: rotate(-8deg); } 75% { transform: rotate(4deg); }
}
.bell-panel { position: absolute; right: 0; top: 48px; width: 380px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; box-shadow: 0 16px 40px rgba(15,31,51,.18); z-index: 1000; }
.bell-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid #eef0f3; font-weight: 700; position: sticky; top: 0; background: #fff; }
.bell-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #f1f3f5; cursor: pointer; }
.bell-item:hover { background: #f7f9fc; }
.bell-item.unread { background: #fff8e6; }
.bell-item.unread:hover { background: #fff1cc; }
.bell-ico { font-size: 20px; line-height: 1.2; }
.bell-title { font-size: 13.5px; font-weight: 600; color: var(--ink, #0f1f33); }
.bell-sub { font-size: 12px; color: #6b7280; margin-top: 2px; }
.bell-time { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.bell-dot { width: 8px; height: 8px; border-radius: 50%; background: #e53935; margin-top: 6px; flex: none; }
.bell-empty { padding: 28px 14px; text-align: center; color: #9ca3af; font-size: 13px; }
@media (max-width: 560px) {
  .bell-wrap { margin-right: 6px; }
  .bell-panel { position: fixed; left: 12px; right: 12px; top: 60px; width: auto; }
}


/* =====================================================================
   ลากูน — ชั้นปรับหน้าตา (แทนโทนแดง/ดำของ AEorder)
   ===================================================================== */
:root { --sea-1: #0891b2; --sea-2: #22c3c9; --sea-deep: #0b5f6e; --sea-foam: #e0f7f8; }
.topbar {
  background: linear-gradient(90deg, var(--sea-1), var(--sea-2));
  border-bottom: none; color: #fff;
}
/* คลื่นใต้แถบบน */
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -12px; height: 14px; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 14' preserveAspectRatio='none'%3E%3Cpath d='M0,0 C150,14 300,14 450,7 C600,0 750,0 900,7 C1050,14 1130,11 1200,5 L1200,0 Z' fill='%2322c3c9'/%3E%3C/svg%3E") no-repeat;
  background-size: 100% 100%;
}
.topbar, .topbar .brand-sub, .topbar .brand-sub-text { color: #fff; }
.topbar .brand-sub-text, .topbar .brand-sub { opacity: .85; }
.topbar .btn-ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.35); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.24); border-color: rgba(255,255,255,.5); }
.topbar .badge { background: rgba(255,255,255,.2); color: #fff; }
.topbar .brand-logo-sm { background:#fff; border-radius:12px; padding:3px 10px; height:40px; box-shadow:0 2px 8px rgba(8,74,92,.18); }   /* โลโก้บนชิปขาว */
.topbar #bellBtn { background: rgba(255,255,255,.16) !important; border-color: rgba(255,255,255,.35) !important; }

/* หัวการ์ด: ฟ้าอ่อน ตัวอักษรฟ้าเข้ม (เดิมฟ้าเต็มแถบ) */
.card-head { background: var(--sea-foam); border-bottom: 1px solid var(--line); }
.card-head h3 { color: var(--sea-deep); }
.card-head .muted, .card-head small { color: var(--ink-soft) !important; }
.card { border-radius: 12px; box-shadow: 0 1px 3px rgba(8,74,92,.05), 0 0 0 1px rgba(8,145,178,.08); }

/* ตาราง: หัวฟ้าอ่อน แทนดำ/แดง */
.tbl thead th {
  background: #ecfbfc; color: var(--sea-deep);
  border-bottom: 2px solid var(--sea-2);
}
.tbl tbody tr:nth-child(even) { background: #f8fdfd; }
.tbl tbody tr:hover { background: #e9f8f9; }
.tbl tbody td { border-bottom: 1px solid #e6f4f6; }

/* เมนูข้าง */
.nav-item.active { background: var(--sea-foam); color: var(--sea-deep); font-weight: 600; }

/* ปุ่ม */
.btn-primary { background: var(--sea-1); }
.btn-primary:hover { background: var(--blue-700); }
.btn { border-radius: 9px; }

/* ป๊อปอัปแจ้งเตือน (เดิมแดง) */
.notif-popup { box-shadow: 0 10px 40px rgba(8,74,92,.22), 0 0 0 1px rgba(8,145,178,.18); }
.notif-popup-head { background: linear-gradient(135deg, var(--sea-1), var(--sea-2)); }
.notif-count { color: var(--sea-1); }

/* หน้าเข้าสู่ระบบ: พื้นไล่ฟ้า + คลื่นด้านล่าง */
.login-wrap {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 220' preserveAspectRatio='none'%3E%3Cpath d='M0,120 C240,200 480,40 720,110 C960,180 1200,60 1440,120 L1440,220 L0,220 Z' fill='%2322c3c9' fill-opacity='.35'/%3E%3Cpath d='M0,160 C260,220 520,100 780,160 C1040,220 1240,130 1440,170 L1440,220 L0,220 Z' fill='%230891b2' fill-opacity='.45'/%3E%3C/svg%3E") bottom / 100% 220px no-repeat,
    linear-gradient(180deg, #f2fbfc 0%, #d9f4f6 100%);
}
.login-card { border-color: #cfeef1; box-shadow: 0 10px 40px rgba(8,74,92,.12); }

@media (max-width: 640px){ .topbar .brand-sub-text{display:none;} .topbar .brand-logo-sm{height:34px;padding:2px 8px;} }
.topbar .bell-btn { border-radius: 50% !important; }
@media (max-width: 640px){ .topbar .user-chip #uName{max-width:72px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:inline-block;vertical-align:middle;} }

/* ═══════════════ มิตรไมตรี (3/11/69) โครงเมนูใหม่ ═══════════════
   จอคอม: แถบเมนูด้านบนใต้หัว (เมนูรองเป็นกลุ่มดรอปดาวน์) · มือถือ: แถบเมนูล่าง + แผ่นเมนูทั้งหมดจากด้านล่าง */
.nav-sheet-head, .nav-group-title { display: none; }
.bottom-nav { display: none; }
.nav-group-btn svg, .bnav-ic svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 861px) {
  .shell { display: block; min-height: calc(100vh - 56px); }
  .side {
    width: auto; position: sticky; top: 56px; z-index: 15;
    background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 14px 24px 8px; box-shadow: 0 2px 10px rgba(8,74,92,.05);
  }
  .nav-bar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; max-width: 1280px; margin: 0 auto; }
  .side .nav-item {
    margin: 0; padding: 8px 14px; border-radius: 999px; white-space: nowrap;
    font-size: 13.5px; gap: 6px; justify-content: flex-start;
  }
  .side .nav-bar > .nav-item.active { background: var(--sea-1); color: #fff; box-shadow: 0 3px 10px rgba(8,145,178,.28); }
  .side .nav-bar > .nav-item .nav-label { flex: none; }
  .nav-group { position: relative; }
  .nav-group-btn {
    display: inline-flex; align-items: center; gap: 4px; border: 0; background: transparent; cursor: pointer;
    padding: 8px 12px 8px 14px; border-radius: 999px; font: inherit; font-size: 13.5px; font-weight: 550; color: var(--ink-soft);
  }
  .nav-group-btn:hover, .nav-group.open .nav-group-btn { background: var(--line-soft); color: var(--ink); }
  .nav-group.has-active .nav-group-btn { background: var(--sea-foam); color: var(--sea-deep); font-weight: 600; }
  .nav-group.open .nav-group-btn svg { transform: rotate(180deg); }
  .nav-group-menu {
    display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 240px; z-index: 30;
    background: #fff; border-radius: 14px; padding: 6px;
    box-shadow: 0 14px 40px rgba(8,74,92,.18), 0 0 0 1px var(--line);
  }
  .nav-group:last-child .nav-group-menu { left: auto; right: 0; }
  .nav-group.open .nav-group-menu { display: block; }
  .nav-group-menu .nav-item { border-radius: 9px; padding: 9px 12px; justify-content: space-between; }
  .nav-group-menu .nav-item .nav-label { flex: 1; }
  .main { margin: 0 auto; max-width: 1280px; padding: 24px 28px; }
}

@media (max-width: 860px) {
  .menu-btn { display: none !important; }
  .side {
    top: auto; right: 0; bottom: 0; left: 0; width: auto; max-width: none; max-height: 82vh;
    border-radius: 20px 20px 0 0; transform: translateY(105%);
    padding: 8px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -10px 30px rgba(8,74,92,.2);
  }
  .side.open { transform: translateY(0); }
  .side::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 2px auto 10px; }
  .nav-sheet-head { display: block; font-weight: 700; font-size: 15px; color: var(--ink); padding: 0 4px 10px; }
  .nav-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .side .nav-item { margin: 0; padding: 11px 12px; border-radius: 12px; background: var(--paper-2); font-size: 14px; }
  .nav-group { grid-column: 1 / -1; }
  .nav-group-btn { display: none; }
  .nav-group-title { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); padding: 10px 4px 6px; }
  .nav-group-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .nav-group-menu .nav-group-title { grid-column: 1 / -1; }
  .main { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important; }

  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 990;
    background: rgba(255,255,255,.97); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(8,74,92,.08);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav.hide { display: none; }
  .bnav-item {
    flex: 1; min-width: 0; border: 0; background: transparent; cursor: pointer; font: inherit;
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 2px; color: var(--ink-soft);
    -webkit-tap-highlight-color: transparent;
  }
  .bnav-ic { position: relative; display: flex; align-items: center; justify-content: center; width: 46px; height: 30px; border-radius: 999px; transition: background .15s; }
  .bnav-ic svg { width: 22px; height: 22px; }
  .bnav-label { font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bnav-item.active { color: var(--sea-deep); }
  .bnav-item.active .bnav-ic { background: var(--sea-foam); color: var(--sea-1); }
  .bnav-badge {
    display: none; position: absolute; top: -3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 999px; background: #e30613; color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
  }
  .nav-backdrop { z-index: 995; }
  .side { z-index: 999; }
}
.nav-sheet-foot { display: none; }
@media (max-width: 860px) {
  .topbar .user-chip, .topbar #logoutBtn { display: none !important; }
  .topbar { gap: 10px; padding: 0 14px; }
  .nav-sheet-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin: 0 0 12px; padding: 4px 4px 12px; border-bottom: 1px solid var(--line);
  }
  .nav-sheet-user { display: flex; flex-direction: column; min-width: 0; font-size: 14px; color: var(--ink); }
  .nav-sheet-user span { font-size: 12px; color: var(--ink-soft); }
  .nav-sheet-logout { flex: none; }
}
/* ★ ตัวเลขแจ้งเตือนบนเมนู: โค้ดเดิมตั้ง display="" ตอนจะโชว์ แต่ CSS ซ่อนไว้ → ไม่เคยขึ้น · มีตัวเลขเมื่อไหร่ให้ขึ้น */
.nav-badge:not(:empty) { display: inline-block; }
