/* ── TOKENS ── */
:root {
  --bg: #f2f4f7;
  --surf: #ffffff;
  --surf2: #f8f9fa;
  --bdr: #e4e7ec;
  --bdr2: #cdd2d9;
  --ink: #101828;
  --sub: #667085;
  --hint: #98a2b3;
  --pri: #1570ef;
  --pri-l: #eff8ff;
  --pri-d: #1249b3;
  --green: #12b76a;
  --green-l: #ecfdf3;
  --gold: #f79009;
  --gold-l: #fffaeb;
  --red: #f04438;
  --red-l: #fef3f2;
  --teal: #0ba5ec;
  --teal-l: #e0f2fe;
  --violet: #7f56d9;
  --violet-l: #f4ebff;
  --orange: #ef6820;
  --orange-l: #fef6ee;
  --navy: #0c111d;
  --r: 14px;
  --r2: 10px;
  --r3: 8px;
  --r4: 6px;
  --sh: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --sh2: 0 4px 16px rgba(16, 24, 40, 0.1);
  --sh3: 0 20px 48px rgba(16, 24, 40, 0.16);
  --mono: "IBM Plex Mono", monospace;
  --sans: "Sarabun", sans-serif;
  --tab: 60px;
  --top: 56px;
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
  background: var(--bg);
}
body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
input,
select,
button,
textarea {
  font-family: inherit;
  font-size: inherit;
  outline: none;
  border: none;
  background: none;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}
button {
  cursor: pointer;
}
::-webkit-scrollbar {
  width: 0;
}

/* ── SETUP ── */
#SETUP {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.su-logo {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 2px;
  margin-bottom: 20px;
}
.su-title {
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}
.su-sub {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 28px;
}
.su-card {
  width: 100%;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 20px;
}
.su-label {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: block;
}
.su-inp {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 14px;
  color: #fff;
  margin-bottom: 8px;
  transition: 0.15s;
}
.su-inp:focus {
  border-color: var(--gold);
  outline: none;
}
.su-inp::placeholder {
  color: rgba(255, 255, 255, 0.25);
}
.su-hint {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.25);
  margin-bottom: 14px;
  line-height: 1.6;
}
.su-btn {
  width: 100%;
  background: var(--gold);
  color: #000;
  font-size: 15px;
  font-weight: 700;
  padding: 14px;
  border-radius: 10px;
}
.su-err {
  font-size: 12px;
  color: #ff6b6b;
  min-height: 18px;
  margin-top: 8px;
  text-align: center;
}

/* ── LOGIN ── */
#LOGIN {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9000;
  display: none;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.lg-header {
  padding: 52px 28px 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.lg-brand {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 2px;
  margin-bottom: 22px;
}
.lg-title {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  margin-bottom: 6px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.lg-sub {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 32px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.lg-avatars {
  display: flex;
  gap: 14px;
  padding: 0 28px;
  overflow-x: auto;
  overflow-y: hidden;
  margin-bottom: 28px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.lg-avatars::-webkit-scrollbar {
  display: none;
}
.uc {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  width: 96px;
  max-width: min(96px, 26vw);
  box-sizing: border-box;
}
.uc-av {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
  transition: 0.2s;
}
.uc-av.has-img {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
  font-size: 0;
}
.uc.sel .uc-av.has-img {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(245, 144, 9, 0.15);
  background-color: transparent;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.uc.sel .uc-av {
  border-color: var(--gold);
  background: rgba(245, 144, 9, 0.12);
  color: var(--gold);
  box-shadow: 0 0 0 4px rgba(245, 144, 9, 0.15);
}
.uc-nm {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  transition: 0.15s;
  width: 100%;
  max-width: 100%;
  text-align: center;
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.uc-rl {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.2);
  width: 100%;
  max-width: 100%;
  text-align: center;
  line-height: 1.2;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.uc.sel .uc-nm {
  color: #fff;
}
.lg-pw-area {
  padding: 0 28px;
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.lg-pw-area.show {
  display: flex;
}
.lg-who {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
  max-width: 100%;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.lg-who-role {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.35);
  max-width: 100%;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.lg-pw-box {
  position: relative;
}
.lg-pw-inp {
  width: 100%;
  background: rgba(255, 255, 255, 0.07);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 15px 44px 15px 18px;
  font-size: 16px;
  color: #fff;
  letter-spacing: 3px;
  transition: 0.15s;
}
.lg-pw-inp::placeholder {
  letter-spacing: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.2);
}
.lg-pw-inp:focus {
  border-color: rgba(247, 144, 9, 0.5);
  outline: none;
}
.lg-eye {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  font-size: 17px;
}
.lg-err {
  font-size: 12.5px;
  color: #ff6b6b;
  min-height: 16px;
}
.lg-btn {
  background: var(--gold);
  color: #000;
  font-size: 15px;
  font-weight: 700;
  padding: 15px;
  border-radius: 12px;
  transition: 0.13s;
}
.lg-btn:active {
  transform: scale(0.98);
}

/* ── APP SHELL ── */
#APP {
  display: none;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
#APP.show {
  display: flex;
}

/* ── TOPBAR ── */
#TOP {
  flex-shrink: 0;
  background: var(--surf);
  border-bottom: 1px solid var(--bdr);
  height: var(--top);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  position: relative;
  z-index: 100;
  justify-content: space-between;
}
.top-brand {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.3;
  flex-shrink: 0;
}
.top-brand small {
  display: block;
  font-size: 9px;
  font-weight: 500;
  color: var(--hint);
  letter-spacing: 0.5px;
}
.top-cust {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: 99px;
  padding: 8px 12px;
  cursor: pointer;
  transition: 0.13s;
}
.top-cust:active {
  background: var(--bdr);
}
.top-cust-txt {
  font-size: 13px;
  color: var(--hint);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-cust-txt.sel {
  color: var(--ink);
  font-weight: 600;
}
.top-av {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.user-dd {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: 12px;
  box-shadow: var(--sh2);
  min-width: 190px;
  z-index: 9999;
  overflow: hidden;
}
.user-dd.on {
  display: block;
}
.udd-hd {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--bdr);
  background: var(--surf2);
}
.udd-nm {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.udd-rl {
  font-size: 11px;
  color: var(--sub);
  margin-top: 1px;
}
.udd-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.1s;
  color: var(--ink);
}
.udd-row:hover {
  background: var(--surf2);
  color: var(--ink);
}
.udd-row.danger {
  color: var(--red);
}
.udd-row.danger:hover {
  color: var(--red);
  background: #fef3f2;
}
/* r26: Dev/Demo tools — Manager only */
[data-mgr-only] {
  display: none;
}
body.is-sale-manager [data-mgr-only] {
  display: flex;
}
body.is-sale-manager .udd-sep[data-mgr-only] {
  display: block;
}
.udd-sep {
  height: 1px;
  background: var(--bdr);
  margin: 2px 0;
}
.kf-only {
  display: none;
}
body.is-kf .kf-only {
  display: flex;
}

/* ── MAIN ── */
#MAIN {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 0;
}

/* ── COST TAB ── */
#costTab {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── PROGRESS ── */
.prog-bar-wrap {
  flex-shrink: 0;
  background: var(--surf);
  border-bottom: 1px solid var(--bdr);
  padding: 8px 16px 0;
}
.prog-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}
.prog-lbl {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--sub);
}
.prog-pct {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--pri);
}
.prog-track {
  height: 8px;
  background: #e8ecf0;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 6px;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.06);
}
.prog-fill {
  height: 100%;
  background: linear-gradient(90deg, #1849a9, #1570ef 40%, #0ba5ec);
  border-radius: 99px;
  transition: width 0.45s cubic-bezier(0.33, 1, 0.68, 1);
  width: 0;
  box-shadow: 0 0 10px rgba(21, 112, 239, 0.35);
}
.sec-pills {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 0 0 8px;
}
.sec-pills::-webkit-scrollbar {
  display: none;
}
.spill {
  flex-shrink: 0;
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.13s;
  background: var(--surf2);
  border: 1px solid var(--bdr);
  color: var(--sub);
  white-space: nowrap;
}
.spill.done {
  background: var(--green-l);
  border-color: #86efac;
  color: var(--green);
}
/* หมวดกรอกครบแล้ว — hover เป็นเขียวชัดขึ้น */
.spill.done:hover {
  background: #d1fadf;
  border-color: #12b76a;
  color: #039855;
  box-shadow: 0 2px 10px rgba(18, 183, 106, 0.22);
  transform: translateY(-1px);
}
.spill.done:active {
  transform: translateY(0);
}
.spill.act {
  background: var(--pri);
  border-color: var(--pri);
  color: #fff;
}
.spill.act.done {
  background: #ecfdf3;
  border-color: #6ce9a6;
  color: #067647;
  box-shadow: 0 0 0 1.5px rgba(18, 183, 106, 0.35);
}
.spill.act.done:hover {
  background: #d1fadf;
  border-color: #12b76a;
  color: #039855;
  box-shadow: 0 2px 12px rgba(18, 183, 106, 0.28), 0 0 0 2px rgba(18, 183, 106, 0.2);
  transform: translateY(-1px);
}

/* ── COST SCROLL ── */
#costScroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 80px;
}
.cost-section {
  scroll-margin-top: 8px;
  margin-bottom: 12px;
}

/* ── CARD ── */
.card {
  background: var(--surf);
  border-radius: var(--r);
  border: 1px solid var(--bdr);
  overflow: hidden;
  box-shadow: var(--sh);
}
/* ใบเสนอราคาใน Cost tab — อย่าตัดเนื้อหายาว (หลาย design / ตารางเยอะ) */
.card.card--proposal {
  overflow: visible;
}
.card.card--proposal > .card-hd {
  overflow: visible;
}
#proposalBody {
  overflow: visible;
}
.card-hd {
  padding: 13px 15px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--bdr);
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
  justify-content: flex-start;
}
.card-hd > div:has(.card-title) {
  flex: 1;
  min-width: 0;
}
.card-hd > .card-ico {
  flex-shrink: 0;
}
.sec-desc {
  background: #f9fafb;
  border: 1px solid var(--bdr);
  border-left: 3px solid var(--pri);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--sub);
  line-height: 1.5;
}
.sec-desc b {
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  display: block;
  margin-bottom: 2px;
}
.card-ico {
  width: 36px;
  height: 36px;
  border-radius: var(--r3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.card-sub {
  font-size: 11.5px;
  color: var(--hint);
  margin-top: 2px;
}
.chd-dark {
  background: var(--navy);
  color: #fff;
}
.chd-dark .card-title {
  color: #fff;
}
.chd-dark .card-sub {
  color: rgba(255, 255, 255, 0.4);
}
.chd-dark * {
  color: inherit;
}
/* S10 ใบเสนอราคา — header ไม่บีบชื่อเป็นตัวเดียวต่อบรรทัด + ปุ่ม wrap บนมือถือ */
.s10-card-hd {
  flex-wrap: wrap;
  align-items: flex-start;
  row-gap: 8px;
}
.s10-card-hd > .card-ico {
  margin-top: 2px;
}
.card-hd.s10-card-hd > .s10-card-hd-title {
  flex: 1 1 160px;
  min-width: 0;
}
.s10-card-hd-title .card-title {
  line-height: 1.3;
  word-break: break-word;
}
.s10-hd-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 220px;
  min-width: 0;
  overflow: visible;
}

/* S8 — ปุ่มพิมพ์/PDF ใบเต็มใต้สรุปต้นทุน */
.s8-doc-actions {
  border-top: 1px solid var(--bdr);
  padding: 12px 14px 14px;
  background: linear-gradient(180deg, #f9fafb, #fff);
}
.s8-doc-actions-hint {
  display: block;
  font-size: 10.5px;
  color: var(--hint);
  line-height: 1.4;
  margin-bottom: 10px;
}
.s8-doc-actions-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.s8-doc-btn {
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: min(100%, 120px);
}
.s8-doc-btn:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}
.s8-doc-btn--pdf {
  background: var(--teal);
  color: #fff;
}
.s8-doc-btn--print {
  background: var(--gold);
  color: #000;
}
.s8-doc-btn--view {
  background: var(--green);
  color: #fff;
}
@media (max-width: 420px) {
  .s8-doc-btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }
}
@media (max-width: 767px) {
  .s10-hd-actions {
    flex: 1 1 100%;
    justify-content: flex-start;
  }
  .s10-hd-actions button {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
  }
}
@media (max-width: 380px) {
  .s10-hd-actions button {
    flex: 1 1 100%;
  }
}
.chd-green {
  background: var(--green-l);
}
.chd-green .card-title {
  color: var(--green);
}
.chd-teal {
  background: var(--teal-l);
}
.chd-teal .card-title {
  color: var(--teal);
}
.chd-violet {
  background: var(--violet-l);
}
.chd-violet .card-title {
  color: var(--violet);
}
.chd-gold {
  background: var(--gold-l);
}
.chd-gold .card-title {
  color: var(--gold);
}
.chd-red {
  background: var(--red-l);
}
.chd-red .card-title {
  color: var(--red);
}
.chd-orange {
  background: var(--orange-l);
}
.chd-orange .card-title {
  color: var(--orange);
}

