:root {
      /* aligned to the site theme (navy/gold + Sarabun) */
      --primary: #1d2f6e;
      --primary-ink: #16255c;
      --bg: #f4f6fa;
      --line: #dde3ef;
      --muted: #5c6472;
      --ink: #20262f;
      --ring: rgba(29, 47, 110, .14);
      --ok: #1c7a43;
      --danger: #b42318;
      --gold: #b8912f;
      --serif: 'Bai Jamjuree', 'Sarabun', serif;
    }

    * { box-sizing: border-box }

    body {
      margin: 0;
      background: var(--bg);
      font-family: 'Sarabun', system-ui, sans-serif;
      color: var(--ink);
      line-height: 1.55;
    }

    .rh-title, .oc-code { font-family: var(--serif); color: var(--primary-ink) }

    svg { display: block }

    /* ===== Top bar ===== */
    .topbar { max-width: 1120px; margin: 18px auto 0; padding: 0 16px; }
    .tb-wrap {
      background: #fff; border: 1px solid var(--line); border-radius: 18px;
      display: flex; align-items: center; justify-content: space-between; gap: 14px;
      padding: 16px 22px; box-shadow: 0 6px 20px rgba(2, 6, 23, .04);
    }
    .tb-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
    .tb-icon {
      width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0;
      background: #eef2fb; color: var(--primary); display: grid; place-items: center;
    }
    .tb-icon svg { width: 26px; height: 26px; }
    .tb-text { display: flex; flex-direction: column; min-width: 0; }
    .tb-title { font-size: 20px; font-weight: 800; color: var(--ink); line-height: 1.2; }
    .tb-sub { font-size: 13px; color: var(--muted); }
    .btn-back {
      display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
      border: 1px solid var(--line); background: #fff; color: #334155;
      padding: 11px 18px; border-radius: 12px; font-weight: 700; text-decoration: none; font-size: 14px;
    }
    .btn-back svg { width: 18px; height: 18px; }
    .btn-back:hover { background: #f8fafc; border-color: #c7d2e5; }

    .wrap { max-width: 1120px; margin: 20px auto; padding: 0 16px; }

    /* ===== Toolbar ===== */
    .toolbar {
      background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 18px;
      box-shadow: 0 6px 20px rgba(2, 6, 23, .04); display: grid; gap: 14px;
    }
    .field { position: relative; }
    .field-icon {
      position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
      color: var(--muted); pointer-events: none;
    }
    .field-icon svg { width: 18px; height: 18px; }
    .field input, .field select {
      width: 100%; padding: 14px 16px 14px 46px; border: 1px solid var(--line);
      border-radius: 12px; font-size: 15px; font-family: inherit; color: var(--ink);
      background: #fff; outline: none;
    }
    .field input::placeholder { color: #94a3b8; }
    .field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
    .selectwrap select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 44px; }
    .chev { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
    .chev svg { width: 18px; height: 18px; }
    .btn-refresh {
      justify-self: start; display: inline-flex; align-items: center; gap: 8px;
      border: 1px solid #dbe7fb; background: #eef4ff; color: var(--primary);
      padding: 12px 18px; border-radius: 12px; font-weight: 700; cursor: pointer;
      font-family: inherit; font-size: 14px;
    }
    .btn-refresh svg { width: 18px; height: 18px; }
    .btn-refresh:hover { background: #e0ecff; }

    /* ===== Results head ===== */
    .results-head { display: flex; align-items: center; gap: 10px; margin: 24px 2px 14px; }
    .rh-icon { color: var(--primary); }
    .rh-icon svg { width: 22px; height: 22px; }
    .rh-title { font-size: 18px; font-weight: 800; }
    .rh-count {
      background: var(--primary); color: #fff; min-width: 24px; height: 24px; padding: 0 8px;
      border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
      font-size: 12.5px; font-weight: 700;
    }

    /* ===== Orders ===== */
    .orders { display: grid; gap: 16px; }
    .order-card {
      background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 20px 22px;
      box-shadow: 0 6px 20px rgba(2, 6, 23, .04); display: flex; align-items: center; gap: 22px;
    }
    .oc-left { flex: 1; min-width: 0; display: flex; gap: 16px; align-items: flex-start; }
    .oc-avatar {
      width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0;
      background: #eef2fb; color: var(--primary); display: grid; place-items: center;
    }
    .oc-avatar svg { width: 26px; height: 26px; }
    .oc-info { flex: 1; min-width: 0; }
    .oc-code-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
    .oc-code { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
    .oc-meta { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; }
    .oc-mcol { display: grid; gap: 8px; align-content: start; }
    .oc-mrow { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #334155; min-width: 0; }
    .oc-mrow svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
    .oc-mrow span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .oc-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; border-left: 1px solid var(--line); padding-left: 22px; }
    .oc-stat {
      display: flex; align-items: center; gap: 12px; background: #f8fafc;
      border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; min-width: 148px;
    }
    .st-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
    .st-icon svg { width: 22px; height: 22px; }
    .oc-stat.items .st-icon { background: #eef2fb; color: var(--primary); }
    .oc-stat.total .st-icon { background: #e9f9ef; color: var(--ok); }
    .st-label { font-size: 12px; color: var(--muted); }
    .st-value { font-size: 20px; font-weight: 800; line-height: 1.15; margin-top: 1px; }
    .st-sub { font-size: 11px; color: var(--muted); }
    .oc-detail {
      display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
      border: 1px solid #dbe7fb; background: #eef4ff; color: var(--primary);
      padding: 12px 16px; border-radius: 12px; font-weight: 700; cursor: pointer; font-family: inherit; font-size: 14px;
    }
    .oc-detail svg { width: 18px; height: 18px; }
    .oc-detail:hover { background: #e0ecff; }

    @media (max-width: 860px) {
      .order-card { flex-direction: column; align-items: stretch; gap: 16px; }
      .oc-right { border-left: none; padding-left: 0; border-top: 1px solid var(--line); padding-top: 16px; flex-wrap: wrap; }
      .oc-stat { flex: 1 1 140px; }
      .oc-detail { flex: 1 1 100%; justify-content: center; }
    }

    /* ===== Badges ===== */
    .badge {
      display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700;
      padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line);
    }
    .badge svg { width: 14px; height: 14px; }
    .b-pending { background: #fffbeb; border-color: #fde68a; color: #92400e; }
    .b-review { background: #f5f3ff; border-color: #ddd6fe; color: #6d28d9; }
    .b-paid { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
    .b-prep { background: #f0f9ff; border-color: #bae6fd; color: #0369a1; }
    .b-shipped { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
    .b-cancelled { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

    /* ===== States ===== */
    .state {
      background: #fff; border: 1px dashed var(--line); border-radius: 16px;
      padding: 44px 20px; text-align: center; color: var(--muted); font-size: 14px;
    }
    .state.err { color: var(--danger); border-color: #fecaca; }

    /* ===== Pager ===== */
    .pager { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 26px 0 44px; }
    .pager-row { display: flex; align-items: center; gap: 8px; }
    .pg-btn {
      width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
      display: grid; place-items: center; cursor: pointer; color: #334155;
    }
    .pg-btn svg { width: 18px; height: 18px; }
    .pg-btn:hover:not(:disabled) { border-color: #c7d2e5; }
    .pg-btn:disabled { opacity: .45; cursor: default; }
    .pg-num {
      min-width: 42px; height: 42px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--primary);
      background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700;
    }
    .pager-caption { font-size: 13px; color: var(--muted); }

    /* ===== Modal ===== */
    .modal {
      position: fixed; inset: 0; display: none; place-items: center; z-index: 40;
      background: rgba(15, 23, 42, .45); padding: 16px;
    }
    .modal.show { display: grid; }
    /* กล่องสูงได้ไม่เกินจอ แล้วให้ "เนื้อหา" เป็นตัวเลื่อน ไม่ใช่ตัวกล่อง —
       เดิม .sheet เป็น overflow:hidden และไม่มี max-height พอรายละเอียดออเดอร์ยาวขึ้น
       (สินค้าหลายรายการ + ตั๋ว + การชำระเงิน) ส่วนล่างถูกตัดทิ้งและเลื่อนดูไม่ได้เลยบนมือถือ */
    .sheet {
      width: min(460px, 96vw); max-height: min(88vh, 100% - 32px);
      display: flex; flex-direction: column;
      background: #fff; border-radius: 16px; border: 1px solid var(--line);
      box-shadow: 0 20px 50px rgba(2, 6, 23, .25); overflow: hidden;
    }
    .sheet > header {
      flex: none;
      display: flex; align-items: center; justify-content: space-between; gap: 10px;
      padding: 14px 18px; border-bottom: 1px solid var(--line);
    }
    .sheet > header b { font-size: 16px; }
    .sheet-body {
      flex: 1 1 auto; min-height: 0; padding: 18px;
      overflow-y: auto; -webkit-overflow-scrolling: touch;  /* iOS เก่าเลื่อนแบบ momentum */
      overscroll-behavior: contain;                          /* เลื่อนสุดแล้วไม่ไปลากหน้าหลังต่อ */
    }
    .btn-ghost {
      border: 1px solid var(--line); background: #fff; color: #334155; padding: 8px 14px;
      border-radius: 10px; font-weight: 700; cursor: pointer; font-family: inherit;
    }
    .btn-ghost:hover { background: #f8fafc; }
    .md-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; }
    .md-row .mk { color: var(--muted); }
    .md-hr { height: 1px; background: var(--line); margin: 10px 0; }
    .md-total { font-weight: 800; font-size: 15px; }

/* ===== 2026 member order workspace ===== */
.orders-page {
  --primary: #183477;
  --primary-ink: #102451;
  --gold: #b8912f;
  --surface-soft: #f7f9fd;
  background:
    radial-gradient(circle at 85% 4%, rgba(184, 145, 47, .08), transparent 24rem),
    #f5f7fb;
}

.orders-page .orders-main { max-width: 1180px; margin-top: 30px; margin-bottom: 64px; }
.orders-hero {
  position: relative; overflow: hidden; display: flex; align-items: center;
  justify-content: space-between; gap: 32px; min-height: 210px; padding: 38px 42px;
  border: 1px solid rgba(184, 145, 47, .42); border-radius: 24px;
  color: #fff; background: linear-gradient(118deg, #0e1c46 0%, #183477 72%, #24438a 100%);
  box-shadow: 0 18px 44px rgba(14, 28, 70, .16);
}
.orders-hero::after {
  content: ""; position: absolute; width: 260px; height: 260px; right: -60px; top: -100px;
  border: 52px solid rgba(202, 164, 69, .12); border-radius: 50%; pointer-events: none;
}
.orders-hero-copy, .orders-hero-actions { position: relative; z-index: 1; }
.orders-eyebrow {
  display: inline-flex; align-items: center; gap: 9px; color: #e4c978;
  font-size: 13px; font-weight: 700; letter-spacing: .04em;
}
.orders-eyebrow::before { content: ""; width: 28px; height: 2px; background: #caa445; }
.orders-hero h1 { margin: 9px 0 8px; font: 800 clamp(28px, 4vw, 42px)/1.16 var(--serif); color: #fff; }
.orders-hero p { max-width: 610px; margin: 0; color: rgba(255,255,255,.75); font-size: 15px; }
.orders-hero-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.hero-link {
  min-height: 46px; padding: 0 17px; border: 1px solid rgba(255,255,255,.28); border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 14px; font-weight: 700; text-decoration: none; transition: .18s ease;
}
.hero-link svg { width: 18px; height: 18px; }
.hero-link.secondary { color: #fff; background: rgba(255,255,255,.08); }
.hero-link.primary { color: #102451; background: #caa445; border-color: #caa445; }
.hero-link:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(0,0,0,.14); }

.orders-page .orders-toolbar {
  margin-top: 20px; padding: 16px; display: grid; grid-template-columns: minmax(280px, 1.6fr) minmax(210px, .75fr) auto;
  align-items: center; gap: 12px; border-radius: 16px; box-shadow: 0 8px 26px rgba(15, 32, 74, .05);
}
.orders-page .field input, .orders-page .field select { min-height: 50px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.orders-page .btn-refresh { min-height: 48px; padding: 0 15px; white-space: nowrap; }
.orders-page .btn-clear { background: #fff; border-color: var(--line); color: #526078; }
.orders-page .results-head { margin: 28px 4px 14px; }
.orders-page .order-card { border-radius: 16px; transition: border-color .18s, box-shadow .18s, transform .18s; }
.orders-page .order-card:hover { border-color: rgba(184,145,47,.48); box-shadow: 0 12px 30px rgba(15,32,74,.08); transform: translateY(-1px); }

.orders-page .state { min-height: 280px; border-style: solid; padding: 48px 24px; display: grid; place-items: center; align-content: center; }
.empty-state .empty-icon {
  width: 64px; height: 64px; display: grid; place-items: center; border-radius: 18px;
  color: var(--primary); background: #eef3ff; border: 1px solid #dbe5fb;
}
.empty-state .empty-icon svg { width: 30px; height: 30px; }
.empty-state h2 { margin: 18px 0 5px; color: var(--primary-ink); font: 800 21px/1.3 var(--serif); }
.empty-state p { max-width: 470px; margin: 0; color: #68758a; }
.empty-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.empty-primary, .empty-secondary {
  min-height: 44px; padding: 0 17px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 11px; font: 700 14px var(--serif); text-decoration: none; cursor: pointer;
}
.empty-primary { border: 1px solid var(--primary); background: var(--primary); color: #fff; }
.empty-secondary { border: 1px solid #ccd6e8; background: #fff; color: var(--primary); }

@media (max-width: 900px) {
  .orders-hero { align-items: flex-start; flex-direction: column; padding: 30px; }
  .orders-hero-actions { justify-content: flex-start; }
  .orders-page .orders-toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar-actions { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .orders-page .orders-main { margin-top: 16px; padding: 0 12px; }
  .orders-hero { min-height: 0; padding: 25px 22px; border-radius: 18px; gap: 24px; }
  .orders-hero p { font-size: 14px; }
  .orders-hero-actions, .hero-link { width: 100%; }
  .orders-page .orders-toolbar { grid-template-columns: 1fr; padding: 12px; }
  .toolbar-actions { grid-column: auto; }
  .orders-page .btn-refresh { flex: 1; justify-content: center; }
  .orders-page .oc-left { gap: 12px; }
  .orders-page .oc-avatar { width: 44px; height: 44px; }
  .orders-page .oc-code { font-size: 17px; }
  .orders-page .oc-meta { grid-template-columns: 1fr; }
  .orders-page .order-card { padding: 17px; }
  .orders-page .oc-stat { min-width: 0; padding: 10px; }
  .orders-page .st-icon { width: 38px; height: 38px; }
  .orders-page .st-value { font-size: 17px; }
  .orders-page .state { min-height: 310px; }
}

/* ปุ่มกลับมาชำระเงินของออเดอร์ที่ยังค้าง (การ์ด + หน้ารายละเอียด) */
.oc-pay {
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
  border: 1px solid var(--primary, #1e3a8a); background: var(--primary, #1e3a8a); color: #fff;
  padding: 12px 18px; border-radius: 12px; font-weight: 700; cursor: pointer;
  font-family: inherit; font-size: 14px; min-height: 44px;
}
.oc-pay:hover { filter: brightness(1.08); }
.oc-pay:disabled { opacity: .65; cursor: default; }
@media (max-width: 860px) { .oc-pay { flex: 1 1 100%; } }

.md-pay {
  display: block; width: 100%; margin-top: 16px; min-height: 46px;
  border: 0; border-radius: 12px; background: var(--primary, #1e3a8a); color: #fff;
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.md-pay:hover { filter: brightness(1.08); }
.md-pay:disabled { opacity: .65; cursor: default; }
.md-payhint { margin-top: 8px; text-align: center; font-size: 12.5px; color: var(--muted, #667085); }

/* ===== โมดัลรายละเอียดคำสั่งซื้อ (ฉบับละเอียด) ===== */
.md-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding-bottom: 14px; border-bottom: 1px solid var(--line, #e6ebf4);
}
.md-code { font-family: 'Bai Jamjuree', sans-serif; font-weight: 800; font-size: 19px; color: var(--primary-ink, #102451); }
.md-when { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted, #667085); font-size: 12.5px; }
.md-when svg { width: 14px; height: 14px; flex: none; }
.md-note {
  margin-top: 12px; padding: 10px 13px; border-radius: 10px;
  background: #f1f5ff; border: 1px solid #dbe7fb; color: #1d2f6e; font-size: 13px; line-height: 1.6;
}
.md-sec { margin-top: 16px; }
.md-sec-t {
  display: flex; align-items: center; gap: 7px; margin-bottom: 8px;
  font-family: 'Bai Jamjuree', sans-serif; font-weight: 700; font-size: 13px;
  letter-spacing: .04em; text-transform: uppercase; color: var(--gold, #b8912f);
}
.md-sec-t svg { width: 15px; height: 15px; flex: none; }
.md-sec .md-row { border-bottom: 1px dashed #eef1f7; }
.md-sec .md-row:last-child { border-bottom: 0; }
.md-row span:last-child { text-align: right; }
.md-addr { max-width: 62%; }
.md-item, .md-pay-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--line, #e6ebf4); border-radius: 12px; background: #fbfcfe;
}
.md-item-name { font-weight: 700; font-size: 14px; color: #16255c; line-height: 1.45; }
.md-item-meta { margin-top: 3px; color: var(--muted, #667085); font-size: 12.5px; line-height: 1.5; }
.md-item-calc { margin-top: 4px; color: #64748b; font-size: 12.5px; }
.md-item-sum { flex: none; font-weight: 800; font-size: 14.5px; color: var(--primary-ink, #102451); }
.md-link {
  display: inline-block; margin-top: 8px; color: var(--primary, #183477);
  font-weight: 700; font-size: 13.5px; text-decoration: none;
}
.md-link:hover { text-decoration: underline; }
@media (max-width: 480px) {
  .md-head { flex-direction: column; gap: 8px; }
  .md-addr { max-width: 100%; }
}

/* ===== แจ้งชำระเงิน/แนบสลิปย้อนหลังจากหน้าคำสั่งซื้อ ===== */
.oc-wait {
  padding: 10px 12px; border: 1px dashed #dbe7fb; border-radius: 10px;
  background: #f6f9ff; color: #33415b; font-size: 13px; line-height: 1.55; text-align: center;
}
.md-bank {
  margin-bottom: 10px; padding: 10px 12px; border: 1px solid #cfe0f7; border-radius: 10px; background: #f7fbff;
}
.md-bank b { font-family: 'Bai Jamjuree', sans-serif; font-size: 15px; color: #16255c; }
.md-slip { display: grid; gap: 10px; }
.md-slip-f span { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: #334155; }
.md-slip-f .input { width: 100%; font-family: inherit; }

/* ===== สถานะการส่งรายชิ้น (migration 033) ===== */
.md-item-ship {
  display: inline-block; margin-top: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1.6;
}
.md-item-ship.wait { background: #fff5e6; color: #a35b00; border: 1px solid #f2d9b0; }
.md-item-ship.done { background: #f0faf3; color: #15803d; border: 1px solid #cfe9d8; }

/* ===== คำขอเปลี่ยนไซส์ (migration 034) ===== */
.md-exch {
  margin-top: 5px; padding: 6px 10px; border-radius: 9px;
  font-size: 12.5px; font-weight: 600; line-height: 1.6;
}
.md-exch.wait { background: #fff5e6; color: #a35b00; border: 1px solid #f2d9b0; }
.md-exch.no   { background: #fdecec; color: #a12b2b; border: 1px solid #f0c0c0; }
.md-exch.ok   { background: #f0faf3; color: #15803d; border: 1px solid #cfe9d8; }
.md-exch-btn {
  display: inline-block; margin-top: 7px; padding: 7px 14px; min-height: 40px;
  border: 1px solid #cddffb; border-radius: 999px; background: #f4f8ff;
  color: #1d3f8f; font: 600 13px 'Sarabun', sans-serif; cursor: pointer;
}
.md-exch-btn:hover:not(:disabled) { background: #e8f0ff; border-color: #1e3a8a; }
.md-exch-btn:disabled { opacity: .55; cursor: default; }

/* ===== ส่วนต่างค้างชำระจากการแลกไซส์ (migration 035) ===== */
.md-row.md-due { color: #a35b00; font-weight: 700; }
.md-due-note {
  margin-bottom: 10px; padding: 9px 12px; border-radius: 9px;
  background: #fff5e6; color: #a35b00; border: 1px solid #f2d9b0;
  font-size: 13px; line-height: 1.7;
}