/* ── FORM ROW ── */
.frow {
  display: flex;
  align-items: center;
  padding: 0 14px;
  min-height: 50px;
  border-bottom: 1px solid var(--bdr);
  gap: 8px;
}
.frow:last-child {
  border: none;
}
.frow.hl {
  background: var(--gold-l);
}
.fl {
  font-size: 13px;
  color: var(--sub);
  font-weight: 500;
  width: 120px;
  flex-shrink: 0;
  line-height: 1.4;
}
.fv {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.sw {
  position: relative;
  flex: 1;
}
.sw::after {
  content: "›";
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%) rotate(90deg);
  font-size: 13px;
  color: var(--hint);
  pointer-events: none;
}
select {
  width: 100%;
  background: var(--surf2);
  border: 1.5px solid var(--bdr);
  border-radius: var(--r3);
  padding: 9px 28px 9px 11px;
  font-size: 13.5px;
  color: var(--ink);
  min-height: 42px;
}
select:focus {
  border-color: var(--pri);
  background: #fff;
  outline: none;
}
.ni {
  background: var(--surf2);
  border: 1.5px solid var(--bdr);
  border-radius: var(--r3);
  padding: 9px;
  font-size: 15px;
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  width: 76px;
  min-height: 42px;
  transition: 0.13s;
}
.ni:focus {
  border-color: var(--pri);
  background: #fff;
}
.unit {
  font-size: 12.5px;
  color: var(--sub);
}
.av {
  background: var(--gold-l);
  border: 1.5px solid #fec84b;
  border-radius: var(--r3);
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: #b54708;
}
.sub-hd {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 11px 14px 7px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sub-hd::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--bdr);
}
.rrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  background: var(--surf2);
}
.rrow-lbl {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--sub);
}
.rrow-val {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

/* ── DESIGN ITEM ── */
.design-item {
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--sh);
  margin-bottom: 10px;
}
.design-hd {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  background: var(--navy);
  cursor: pointer;
  user-select: none;
}
.design-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(247, 144, 9, 0.2);
  border: 1.5px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  flex-shrink: 0;
}
.design-name {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  flex: 1;
}
.design-info {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 1px;
}
.design-cost {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  background: rgba(247, 144, 9, 0.15);
  color: var(--gold);
  padding: 4px 10px;
  border-radius: 99px;
  flex-shrink: 0;
}
.design-chev {
  color: rgba(255, 255, 255, 0.35);
  font-size: 15px;
  flex-shrink: 0;
  transition: 0.2s;
}
.design-del {
  width: 28px;
  height: 28px;
  border-radius: var(--r4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  flex-shrink: 0;
}
.design-del:active {
  background: rgba(240, 68, 56, 0.25);
  color: #fda29b;
}
.design-body {
  padding: 0;
}
.design-item.closed .design-chev {
  transform: rotate(-90deg);
}
.design-item.closed .design-body {
  display: none;
}

/* tech row */
.tech-row {
  background: var(--surf2);
  border-radius: var(--r3);
  padding: 10px 12px;
  border: 1px solid var(--bdr);
  margin-bottom: 8px;
}
.tech-row-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.tech-num {
  width: 22px;
  height: 22px;
  border-radius: var(--r4);
  background: var(--violet-l);
  color: var(--violet);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.tech-del {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: var(--r4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--hint);
  cursor: pointer;
}
.tech-del:active {
  background: var(--red-l);
  color: var(--red);
}
.tech-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 7px;
}
.tech-price-row {
  display: flex;
  justify-content: flex-end;
}

/* custom fabric */
.fab-custom-box {
  background: var(--orange-l);
  border: 1.5px solid #fdba74;
  border-radius: var(--r3);
  padding: 12px 14px;
  margin: 8px 0;
}
.fab-custom-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--orange);
  margin-bottom: 10px;
}
.fab-inp {
  width: 100%;
  background: #fff;
  border: 1.5px solid var(--bdr);
  border-radius: var(--r3);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 8px;
  transition: 0.13s;
}
.fab-inp:focus {
  border-color: var(--pri);
  outline: none;
}
.fab-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.fab-hint {
  font-size: 11px;
  color: var(--sub);
  line-height: 1.6;
  margin-top: 4px;
}

/* add btn */
.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px;
  border: 1.5px dashed var(--bdr2);
  border-radius: var(--r3);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--pri);
  cursor: pointer;
  transition: 0.13s;
  margin: 8px 12px 12px;
}
.add-btn:active {
  background: var(--pri-l);
}

/* overview card */
.ov-card {
  background: var(--navy);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 10px;
}
.ov-top {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.ov-left {
  color: rgba(255, 255, 255, 0.4);
  font-size: 11px;
}
.ov-qty {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}
.ov-designs {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: 2px;
}
.ov-right {
  text-align: right;
}
.ov-unit-lbl {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 2px;
}
.ov-unit {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--gold);
}
.ov-total {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: 2px;
}
.ov-sells {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.ov-sell-col {
  padding: 10px 12px;
  text-align: center;
}
.ov-sells button.ov-sell-col {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}
.ov-sell-col.active {
  background: rgba(18, 183, 106, 0.12);
}
.ov-sell-lbl {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: rgba(255, 255, 255, 0.3);
  margin-bottom: 3px;
}
.ov-sell-col.active .ov-sell-lbl {
  color: var(--green);
}
.ov-sell-val {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
}
.ov-sell-col.active .ov-sell-val {
  color: var(--green);
}
.ov-profit {
  padding: 9px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ov-profit-lbl {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
}
.ov-profit-val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--green);
}
.ov-profit-val--purple {
  color: #c4b5fd;
}

/* vol tier badge */
.vol-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--teal-l);
  border: 1px solid var(--teal);
  color: var(--teal);
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
}

/* ── SERVICE ROWS ── */
.svc-row {
  background: var(--surf2);
  border-radius: var(--r3);
  padding: 10px 12px;
  border: 1px solid var(--bdr);
  margin-bottom: 8px;
}
.svc-row-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.svc-num {
  width: 22px;
  height: 22px;
  border-radius: var(--r4);
  background: var(--bdr2);
  color: var(--sub);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.svc-num.on {
  background: var(--pri-l);
  color: var(--pri);
}
.svc-rm {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: var(--r4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--hint);
  cursor: pointer;
}
.svc-rm:active {
  background: var(--red-l);
  color: var(--red);
}
.svc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 7px;
}
.svc-price {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: #b54708;
  background: var(--gold-l);
  border: 1px solid #fec84b;
  border-radius: var(--r4);
  padding: 4px 9px;
  margin-left: auto;
}

/* ── TOGGLE BUTTONS ── */
.toggle-grp {
  display: flex;
  gap: 6px;
  padding: 3px;
  border: 1px solid #e4e7ec;
  border-radius: 12px;
  background: #f8fafc;
  width: 100%;
  max-width: 270px;
}
.toggle-btn {
  flex: 1;
  min-height: 44px;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 700;
  border: 1px solid transparent;
  background: transparent;
  color: var(--sub);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  line-height: 1.1;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease,
    box-shadow 0.18s ease, transform 0.12s ease;
}
.toggle-btn > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.toggle-btn:hover:not(.on-yes):not(.on-rush):not(.on-no) {
  background: transparent;
  border-color: transparent;
  color: var(--sub);
  box-shadow: none;
  transform: none;
}
.toggle-btn.on-yes {
  background: var(--violet);
  border-color: var(--violet);
  color: #fff;
  box-shadow: 0 2px 8px rgba(127, 86, 217, 0.26);
}
.toggle-btn.on-rush {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  box-shadow: 0 2px 8px rgba(247, 144, 9, 0.3);
}
.toggle-btn.on-no {
  background: var(--pri);
  border-color: var(--pri);
  color: #fff;
  box-shadow: 0 2px 8px rgba(21, 112, 239, 0.24);
}
.toggle-btn.on-yes:hover,
.toggle-btn.on-rush:hover,
.toggle-btn.on-no:hover {
  filter: brightness(1.03);
  transform: none;
}

/* ── SELL CARDS ── */
.sell-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 14px;
}
.sc {
  border-radius: var(--r2);
  padding: 13px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: 0.15s;
}
.sc:active {
  transform: scale(0.97);
}
.sc.picked {
  box-shadow: 0 0 0 3px currentColor;
}
.sc-a {
  background: #f4f3ff;
  border-color: #c4b5fd;
  color: #5b21b6;
}
.sc-b {
  background: var(--green-l);
  border-color: #86efac;
  color: #14532d;
}
.sc-c {
  background: var(--gold-l);
  border-color: #fde68a;
  color: #78350f;
}
.sc-d {
  background: var(--teal-l);
  border-color: #7dd3fc;
  color: #075985;
}
.sc-lbl {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  opacity: 0.5;
  margin-bottom: 5px;
}
.sc-p {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}
.sc-vat {
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0.45;
  margin-bottom: 6px;
  margin-top: 1px;
}
.sc-pf {
  font-family: var(--mono);
  font-size: 10.5px;
  padding-top: 5px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  color: #7c3aed;
  font-weight: 600;
  opacity: 1;
}
.sc-ord {
  font-size: 10px;
  opacity: 0.3;
  margin-top: 2px;
}
.cm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 12px;
}
.cm-inp {
  width: 54px;
  text-align: center;
  font-weight: 700;
  color: var(--pri);
  background: var(--pri-l);
  border: 1.5px solid #bad7fb;
  border-radius: var(--r3);
  padding: 7px;
  font-family: var(--mono);
  font-size: 14px;
  min-height: 38px;
}

/* per-design sell breakdown */
.dsg-sell-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bdr);
}
.dsg-sell-row:last-child {
  border: none;
}
.dsg-sell-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.dsg-sell-sub {
  font-size: 11px;
  color: var(--sub);
  margin-top: 1px;
}
.dsg-sell-val {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--pri);
  text-align: right;
}
.dsg-sell-vat {
  font-size: 10.5px;
  color: var(--sub);
  text-align: right;
  margin-top: 1px;
  font-family: var(--mono);
}

/* ── BREAKDOWN ── */
.bd-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px dashed var(--bdr);
}
.bd-row:last-of-type {
  border: none;
}
.bd-k {
  font-size: 13px;
  color: var(--sub);
}
.bd-v {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
}
.bd-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--navy);
  border-radius: var(--r3);
  padding: 11px 13px;
  margin-top: 10px;
}
.bd-total-k {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
}
.bd-total-v {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
}

/* ── EQ ROWS ── */
.eq-row {
  background: var(--surf2);
  border-radius: var(--r3);
  padding: 10px 12px;
  border: 1px solid var(--bdr);
  margin-bottom: 8px;
}
.eq-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

/* ── JT GRID ── */
.jt-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 8px 12px 12px;
}
.jt-cell {
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: var(--r3);
  padding: 7px 4px;
  text-align: center;
}
.jt-cell.on {
  background: var(--teal-l);
  border-color: var(--teal);
}
.jt-r {
  font-size: 9.5px;
  color: var(--hint);
  margin-bottom: 2px;
}
.jt-p {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
}
.jt-cell.on .jt-r,
.jt-cell.on .jt-p {
  color: var(--teal);
}

/* ── PROPOSAL ── */
.prop-wrap {
  padding: 16px 16px 20px;
}
.prop-hd {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--navy);
  margin-bottom: 14px;
}
.prop-logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
}
.prop-logo small {
  display: block;
  font-size: 9px;
  font-weight: 500;
  color: var(--hint);
  letter-spacing: 0.5px;
  margin-top: 2px;
}
.prop-meta {
  font-size: 11px;
  color: var(--sub);
  line-height: 1.9;
  text-align: right;
}
.prop-cust {
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: var(--r3);
  padding: 10px 13px;
  margin-bottom: 14px;
}
.prop-cust-id {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 2px;
}
.prop-cust-nm {
  font-size: 14px;
  font-weight: 700;
}
.prop-sh {
  font-size: 10px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.prop-sh::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--bdr);
}
.prop-tbl {
  width: 100%;
  font-size: 12.5px;
  border-collapse: collapse;
  margin-bottom: 14px;
}
.prop-tbl td {
  padding: 5px 0;
  border-bottom: 1px solid var(--bdr);
}
.prop-tbl td:first-child {
  color: var(--sub);
}
.prop-tbl td:last-child {
  text-align: right;
  font-family: var(--mono);
  font-weight: 700;
}
.prop-scards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 6px;
}
.prop-sc {
  border-radius: var(--r3);
  padding: 10px;
  border: 1.5px solid transparent;
}
.psc-a {
  background: #f4f3ff;
  border-color: #c4b5fd;
  color: #5b21b6;
}
.psc-b {
  background: var(--green-l);
  border-color: #86efac;
  color: #14532d;
}
.psc-c {
  background: var(--gold-l);
  border-color: #fde68a;
  color: #78350f;
}
.psc-d {
  background: var(--teal-l);
  border-color: #7dd3fc;
  color: #075985;
}
.psc-lbl {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.5;
  margin-bottom: 3px;
}
.psc-p {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 1px;
}
.psc-v {
  font-family: var(--mono);
  font-size: 9px;
  opacity: 0.4;
  margin-bottom: 4px;
}
.psc-g {
  font-family: var(--mono);
  font-size: 9.5px;
  padding-top: 3px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  color: #7c3aed;
  font-weight: 600;
  opacity: 1;
}
.prop-scards-legend {
  font-size: 10px;
  color: #667085;
  line-height: 1.45;
  margin: 0 0 8px;
  padding: 8px 10px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid var(--bdr);
}
/* mini-header ซ้ำบนหน้า 2 (แสดงเฉพาะตอนพิมพ์) */
.prop-page2-mini-hd {
  display: none;
}
@media print {
  /* บังคับขึ้นหน้าใหม่เมื่อ 2+ designs */
  .prop-page2-block {
    break-before: page;
    page-break-before: always;
    padding-top: 8px;
  }
  /* แสดง mini-header บนหน้า 2 */
  .prop-page2-mini-hd {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding-bottom: 8px;
    border-bottom: 2px solid #101828;
    margin-bottom: 14px;
  }
}

.prop-foot {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--bdr);
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--hint);
}

/* ── HIST ── */
#histTab {
  flex: 1;
  overflow: hidden;
  display: none;
  flex-direction: column;
  /* ให้ .hist-inner ได้ flex-grow + scroll จริง แทนถูกบีบเหลือแค่ครึ่งจอ */
  min-height: 0;
}
#histTab.on {
  display: flex;
}
/* r22: Promotion tab */
#promoTab {
  flex: 1;
  overflow: hidden;
  display: none;
  flex-direction: column;
  min-height: 0;
}
#promoTab.on {
  display: flex;
}
.hist-inner {
  /* basis 0 = พื้นที่ list คงที่ตาม viewport ไม่หดขยายตามจำนวนการ์ด */
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* กัน layout กระตุกเมื่อมี/ไม่มี scrollbar */
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  padding: 8px 14px 72px;
}
.hist-inner > .hist-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: min(360px, 55dvh);
  padding: 40px 20px;
  box-sizing: border-box;
}

/* แถวบน ใบเสนอ — ลดความสูงรวมบนมือถือ ให้ list ได้สัดส่วนมากขึ้น */
.hist-chrome {
  flex-shrink: 0;
  min-width: 0;
}
.hist-header-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
}
.hist-btn {
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.hist-btn-primary {
  border: none;
  background: linear-gradient(135deg, #f79009, #7f56d9);
  color: #fff;
  box-shadow: 0 2px 6px rgba(127, 86, 217, 0.25);
}
.hist-btn-outline {
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--bdr);
}
.hist-creator-select {
  flex: 1;
  min-width: 120px;
  max-width: 100%;
  border: 1px solid var(--bdr);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  background: #fff;
  color: var(--ink);
}
.hist-activity-btn {
  flex-shrink: 0;
  cursor: pointer;
  padding: 5px 11px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  border: 1.5px solid #d9d6fe;
  background: #f4f3ff;
  color: #5925dc;
  line-height: 1.25;
}
.hist-page-header {
  padding: 10px 14px 4px;
  flex-shrink: 0;
}
.hist-page-creator {
  padding: 0 14px 6px;
  flex-shrink: 0;
}
.hist-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 4px;
  flex-shrink: 0;
  min-width: 0;
  min-height: 48px;
  box-sizing: border-box;
}
.hist-filter-row .hist-filter {
  padding: 4px 0;
}
.hist-overview-details {
  flex-shrink: 0;
  padding: 0 14px 6px;
  min-width: 0;
}
@media (max-width: 1023px) {
  /* จำกัดความสูงส่วนหัว+filter+ภาพรวม — เลื่อนในบล็อกนี้ได้ ไม่กินทั้งจอ */
  .hist-chrome {
    max-height: min(40dvh, 380px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--bdr);
    /* ไม่ใช้พื้นขาวครอบทั้งบล็อก — ให้โชว์พื้นหลังหน้า (--bg) แบบมินิมอล */
    background: transparent;
  }
  .hist-overview-panel {
    max-height: min(38dvh, 280px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .hist-overview-summary-sub {
    display: none;
  }
  .hist-overview-details > summary {
    padding: 6px 10px;
    font-size: 11px;
  }
  .hist-overview-details {
    padding: 0 12px 4px;
  }
}
@media (max-width: 767px) {
  .hist-page-header {
    padding: 8px 12px 2px;
  }
  .hist-page-creator {
    padding: 0 12px 4px;
  }
  .hist-filter-row {
    padding: 2px 12px 4px;
    min-height: 44px;
  }
  .hist-inner {
    padding-top: 6px;
  }
  .hist-btn {
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* กล่องภาพรวม — พับได้ + กะทัดรัด (padding base อยู่ด้านบนก่อน @media 1023) */
.hist-page-title {
  font-size: clamp(15px, 4vw, 17px);
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
}
.hist-overview-details > summary > span:first-of-type {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  min-width: 0;
  text-align: left;
}
.hist-overview-summary-sub {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: var(--hint);
  line-height: 1.3;
}
.hist-overview-summary-meta {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  font-family: var(--mono);
  flex-shrink: 0;
}
.hist-overview-details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--sub);
  padding: 8px 10px;
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: 8px;
  user-select: none;
}
.hist-overview-details > summary::-webkit-details-marker {
  display: none;
}
.hist-overview-details > summary::after {
  content: '▼';
  font-size: 9px;
  opacity: 0.55;
  flex-shrink: 0;
}
.hist-overview-details[open] > summary::after {
  content: '▲';
}
.hist-overview-panel {
  margin-top: 6px;
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: 10px;
  padding: 8px 10px;
  box-sizing: border-box;
}
.hist-overview-hint {
  font-size: 10px;
  color: var(--hint);
  margin-top: 6px;
  text-align: center;
  line-height: 1.35;
}
.hist-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
@media (max-width: 400px) {
  .hist-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.hist-stat-cell {
  text-align: center;
  min-width: 0;
}
.hist-stat-val {
  font-size: clamp(12px, 3.2vw, 14px);
  font-weight: 700;
  font-family: var(--mono);
  line-height: 1.2;
}
.hist-stat-lbl {
  font-size: 9px;
  color: var(--sub);
  margin-top: 2px;
  line-height: 1.25;
}
@media (max-width: 767px) {
  #histTab .hf-pill {
    padding: 4px 10px;
    font-size: 11.5px;
  }
}
/* q-card redesign r20: row layout กะทัดรัด (card เดิมเป็น vertical, ใหม่เป็น row คล้าย table) */
/* r20c: เพิ่ม customer column ขวาสุด + pills สำหรับ nums */
/* r20d: fix grid ให้ pills align ตรงกันทุก card — QN(auto) | Project(fixed) | Pills(fixed) | Customer(1fr) */
.q-card {
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 4px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
  cursor: pointer;
  display: grid;
  /* r21: widen nums column for 5 pills — QN(auto) | Project(fixed) | Nums(flex) | Customer(1fr) */
  grid-template-columns: 115px 150px minmax(280px, 680px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  transition: background 0.1s;
  min-width: 0;
}
.q-card:hover {
  background: #fafbfc;
}
.q-card:active {
  transform: scale(0.995);
}
.q-top {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 0;
  align-items: flex-start;
  min-width: 0;
}
.q-id {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-l);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.q-ts {
  font-size: 9.5px;
  color: var(--hint);
}
.q-proj {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 0;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* r20c: q-cust เดิม (แสดงชื่อลูกค้า + user) ซ่อน เพราะย้ายไปขวาสุดเป็น q-cust-right */
.q-card > .q-cust:not(.q-cust-right) {
  display: none;
}
.q-cust {
  font-size: 11px;
  color: var(--sub);
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.25;
  text-align: right;
  max-width: 220px;
}
/* r20c: nums เป็น pill style (r20d: filled ธรรมดา + fixed width ให้ตรงกันทุก card) */
.q-nums {
  display: flex;
  gap: 6px;
  flex-shrink: 1;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}
.q-num {
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: 999px;
  padding: 5px 10px;
  text-align: center;
  min-width: 72px;
  max-width: 120px;
  flex: 1 1 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  box-sizing: border-box;
}
/* sell pill gets green accent */
.q-num-v--sell {
  color: var(--green);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.15;
}
.q-num-l {
  font-size: 8.5px;
  color: var(--sub);
  margin-bottom: 0;
  font-weight: 600;
  letter-spacing: 0.2px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.q-num-v {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
}
/* r20d: accent สีเขียวเฉพาะ value ของ "ขาย" เพื่อแยก ต้นทุน vs ขาย ได้ชัด */
.q-num-v.g {
  color: var(--green);
}
/* r20: action buttons + cancelled tag span ทั้งแถว (ไม่แย่ง column ของ grid) */
.q-card > .q-actions {
  grid-column: 1 / -1;
  margin-top: 4px !important;
  padding-top: 6px !important;
}
.q-card > [data-cancel-tag] {
  grid-column: 1 / -1;
}
.q-card > [data-status-tag] {
  grid-column: 1 / -1;
  justify-self: start;
  width: max-content;
  max-width: min(100%, 320px);
  box-sizing: border-box;
}
.q-card > .q-card-tools {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.q-actions-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 11px;
  font-size: 11px;
  font-weight: 600;
  color: #475467;
  background: transparent;
  border: 1px solid #e4e7ec;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  font-family: inherit;
  line-height: 1.25;
}
.q-actions-toggle:hover {
  background: #f9fafb;
  border-color: #d0d5dd;
  color: #344054;
}
.q-actions-toggle-chevron {
  font-size: 8px;
  opacity: 0.72;
  line-height: 1;
  transform: translateY(0.5px);
}
.q-promo-inline-chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid #d9c8ff;
  background: #f4efff;
  color: #5925dc;
  line-height: 1.25;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-promo-inline-chip--ok {
  border-color: #6ce9a6;
  background: #ecfdf3;
  color: #067647;
}
.q-promo-inline-chip--click {
  cursor: pointer;
}
.q-promo-inline-chip--click:focus {
  outline: 2px solid #5925dc;
  outline-offset: 2px;
}
.q-card > .q-promo-compact {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 11.5px;
  line-height: 1.35;
  box-sizing: border-box;
}
.q-promo-compact--pending {
  border: 2px solid #9b8afb;
  background: #faf5ff;
  box-shadow: 0 1px 3px rgba(89, 37, 220, 0.12);
}
.q-promo-compact--approved {
  border: 1px solid #6ce9a6;
  background: #ecfdf3;
}
.q-promo-compact--rejected {
  border: 1px solid #ffc8c8;
  background: #fff1f1;
}
.q-promo-compact-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.q-promo-compact-actions .qa-btn {
  padding: 10px 14px !important;
  font-size: 12px !important;
  border-radius: 8px !important;
  font-weight: 700 !important;
  cursor: pointer;
  flex: 1 1 0;
  min-width: 90px;
  white-space: nowrap;
  text-align: center;
  box-sizing: border-box;
}
.q-promo-compact-actions .qa-send {
  background: linear-gradient(135deg, #f79009, #7f56d9) !important;
  color: #fff !important;
  border: 1px solid #53389e !important;
  box-shadow: 0 1px 3px rgba(89, 37, 220, 0.22);
}
.q-promo-compact-actions .qa-undo {
  background: #fff !important;
  color: #344054 !important;
  border: 1px solid #d0d5dd !important;
}

/* Promo tab (History / โปร): ปุ่มจัดการโปร / ยกเลิกคำขอ ให้มีกรอบชัด */
.hist-card.promo-card .promo-pending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.hist-card.promo-card .promo-pending-actions > button {
  border-radius: 8px;
  font-weight: 700;
  font-size: 12px;
  padding: 8px 12px;
  cursor: pointer;
  box-sizing: border-box;
}
.hist-card.promo-card .promo-pending-actions .promo-btn-open {
  border: 1px solid #d0d5dd;
  background: #fff;
  color: var(--ink);
}
.hist-card.promo-card .promo-pending-actions .promo-btn-manage {
  border: 1px solid #53389e;
  background: linear-gradient(135deg, #f79009, #7f56d9);
  color: #fff;
  box-shadow: 0 1px 3px rgba(89, 37, 220, 0.22);
}
.hist-card.promo-card .promo-pending-actions .promo-btn-reject {
  border: 1px solid #fda29b;
  background: #fff;
  color: #b42318;
}
.hist-card.promo-card .promo-pending-actions .promo-btn-cancel-req {
  border: 1px solid #d0d5dd;
  background: #fff;
  color: #344054;
}
.q-card > [data-promo-tag] {
  grid-column: 1 / -1;
}
/* r20b: ปุ่ม action ใน card — ขนาดใกล้ grid เดิม แต่ยังยืดเต็มแถวได้ */
.q-card .q-actions button {
  padding: 10px 14px !important;
  font-size: 12px !important;
}
/* Mobile: ≤480px ให้กลับมาเป็น stack เพื่ออ่านง่าย */
@media (max-width: 480px) {
  .q-card {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 8px 10px;
  }
  .q-nums {
    justify-content: flex-start;
    gap: 4px;
    flex-wrap: wrap;
    border-top: 1px dashed var(--bdr);
    padding-top: 4px;
    margin-top: 1px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .q-num {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    max-width: none;
    padding: 5px 8px;
  }
  .q-num-l {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    line-height: 1.15;
    hyphens: auto;
  }
  .q-cust-right {
    text-align: left;
    max-width: 100%;
  }
  /* r25: Dashboard ยังคงเป็น horizontal scroll (ไม่ stack) */
}
/* Tablet / iPad portrait: 481–1023px — QN+project บรรทัดบน, metrics เต็มความกว้าง (กันปุ่มถูกตัดขอบ) */
@media (min-width: 481px) and (max-width: 1023px) {
  .q-card {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
    gap: 8px 10px;
    align-items: start;
  }
  .q-card > .q-top {
    grid-column: 1;
    grid-row: 1;
  }
  .q-card > .q-proj {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }
  .q-card > .q-nums {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border-top: 1px dashed var(--bdr);
    padding-top: 6px;
    margin-top: 2px;
  }
  .q-card:not(.compact) > .q-nums .q-num {
    flex: 1 1 100px;
    min-width: 0;
    width: auto;
    max-width: 160px;
  }
  .q-cust-right {
    grid-column: 1 / -1;
    text-align: left;
    max-width: 100%;
    padding-top: 2px;
    border-top: 1px dashed var(--bdr);
    margin-top: 2px;
  }
}
/* r47: Compact view (mobile + pc-mode phone frame) */
/* === COMPACT MODE === */
/* Apply when viewport ≤480px (real mobile) OR body.pc-mode (simulated phone) */
@media (max-width: 480px) {
  .q-card.compact:not(.expanded) {
    grid-template-columns: auto 1fr auto !important;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
  }
  .q-card.compact:not(.expanded) .q-nums {
    display: flex !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    justify-content: flex-end;
  }
  .q-card.compact:not(.expanded) .q-num {
    display: none;
  }
  .q-card.compact:not(.expanded) .q-num.q-num-primary {
    display: flex !important;
    width: auto;
    min-width: 80px;
    background: transparent;
    border: 0;
    padding: 2px 4px;
  }
  .q-card.compact:not(.expanded) .q-num.q-num-primary .q-num-l {
    font-size: 8px;
    color: var(--hint);
  }
  .q-card.compact:not(.expanded) .q-num.q-num-primary .q-num-v {
    font-size: 13px;
    font-weight: 800;
    color: var(--ink);
  }
  .q-card.compact:not(.expanded) .q-cust-right {
    display: none !important;
  }
  .q-card.compact:not(.expanded) > .q-actions {
    display: none !important;
  }
  .q-card.compact:not(.expanded) > [data-cancel-tag] {
    display: none !important;
  }
  .q-card.compact:not(.expanded) > [data-status-tag] {
    display: none !important;
  }
  .q-card.compact:not(.expanded) > [data-promo-tag] {
    display: none !important;
  }
  .q-card.compact:not(.expanded) > [data-r49-promo] {
    display: none !important;
  }
  .q-card.compact:not(.expanded) .q-top {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .q-card.compact:not(.expanded) .q-id {
    font-size: 9px;
    padding: 1px 5px;
  }
  .q-card.compact:not(.expanded) .q-ts {
    display: none;
  }
  .q-card.compact:not(.expanded) .q-proj {
    font-size: 12.5px;
    flex: 1;
    min-width: 0;
  }
  .q-card.compact .expand-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--sub);
    font-size: 13px;
    flex-shrink: 0;
    transition: transform 0.15s;
  }
  .q-card.compact.expanded .expand-hint {
    transform: rotate(180deg);
  }
  .q-card.compact.expanded {
    grid-template-columns: 1fr !important;
    gap: 6px;
  }
  .q-card.compact.expanded .q-nums {
    justify-content: flex-start;
    gap: 5px;
    flex-wrap: wrap;
    border-top: 1px dashed var(--bdr);
    padding-top: 5px;
    margin-top: 2px;
  }
  .q-card.compact.expanded .q-num {
    display: flex;
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    width: auto;
  }
  .q-card.compact.expanded .q-cust-right {
    display: block !important;
    text-align: left;
    max-width: 100%;
    padding-top: 4px;
    border-top: 1px dashed var(--bdr);
    font-size: 11px;
  }
  .q-card.compact.expanded > .q-actions {
    display: flex !important;
  }
  .q-card.compact.expanded > [data-cancel-tag] {
    display: block !important;
  }
  .q-card.compact.expanded > [data-status-tag] {
    display: inline-block !important;
  }
  .q-card.compact.expanded > [data-promo-tag] {
    display: block !important;
  }
  .q-card.compact.expanded > [data-r49-promo] {
    display: block !important;
  }
}
/* r55: Desktop PC view (>480px, NOT pc-mode phone frame) — same compact behavior */
@media (min-width: 481px) {
  body:not(.pc-mode) .q-card.compact:not(.expanded) {
    grid-template-columns: auto 1fr auto !important;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-nums {
    display: flex !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    justify-content: flex-end;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-num {
    display: none;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-num.q-num-primary {
    display: flex !important;
    width: auto;
    min-width: 90px;
    background: transparent;
    border: 0;
    padding: 2px 4px;
  }
  body:not(.pc-mode)
    .q-card.compact:not(.expanded)
    .q-num.q-num-primary
    .q-num-l {
    font-size: 9px;
    color: var(--hint);
  }
  body:not(.pc-mode)
    .q-card.compact:not(.expanded)
    .q-num.q-num-primary
    .q-num-v {
    font-size: 14px;
    font-weight: 800;
    color: var(--ink);
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-cust-right {
    display: none !important;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) > .q-actions {
    display: none !important;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) > [data-cancel-tag] {
    display: none !important;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) > [data-status-tag] {
    display: none !important;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) > [data-promo-tag] {
    display: none !important;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) > [data-r49-promo] {
    display: none !important;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-top {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-id {
    font-size: 10px;
    padding: 2px 6px;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-ts {
    display: none;
  }
  body:not(.pc-mode) .q-card.compact:not(.expanded) .q-proj {
    font-size: 13.5px;
    flex: 1;
    min-width: 0;
  }
  body:not(.pc-mode) .q-card.compact .expand-hint {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: var(--sub);
    font-size: 14px;
    flex-shrink: 0;
    transition: transform 0.15s;
  }
  body:not(.pc-mode) .q-card.compact.expanded .expand-hint {
    transform: rotate(180deg);
  }
  body:not(.pc-mode) .q-card.compact.expanded {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  body:not(.pc-mode) .q-card.compact.expanded .q-nums {
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: wrap;
    border-top: 1px dashed var(--bdr);
    padding-top: 6px;
    margin-top: 2px;
  }
  body:not(.pc-mode) .q-card.compact.expanded .q-num {
    display: flex;
    flex: 0 1 auto;
    min-width: 130px;
    width: auto;
  }
  body:not(.pc-mode) .q-card.compact.expanded .q-cust-right {
    display: block !important;
    text-align: left;
    max-width: 100%;
    padding-top: 4px;
    border-top: 1px dashed var(--bdr);
    font-size: 11.5px;
  }
  body:not(.pc-mode) .q-card.compact.expanded > .q-actions {
    display: flex !important;
  }
  body:not(.pc-mode) .q-card.compact.expanded > [data-cancel-tag] {
    display: block !important;
  }
  body:not(.pc-mode) .q-card.compact.expanded > [data-status-tag] {
    display: inline-block !important;
  }
  body:not(.pc-mode) .q-card.compact.expanded > [data-promo-tag] {
    display: block !important;
  }
  body:not(.pc-mode) .q-card.compact.expanded > [data-r49-promo] {
    display: block !important;
  }
}

/* === PC mode (phone frame on desktop): same compact behavior === */
body.pc-mode .q-card.compact:not(.expanded) {
  grid-template-columns: auto 1fr auto !important;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
}
body.pc-mode .q-card.compact:not(.expanded) .q-nums {
  display: flex !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  gap: 0 !important;
  justify-content: flex-end;
}
body.pc-mode .q-card.compact:not(.expanded) .q-num {
  display: none;
}
body.pc-mode .q-card.compact:not(.expanded) .q-num.q-num-primary {
  display: flex !important;
  width: auto;
  min-width: 80px;
  background: transparent;
  border: 0;
  padding: 2px 4px;
}
body.pc-mode .q-card.compact:not(.expanded) .q-num.q-num-primary .q-num-l {
  font-size: 8px;
  color: var(--hint);
}
body.pc-mode .q-card.compact:not(.expanded) .q-num.q-num-primary .q-num-v {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}
body.pc-mode .q-card.compact:not(.expanded) .q-cust-right {
  display: none !important;
}
body.pc-mode .q-card.compact:not(.expanded) > .q-actions {
  display: none !important;
}
body.pc-mode .q-card.compact:not(.expanded) > [data-cancel-tag] {
  display: none !important;
}
body.pc-mode .q-card.compact:not(.expanded) > [data-status-tag] {
  display: none !important;
}
body.pc-mode .q-card.compact:not(.expanded) > [data-promo-tag] {
  display: none !important;
}
body.pc-mode .q-card.compact:not(.expanded) > [data-r49-promo] {
  display: none !important;
}
body.pc-mode .q-card.compact:not(.expanded) .q-top {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
body.pc-mode .q-card.compact:not(.expanded) .q-id {
  font-size: 9px;
  padding: 1px 5px;
}
body.pc-mode .q-card.compact:not(.expanded) .q-ts {
  display: none;
}
body.pc-mode .q-card.compact:not(.expanded) .q-proj {
  font-size: 12.5px;
  flex: 1;
  min-width: 0;
}
body.pc-mode .q-card.compact .expand-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--sub);
  font-size: 13px;
  flex-shrink: 0;
  transition: transform 0.15s;
}
body.pc-mode .q-card.compact.expanded .expand-hint {
  transform: rotate(180deg);
}
body.pc-mode .q-card.compact.expanded {
  grid-template-columns: 1fr !important;
  gap: 6px;
}
body.pc-mode .q-card.compact.expanded .q-nums {
  justify-content: flex-start;
  gap: 5px;
  flex-wrap: wrap;
  border-top: 1px dashed var(--bdr);
  padding-top: 5px;
  margin-top: 2px;
}
body.pc-mode .q-card.compact.expanded .q-num {
  display: flex;
  flex: 1 1 calc(50% - 3px);
  min-width: 0;
  width: auto;
}
body.pc-mode .q-card.compact.expanded .q-cust-right {
  display: block !important;
  text-align: left;
  max-width: 100%;
  padding-top: 4px;
  border-top: 1px dashed var(--bdr);
  font-size: 11px;
}
body.pc-mode .q-card.compact.expanded > .q-actions {
  display: flex !important;
}
body.pc-mode .q-card.compact.expanded > [data-cancel-tag] {
  display: block !important;
}
body.pc-mode .q-card.compact.expanded > [data-status-tag] {
  display: inline-block !important;
}
body.pc-mode .q-card.compact.expanded > [data-promo-tag] {
  display: block !important;
}
body.pc-mode .q-card.compact.expanded > [data-r49-promo] {
  display: block !important;
}
/* r48: promo-card compact mode */
@media (max-width: 480px) {
  .q-card.promo-card.compact:not(.expanded) .promo-detail {
    display: none !important;
  }
  .q-card.promo-card.compact .promo-expand-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    color: var(--sub);
    font-size: 13px;
    flex-shrink: 0;
    transition: transform 0.15s;
    margin-left: auto;
  }
  .q-card.promo-card.compact.expanded .promo-expand-hint {
    transform: rotate(180deg);
  }
  .q-card.promo-card.compact:not(.expanded) > div:first-child {
    cursor: pointer;
  }
}
body.pc-mode .q-card.promo-card.compact:not(.expanded) .promo-detail {
  display: none !important;
}
body.pc-mode .q-card.promo-card.compact .promo-expand-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--sub);
  font-size: 13px;
  flex-shrink: 0;
  transition: transform 0.15s;
  margin-left: auto;
}
body.pc-mode .q-card.promo-card.compact.expanded .promo-expand-hint {
  transform: rotate(180deg);
}
body.pc-mode .q-card.promo-card.compact:not(.expanded) > div:first-child {
  cursor: pointer;
}
.q-card.promo-card .promo-expand-hint {
  display: none;
}
/* hide expand-hint on big desktop (>900px and not pc-mode) */
.q-card .expand-hint {
  display: none;
}
.hist-empty {
  text-align: center;
}
.hist-empty-ico {
  font-size: 48px;
  margin-bottom: 12px;
}
.hist-empty-t {
  font-size: 16px;
  font-weight: 700;
  color: var(--sub);
}
.hist-filter {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 5px;
  padding: 6px 0;
  overflow-x: auto;
  flex-shrink: 0;
  flex: 1;
  min-width: 0;
}
.hist-filter::-webkit-scrollbar {
  display: none;
}
.hf-pill {
  flex-shrink: 0;
  box-sizing: border-box;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  background: var(--surf2);
  border: 1px solid var(--bdr);
  color: var(--sub);
  transition:
    background 0.13s,
    border-color 0.13s,
    color 0.13s,
    box-shadow 0.13s,
    transform 0.13s,
    filter 0.13s;
}
/* ปุ่ม filter ที่ยังไม่เลือก — hover ชัดเจน */
.hf-pill:hover:not(.on) {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.1);
  filter: brightness(0.98);
}
.hf-pill:active:not(.on) {
  transform: translateY(0);
}
/* ปุ่มที่เลือกอยู่ — เข้มตามโทนสีของแต่ละ status (ไม่ใช้ navy เดียวกันทุกตัว) */
.hf-pill.hf-all.on {
  background: #020617;
  border-color: #0f172a;
  color: #f8fafc;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.35);
}
.hf-pill.hf-pending.on {
  background: #b45309;
  border-color: #92400e;
  color: #fffbeb;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(180, 83, 9, 0.3);
}
.hf-pill.hf-confirmed.on {
  background: #0f766e;
  border-color: #0d5c56;
  color: #ecfdf5;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.32);
}
.hf-pill.hf-sent.on {
  background: #1d4ed8;
  border-color: #1e40af;
  color: #eff6ff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.3);
}
.hf-pill.hf-pro.on {
  background: #6d28d9;
  border-color: #5b21b6;
  color: #faf5ff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(109, 40, 217, 0.32);
}
.hf-pill.hf-won.on {
  background: #a16207;
  border-color: #854d0e;
  color: #fffbeb;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(161, 98, 7, 0.3);
}
.hf-pill.hf-lost.on {
  background: #b42318;
  border-color: #912018;
  color: #fef2f2;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(180, 35, 24, 0.3);
}
.hf-pill.hf-cancelled.on {
  background: #374151;
  border-color: #1f2937;
  color: #f9fafb;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(55, 65, 81, 0.35);
}
.hf-pill.hf-all.on:hover,
.hf-pill.hf-pending.on:hover,
.hf-pill.hf-confirmed.on:hover,
.hf-pill.hf-sent.on:hover,
.hf-pill.hf-pro.on:hover,
.hf-pill.hf-won.on:hover,
.hf-pill.hf-lost.on:hover,
.hf-pill.hf-cancelled.on:hover {
  filter: brightness(1.06);
}
/* r66: status chip colors (match legacy screenshot) */
.hf-pill.hf-all {
  background: #111827;
  border-color: #111827;
  color: #fff;
}
.hf-pill.hf-pending {
  background: #fff8eb;
  border-color: #f6d98b;
  color: #9a6b00;
}
.hf-pill.hf-confirmed {
  background: #eefbf3;
  border-color: #b4e7c8;
  color: #0f766e;
}
.hf-pill.hf-sent {
  background: #edf5ff;
  border-color: #c7dcff;
  color: #1d4ed8;
}
.hf-pill.hf-pro {
  background: #f4efff;
  border-color: #d9c8ff;
  color: #6d28d9;
}
.hf-pill.hf-won {
  background: #fff6dd;
  border-color: #f4d27c;
  color: #9a6700;
}
.hf-pill.hf-lost {
  background: #fff1f1;
  border-color: #ffc8c8;
  color: #b42318;
}
.hf-pill.hf-cancelled {
  background: #5f5f5f;
  border-color: #5f5f5f;
  color: #fff;
}

/* r66: แถวเดียว — ปุ่มยืดแบ่งพื้นที่คล้าย grid เดิม (1fr), แคบเกินไปค่อยเลื่อนแนวนอน */
.q-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.q-actions .qa-btn {
  flex: 1 1 0;
  min-width: 108px;
  white-space: normal;
  line-height: 1.25;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-align: center;
  border-radius: 8px;
  border: 1px solid var(--bdr);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 10px 14px !important;
}
.q-actions .qa-confirm {
  background: #ebfbee;
  border-color: #b7e5c1;
  color: #067647;
}
.q-actions .qa-reject,
.q-actions .qa-cancel {
  background: #fef3f2;
  border-color: #fecdca;
  color: #b42318;
}
.q-actions .qa-edit {
  background: #eef4ff;
  border-color: #c6d8ff;
  color: #1849a9;
}
.q-actions .qa-send {
  background: linear-gradient(135deg, #1570ef, #5925dc);
  border-color: transparent;
  color: #fff;
}
.q-actions .qa-pro {
  background: #f4efff;
  border-color: #d9c8ff;
  color: #5925dc;
}
.q-actions .qa-undo {
  background: #f5f3ff;
  border-color: #d9d6fe;
  color: #5925dc;
}
.q-actions .qa-win {
  background: linear-gradient(135deg, #f79009, #12b76a);
  border-color: #079455;
  color: #fff;
  box-shadow: 0 1px 3px rgba(18, 183, 106, 0.22);
}
.q-actions .qa-lost {
  background: #fef3f2;
  border-color: #fda29b;
  color: #b42318;
}
.q-actions .qa-back {
  background: #eef4ff;
  border-color: #84caff;
  color: #1849a9;
}
.q-actions .qa-pdf {
  background: #fff8ec;
  border-color: #fedf89;
  color: #b54708;
}
.q-actions .qa-xls {
  background: #effcf6;
  border-color: #a6f4c5;
  color: #027a48;
}
.q-actions .qa-undo-lost {
  background: #fff;
  border: 1px solid #f04438 !important;
  color: #b42318;
  flex: 1 1 0;
  min-width: 68px;
  padding: 5px 7px !important;
  font-size: 10.5px !important;
}
.q-actions .qa-undo-lost:hover {
  background: #fef3f2;
}
.q-actions .qa-undo-won {
  background: #fff;
  border: 1px solid #12b76a !important;
  color: #067647;
}
.q-actions .qa-undo-won:hover {
  background: #ecfdf3;
}
/* Undo Cancel — โทนเดียวกับป้ายสถานะ Cancelled */
.q-actions .qa-undo-cancel {
  background: #fff;
  border: 1px solid #5f5f5f !important;
  color: #111827;
  flex: 1 1 0;
  min-width: 68px;
  padding: 5px 7px !important;
  font-size: 10.5px !important;
}
.q-actions .qa-undo-cancel:hover {
  background: #f3f4f6;
}
.q-actions .q-lost-actions {
  flex: 1 1 150px;
  min-width: min(100%, 148px);
  max-width: min(280px, 100%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
}
.q-actions .q-lost-reason-box {
  padding: 5px 6px 6px 8px;
  border-radius: 7px;
  background: linear-gradient(165deg, #fffcfc 0%, #fff5f5 48%, #fff0f0 100%);
  border: 1px solid #fecdca;
  border-left: 2px solid #e04f42;
  box-shadow: 0 1px 2px rgba(180, 35, 24, 0.04);
  line-height: 1.4;
}
.q-actions .q-lost-reason-box--empty .q-lost-reason-text {
  color: #98a2b3;
  font-style: italic;
  font-weight: 500;
  line-height: 1.4;
  max-height: none;
  overflow-y: visible;
}
.q-actions .q-lost-reason-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #912018;
  margin: 0 0 3px;
  line-height: 1.25;
}
.q-actions .q-lost-reason-text {
  font-size: 10.5px;
  font-weight: 500;
  color: #101828;
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  max-height: 6em;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 1px;
}
.q-actions .qa-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Lost reason modal (History card — ลูกค้าไม่เอา) */
.lost-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9400;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(24px, 5vh) 12px 32px;
  overflow-y: auto;
  box-sizing: border-box;
}
.lost-modal {
  width: min(94vw, 520px);
  background: #fff;
  border-radius: 16px;
  padding: 20px 20px 18px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
  margin-top: 2vh;
}
.lost-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.lost-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
  color: #101828;
}
.lost-modal-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: #667085;
  line-height: 1.4;
  word-break: break-word;
}
.lost-modal-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: #f2f4f7;
  color: #667085;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  font-family: inherit;
}
.lost-modal-close:hover {
  background: #e4e7ec;
  color: #344054;
}
.lost-modal-section-label {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: #344054;
}
.lost-modal-cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.lost-modal-cat-btn {
  padding: 14px 10px;
  border-radius: 12px;
  border: 2px solid #e4e7ec;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.35;
  text-align: center;
  box-sizing: border-box;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.lost-modal-cat-btn:hover {
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.08);
}
.lost-modal-reason-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.lost-modal-reason-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #d0d5dd;
  background: #fff;
  color: #101828;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
  box-sizing: border-box;
  transition: background 0.12s, border-color 0.12s;
}
.lost-modal-reason-btn:hover {
  background: #f9fafb;
}
.lost-modal-reason-btn--on {
  border: 2px solid #344054;
  background: #f2f4f7;
}
.lost-modal-hint {
  font-size: 13px;
  color: #667085;
  padding: 12px 14px;
  background: #f9fafb;
  border-radius: 10px;
  margin-bottom: 16px;
  line-height: 1.45;
}
.lost-modal-textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 88px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #d0d5dd;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.45;
  resize: vertical;
  margin-bottom: 4px;
}
.lost-modal-textarea::placeholder {
  color: #98a2b3;
}
.lost-modal-footer {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.lost-modal-btn-cancel {
  flex: 1;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid #d0d5dd;
  background: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: #344054;
  font-family: inherit;
}
.lost-modal-btn-cancel:hover {
  background: #f9fafb;
}
.lost-modal-btn-confirm {
  flex: 1.35;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  background: #f97066;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(249, 112, 102, 0.35);
}
.lost-modal-btn-confirm:hover:not(:disabled) {
  background: #e04f42;
}
.lost-modal-btn-confirm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── BOTTOM NAV ── */
#NAV {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab);
  background: var(--surf);
  border-top: 1px solid var(--bdr);
  display: none;
  z-index: 200;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#NAV.on {
  display: flex;
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  padding: 4px 2px;
  position: relative;
  min-width: 0;
}
.nav-ico {
  font-size: 20px;
  line-height: 1;
}
/* r22: label ย่อให้ 4 ช่องพอดี + truncate ป้องกันล้น */
.nav-lbl {
  font-size: 9.5px;
  color: var(--hint);
  font-weight: 500;
  transition: 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
  padding: 0 2px;
}
.nav-tab.on .nav-lbl {
  color: var(--pri);
  font-weight: 700;
}
.nav-tab.on::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--pri);
  border-radius: 3px 3px 0 0;
}
/* r22: badge bubble สำหรับ notification count */
.nav-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 22px);
  background: #f04438;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(240, 68, 56, 0.4);
}
/* r49: ซ่อน nt4 (โปรโมชั่น) จาก nav bar — promo รวมเข้า history แล้ว */
#nt4 {
  display: none !important;
}

/* ── STRIP ── */
#STRIP {
  position: fixed;
  bottom: calc(var(--tab) + env(safe-area-inset-bottom, 0));
  left: 0;
  right: 0;
  height: 44px;
  background: var(--surf);
  border-top: 1px solid var(--bdr);
  display: flex;
  align-items: center;
  z-index: 199;
  padding: 0 16px;
}
.sv {
  flex: 1;
  text-align: center;
}
.sv-l {
  font-size: 9px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 1px;
}
.sv-v {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.sv-v.blu {
  color: var(--pri);
}
.sv-v.grn {
  color: var(--green);
}
.sv-sep {
  width: 1px;
  height: 18px;
  background: var(--bdr);
}

/* ── CS OVERLAY ── */
#csOv {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.4);
}
#csOv.on {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.cs-sheet {
  background: var(--surf);
  border-radius: 22px 22px 0 0;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.cs-grip {
  width: 36px;
  height: 4px;
  background: var(--bdr2);
  border-radius: 99px;
  margin: 12px auto 0;
}
.cs-hd {
  padding: 12px 16px 8px;
  display: flex;
  gap: 10px;
}
.cs-inp-wrap {
  flex: 1;
  position: relative;
}
.cs-inp {
  width: 100%;
  background: var(--surf2);
  border: 1.5px solid var(--bdr);
  border-radius: var(--r3);
  padding: 10px 34px 10px 14px;
  font-size: 15px;
  color: var(--ink);
}
.cs-inp:focus {
  border-color: var(--pri);
  outline: none;
}
.cs-clr {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--hint);
  cursor: pointer;
  display: none;
  font-size: 13px;
}
.cs-cancel {
  font-size: 14px;
  font-weight: 600;
  color: var(--pri);
  flex-shrink: 0;
  cursor: pointer;
  padding: 4px 0;
}
.cs-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}
.cs-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--bdr);
}
.cs-item:active {
  background: var(--surf2);
}
.cs-id {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--gold);
  font-weight: 700;
  min-width: 90px;
  flex-shrink: 0;
}
.cs-info {
  flex: 1;
  min-width: 0;
}
.cs-nm {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cs-biz {
  font-size: 11.5px;
  color: var(--sub);
  margin-top: 1px;
}
.cs-tier {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r4);
  flex-shrink: 0;
}
.t-vvip {
  background: #ffe3e3;
  color: #c92a2a;
}
.t-vip {
  background: #ffe8cc;
  color: #d9480f;
}
.t-reg {
  background: var(--surf2);
  color: var(--sub);
}
.t-new {
  background: var(--pri-l);
  color: var(--pri);
}

/* ── BOTTOM SHEET ── */
.bs-ov {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0, 0, 0, 0.4);
  align-items: flex-end;
}
.bs-ov.on {
  display: flex;
}
.bs {
  background: var(--surf);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bs-grip {
  width: 36px;
  height: 4px;
  background: var(--bdr2);
  border-radius: 99px;
  margin: 12px auto 0;
}
.bs-title {
  font-size: 17px;
  font-weight: 700;
  padding: 13px 16px 0;
}
.bs-sub {
  font-size: 13px;
  color: var(--sub);
  padding: 3px 16px 12px;
  border-bottom: 1px solid var(--bdr);
}
.bs-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.bs-field label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--sub);
  margin-bottom: 5px;
}
.bs-inp {
  width: 100%;
  background: var(--surf2);
  border: 1.5px solid var(--bdr);
  border-radius: var(--r3);
  padding: 11px 13px;
  font-size: 14.5px;
  color: var(--ink);
  transition: 0.13s;
}
.bs-inp:focus {
  border-color: var(--pri);
  background: #fff;
  outline: none;
}
.bs-sel {
  width: 100%;
  background: var(--surf2);
  border: 1.5px solid var(--bdr);
  border-radius: var(--r3);
  padding: 11px 13px;
  font-size: 14.5px;
  cursor: pointer;
}
.bs-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.bs-err {
  font-size: 12px;
  color: var(--red);
  min-height: 16px;
}
.bs-footer {
  display: flex;
  gap: 10px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--bdr);
}
.bs-cancel {
  flex: 1;
  padding: 12px;
  border-radius: var(--r3);
  background: var(--surf2);
  border: 1px solid var(--bdr);
  font-size: 14px;
  font-weight: 600;
  color: var(--sub);
  cursor: pointer;
}
.bs-ok {
  flex: 2;
  padding: 12px;
  border-radius: var(--r3);
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.13s;
}

/* ── MORE ── */
#moreOv {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.4);
}
#moreOv.show {
  display: flex;
  align-items: flex-end;
}
.more-sheet {
  background: var(--surf);
  border-radius: 22px 22px 0 0;
  width: 100%;
  padding: 0 0 calc(var(--tab) + env(safe-area-inset-bottom, 0));
}
.more-grip {
  width: 36px;
  height: 4px;
  background: var(--bdr2);
  border-radius: 99px;
  margin: 12px auto 4px;
}
.more-title {
  padding: 8px 16px 10px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.more-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 14px;
}
.more-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 18px 8px;
  background: var(--surf2);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
  cursor: pointer;
  transition: 0.13s;
}
.more-btn:active {
  background: var(--bdr);
}
.more-btn-ico {
  font-size: 26px;
}
.more-btn-lbl {
  font-size: 13px;
  font-weight: 600;
  color: var(--sub);
}

/* ── TOAST ── */
#TOAST {
  position: fixed;
  bottom: calc(var(--tab) + 50px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  display: none;
  white-space: nowrap;
  z-index: 9999;
  pointer-events: none;
}
.toast-inner {
  background: var(--ink);
  color: #fff;
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--sh2);
}

/* ── PRINT ── */

/* ── PC/Mobile view toggle (r43) ── */
.vm-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 99999;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.vm-toggle:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: scale(1.05);
}
.vm-toggle-ic {
  font-size: 14px;
}
body.pc-mode {
  background: #f2f4f7;
  overflow: auto;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 0;
}
body.pc-mode #APP.show,
body.pc-mode #LOGIN,
body.pc-mode #SETUP,
body.pc-mode #MODE_SEL,
body.pc-mode #MD_APP {
  position: relative !important;
  inset: auto !important;
  left: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  transform: none !important;
  width: 420px !important;
  max-width: 420px !important;
  height: 900px !important;
  max-height: calc(100vh - 48px) !important;
  margin: 0 !important;
  border-radius: 40px !important;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.15),
    0 0 0 8px #1a1d22,
    0 0 0 10px #3a3d42 !important;
  overflow: hidden !important;
  flex-shrink: 0;
}
body.pc-mode #APP.show {
  display: flex;
}
body.pc-mode #LOGIN {
  overflow-y: auto !important;
}
body.pc-mode #SETUP {
  padding: 40px 20px !important;
  background: #0a0a0a !important;
}
/* Keep inner fixed elements within phone frame by switching to absolute */
body.pc-mode #APP.show #NAV,
body.pc-mode #APP.show #STRIP,
body.pc-mode #APP.show #TOAST {
  position: absolute !important;
}
body.pc-mode #APP.show #NAV {
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
}
body.pc-mode #APP.show #STRIP {
  left: 0 !important;
  right: 0 !important;
}
@media (max-width: 900px) {
  .vm-toggle {
    display: none;
  }
  body.pc-mode {
    background: var(--bg);
    padding: 0;
    display: block;
  }
  body.pc-mode #APP.show,
  body.pc-mode #LOGIN,
  body.pc-mode #SETUP,
  body.pc-mode #MODE_SEL,
  body.pc-mode #MD_APP {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    position: fixed !important;
    inset: 0 !important;
  }
  body.pc-mode #APP.show #NAV,
  body.pc-mode #APP.show #STRIP,
  body.pc-mode #APP.show #TOAST {
    position: fixed !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive — mobile · tablet · iPad / iPad Pro (Next app shell)
   Breakpoints: phone ≤767px · tablet 768–1023px · large tablet 1024–1366px
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  body {
    font-size: 14px;
  }
  #TOP {
    padding-left: max(12px, env(safe-area-inset-left, 0));
    padding-right: max(12px, env(safe-area-inset-right, 0));
    padding-top: max(4px, env(safe-area-inset-top, 0));
    min-height: calc(var(--top) + env(safe-area-inset-top, 0));
    height: auto;
    flex-wrap: nowrap;
    gap: 8px;
  }
  .top-brand {
    max-width: 30%;
    line-height: 1.15;
  }
  .top-brand small {
    letter-spacing: 0.3px;
  }
  .top-cust {
    padding: 7px 10px;
  }
  .prog-bar-wrap {
    padding-left: max(12px, env(safe-area-inset-left, 0));
    padding-right: max(12px, env(safe-area-inset-right, 0));
  }
  #costScroll {
    padding-left: max(10px, env(safe-area-inset-left, 0));
    padding-right: max(10px, env(safe-area-inset-right, 0));
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0));
  }
  #histTab {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    padding-bottom: calc(var(--tab) + 20px + env(safe-area-inset-bottom, 0));
  }
  .hist-inner {
    padding-left: max(0px, env(safe-area-inset-left, 0));
    padding-right: max(0px, env(safe-area-inset-right, 0));
  }
  .frow {
    flex-wrap: wrap;
    padding: 10px 12px;
    min-height: 0;
    align-items: flex-start;
  }
  .frow .fl {
    width: 100%;
    margin-bottom: 4px;
  }
  .frow .fv {
    width: 100%;
    justify-content: flex-start;
  }
  .card-hd {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 12px;
  }
  .card-hd > div:has(.card-title) {
    min-width: min(100%, 200px);
  }
  .sell-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px 10px;
  }
  .sc {
    padding: 10px;
  }
  .sc-p {
    font-size: clamp(14px, 4.2vw, 20px);
  }
  .prop-scards {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .psc-p {
    font-size: clamp(13px, 3.8vw, 16px);
  }
  .dsg-sell-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .tech-grid {
    grid-template-columns: 1fr;
  }
  .prop-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    padding: 12px 12px 16px;
  }
  .prop-hd {
    flex-direction: column;
    gap: 10px;
  }
  #STRIP {
    padding-left: max(8px, env(safe-area-inset-left, 0));
    padding-right: max(8px, env(safe-area-inset-right, 0));
  }
  .sv-v {
    font-size: 11px;
  }
  .sv-l {
    font-size: 8px;
  }
  .q-actions {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .q-actions .qa-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
    padding: 9px 10px !important;
    font-size: 11.5px;
  }
}

/* Phone portrait — single column sell / proposal cards */
@media (max-width: 420px) {
  .sell-grid {
    grid-template-columns: 1fr;
  }
  .prop-scards {
    grid-template-columns: 1fr;
  }
}

/* Tablet & iPad portrait — balanced padding, readable line length */
@media (min-width: 768px) and (max-width: 1023px) {
  #NAV.on {
    padding-left: max(12px, env(safe-area-inset-left, 0));
    padding-right: max(12px, env(safe-area-inset-right, 0));
  }
  #TOP {
    padding-left: max(18px, env(safe-area-inset-left, 0));
    padding-right: max(18px, env(safe-area-inset-right, 0));
  }
  #costScroll {
    padding-left: max(20px, env(safe-area-inset-left, 0));
    padding-right: max(20px, env(safe-area-inset-right, 0));
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0));
  }
  .sell-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .tech-grid {
    grid-template-columns: 1fr 1fr;
  }
  .q-actions {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .q-actions .qa-btn {
    flex: 1 1 calc(33.333% - 8px);
    min-width: 0;
    padding: 9px 11px !important;
    font-size: 11.5px;
  }
  #histTab {
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* iPad Pro & large tablets — constrain content width for readability */
@media (min-width: 1024px) and (max-width: 1366px) {
  #NAV.on {
    padding-left: max(12px, env(safe-area-inset-left, 0));
    padding-right: max(12px, env(safe-area-inset-right, 0));
  }
  #costScroll {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
    padding-left: max(24px, env(safe-area-inset-left, 0));
    padding-right: max(24px, env(safe-area-inset-right, 0));
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0));
  }
  #histTab {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
    padding-left: max(12px, env(safe-area-inset-left, 0));
    padding-right: max(12px, env(safe-area-inset-right, 0));
  }
  .sell-grid {
    gap: 10px;
  }
  .q-actions {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .q-actions .qa-btn {
    flex: 1 1 calc(25% - 8px);
    min-width: 0;
  }
}

/* Login / setup safe areas — phone through iPad / iPad Pro */
@media (max-width: 1024px) {
  .lg-header {
    padding-left: max(20px, env(safe-area-inset-left, 0));
    padding-right: max(20px, env(safe-area-inset-right, 0));
    padding-top: max(36px, env(safe-area-inset-top, 0));
  }
  .lg-avatars {
    padding-left: max(20px, env(safe-area-inset-left, 0));
    padding-right: max(20px, env(safe-area-inset-right, 0));
  }
  .lg-pw-area {
    padding-left: max(20px, env(safe-area-inset-left, 0));
    padding-right: max(20px, env(safe-area-inset-right, 0));
  }
}

/* PRINT host — direct child of <body>, hidden on screen, used only for printing */
#PRINT_HOST {
  display: none;
}

@media print {
  @page {
    size: A4;
    margin: 10mm 12mm;
  }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /*
   * ซ่อน Next.js root ทั้งหมด — ป้องกัน layout ของ app กินพื้นที่หน้ากระดาษ
   * เนื้อหาที่จะพิมพ์อยู่ใน #PRINT_HOST ที่เป็น direct child ของ <body>
   */
  body > #__next {
    display: none !important;
  }

  /* แสดง print host เต็มหน้ากระดาษ */
  body > #PRINT_HOST {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #101828 !important;
    overflow: visible !important;
  }

  /* เนื้อหาใบเสนอ — flow ตามธรรมชาติ แบ่งหน้าได้หลายหน้า */
  .proposal-print-area {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    page-break-inside: auto;
    break-inside: auto;
  }

  /* ตาราง — แถวห้ามตัดกลางหน้า */
  .proposal-print-area .prop-tbl {
    page-break-inside: auto;
    break-inside: auto;
    width: 100%;
  }
  .proposal-print-area .prop-tbl tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* การ์ดราคาขาย — อย่าตัดกลาง */
  .proposal-print-area .prop-scards {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* section header — อย่าโดดอยู่ท้ายหน้า */
  .proposal-print-area .prop-sh {
    page-break-after: avoid;
    break-after: avoid;
  }

  /* page-break บังคับเมื่อมี 2+ designs */
  .prop-page2-block {
    page-break-before: always !important;
    break-before: page !important;
    padding-top: 8px;
  }
}
#POUT {
  display: none;
}

/* ══ Responsive & Touch-friendly improvements ══════════════════════════════ */

/* Filter pills — touch target min 44px height on mobile */
@media (max-width: 767px) {
  .hf-pill {
    min-height: 44px;
    padding: 6px 12px;
    font-size: 12px;
  }
  /* Action buttons in quote cards — ensure at least 44px touch area */
  .q-actions .qa-btn {
    min-height: 44px;
  }
  /* 5-pill wrap nicely on small screens */
  .q-nums {
    flex-wrap: wrap;
    gap: 4px;
  }
  .q-num {
    flex: 1 1 calc(33% - 4px);
    min-width: 60px;
    max-width: none;
  }
}

/* Tablet (481–1023px): allow 5 pills side-by-side with flexible sizing */
@media (min-width: 481px) and (max-width: 1023px) {
  .q-num {
    flex: 1 1 80px;
    max-width: 140px;
  }
}

/* Extra small (≤380px): 2-per-row pill wrap */
@media (max-width: 380px) {
  .q-num {
    flex: 1 1 calc(50% - 4px);
    min-width: 56px;
  }
  .hf-pill {
    font-size: 11px;
    padding: 5px 9px;
  }
}

/* Dialogs & modals — full-width on mobile */
@media (max-width: 600px) {
  .lost-modal {
    max-width: 96vw !important;
    padding: 0 !important;
    border-radius: 12px !important;
  }
}

/* Adaptive layout: on PC (wider viewports), increase main content area density */
@media (min-width: 1024px) {
  .q-card {
    grid-template-columns: 115px 180px minmax(340px, 760px) minmax(0, 1fr);
  }
  .q-num {
    min-width: 80px;
    max-width: 130px;
  }
  /* Larger filter pills on desktop for better readability */
  .hf-pill {
    font-size: 12.5px;
    padding: 6px 14px;
  }
}
