.checkout-legacy-page {
  font-family: var(--font-body);
  color: var(--text-primary);
}

.checkout-legacy-page .checkout-layout {
  align-items: flex-start;
}

.checkout-legacy-page .checkout-layout>.checkout-stack:first-child {
  order: 2;
}

.checkout-legacy-page .checkout-layout>.checkout-stack:last-child {
  order: 1;
}

.checkout-legacy-page #shopping-cart,
.checkout-legacy-page .form_detial {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.checkout-legacy-page #shopping-cart>.txt-heading {
  display: none;
}

.checkout-panel-heading {
  padding: 24px 24px 0;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-bottom: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.checkout-legacy-page #shopping-cart.checkout-panel {
  padding: 24px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.checkout-legacy-page .tbl-cart {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  border: 0;
}

.checkout-legacy-page .tbl-cart th {
  padding: 10px 8px;
  border: 0;
  background: var(--primary-light);
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: 0.84rem;
}

.checkout-legacy-page .tbl-cart td {
  padding: 14px 8px;
  border: 0;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.checkout-legacy-page .tbl-cart tr:last-child td {
  border-bottom: 0;
  background: #fbfdff;
  font-family: var(--font-heading);
  font-weight: 800;
}

.checkout-legacy-page .cart-item-image {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
  margin-right: 10px;
  border: 1px solid var(--border-light);
  background: #f7f9fc;
}

.checkout-legacy-page .btnRemoveAction {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--danger-light);
}

.checkout-legacy-page .btnRemoveAction img {
  width: 15px;
  height: 15px;
}

.checkout-legacy-page .form_detial .toppic {
  display: none;
}

.checkout-legacy-page .form_detial table,
.checkout-legacy-page .form_detial tbody,
.checkout-legacy-page .form_detial tr,
.checkout-legacy-page .form_detial td {
  display: block;
  width: 100% !important;
  border: 0;
}

.checkout-legacy-page .form_detial tbody {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 20px;
}

.checkout-legacy-page .form_detial tr {
  min-width: 0;
}

.checkout-legacy-page .form_detial td {
  padding: 0;
}

.checkout-legacy-page .form_detial td.text-right {
  margin-bottom: 8px;
  text-align: left !important;
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: 0.94rem;
  font-weight: 800;
}

.checkout-legacy-page .form_detial tr:nth-child(2),
.checkout-legacy-page .form_detial tr:nth-child(4),
.checkout-legacy-page .form_detial tr:nth-child(10),
.checkout-legacy-page .form_detial tr:nth-child(n+11) {
  grid-column: 1 / -1;
}

.checkout-legacy-page .form_detial tr:has(td.text-right + td:empty) {
  display: none;
}

.checkout-legacy-page .form_detial input:not([type="checkbox"]):not([type="submit"]),
.checkout-legacy-page .form_detial select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-primary);
  transition: var(--transition-fast);
}

.checkout-legacy-page .form_detial input:focus,
.checkout-legacy-page .form_detial select:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: var(--shadow-focus);
}

.checkout-legacy-page .form_detial label {
  color: var(--text-secondary);
  line-height: 1.7;
}

.checkout-legacy-page .no-style {
  width: auto !important;
  min-height: auto !important;
}

.checkout-legacy-page #submitBtn {
  width: auto;
  min-height: 44px;
  padding: 10px 20px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 800;
  box-shadow: var(--shadow-primary);
}

.checkout-legacy-page #submitBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.checkout-legacy-page #submitBtn:not(:disabled):hover {
  background: var(--primary-dark);
}

.checkout-legacy-page .form_detial tr:last-child {
  display: flex;
  justify-content: flex-end;
}

.checkout-legacy-page .form_detial tr:last-child td:first-child {
  display: none;
}

@media (max-width: 991.98px) {

  .checkout-legacy-page .checkout-layout>.checkout-stack:first-child,
  .checkout-legacy-page .checkout-layout>.checkout-stack:last-child {
    order: initial;
  }
}

@media (max-width: 767.98px) {
  .checkout-legacy-page .form_detial tbody {
    grid-template-columns: 1fr;
  }

  .checkout-legacy-page .tbl-cart,
  .checkout-legacy-page .tbl-cart tbody,
  .checkout-legacy-page .tbl-cart tr,
  .checkout-legacy-page .tbl-cart td {
    display: block;
    width: 100%;
  }

  .checkout-legacy-page .tbl-cart th {
    display: none;
  }

  .checkout-legacy-page .tbl-cart tr {
    padding: 14px;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    background: #fff;
  }

  .checkout-legacy-page .tbl-cart td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border: 0;
    text-align: left !important;
  }

  .checkout-legacy-page .tbl-cart td::before {
    flex: 0 0 auto;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 800;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(1) {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    justify-content: start;
    align-items: center;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(1)::before {
    display: none;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(2)::before {
    content: "จำนวน";
  }

  .checkout-legacy-page .tbl-cart td:nth-child(3)::before {
    content: "ราคาต่อรายการ";
  }

  .checkout-legacy-page .tbl-cart td:nth-child(4)::before {
    content: "ราคารวม";
  }

  .checkout-legacy-page .tbl-cart td:nth-child(5)::before {
    content: "ลบ";
  }

  .checkout-legacy-page .tbl-cart tr:last-child td:nth-child(1) {
    display: flex;
  }

  .checkout-legacy-page .tbl-cart tr:last-child td:nth-child(1)::before {
    content: "รวม";
    display: block;
  }

  .checkout-legacy-page .tbl-cart tr:last-child td:nth-child(3)::before {
    content: "ยอดรวม";
  }

  .checkout-legacy-page .cart-item-image {
    width: 58px;
    height: 58px;
    margin-right: 0;
  }
}

/* =========================================================
   Mobile checkout polish
   วางท้ายไฟล์ CSS เดิม
========================================================= */

@media (max-width: 767.98px) {
  .checkout-legacy-page {
    overflow-x: clip;
  }

  .checkout-legacy-page .container.checkout-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* ให้ทุกกล่องมีพื้นที่หายใจบนมือถือ */
  .checkout-legacy-page .checkout-panel,
  .checkout-legacy-page #shopping-cart.checkout-panel {
    padding: 16px;
    border-radius: 18px;
  }

  .checkout-legacy-page .checkout-panel-heading {
    padding: 18px 16px 0;
    border-radius: 18px 18px 0 0;
  }

  .checkout-legacy-page .checkout-panel-body {
    padding: 18px 16px;
  }

  /* กรณี shopping-cart ไม่มี checkout-panel-body */
  .checkout-legacy-page #shopping-cart.checkout-panel .tbl-cart {
    margin-top: 0;
  }

  /* Form legacy table -> mobile form */
  .checkout-legacy-page .form_detial tbody {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .checkout-legacy-page .form_detial tr {
    width: 100%;
    min-width: 0;
  }

  .checkout-legacy-page .form_detial td.text-right {
    margin-bottom: 6px;
    font-size: 0.92rem;
    line-height: 1.4;
  }

  .checkout-legacy-page .form_detial input:not([type="checkbox"]):not([type="submit"]),
  .checkout-legacy-page .form_detial select {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    font-size: 16px;
    border-radius: 14px;
  }

  .checkout-legacy-page .form_detial label {
    display: block;
    line-height: 1.55;
  }

  /* Submit button เต็มแถว */
  .checkout-legacy-page .form_detial tr:last-child {
    display: block;
  }

  .checkout-legacy-page .form_detial tr:last-child td {
    width: 100% !important;
  }

  .checkout-legacy-page #submitBtn {
    width: 100%;
    min-height: 52px;
    border-radius: 16px;
    font-size: 1rem;
  }

  /* Cart table -> mobile card */
  .checkout-legacy-page .tbl-cart,
  .checkout-legacy-page .tbl-cart tbody,
  .checkout-legacy-page .tbl-cart tr,
  .checkout-legacy-page .tbl-cart td {
    display: block;
    width: 100%;
  }

  .checkout-legacy-page .tbl-cart th,
  .checkout-legacy-page .tbl-cart thead {
    display: none;
  }

  .checkout-legacy-page .tbl-cart tbody {
    display: grid;
    gap: 12px;
  }

  .checkout-legacy-page .tbl-cart tr {
    padding: 14px;
    border: 1px solid var(--border-light);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
  }

  .checkout-legacy-page .tbl-cart td {
    border: 0;
    padding: 8px 0;
  }

  .checkout-legacy-page .tbl-cart td:not(:first-child) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: right !important;
  }

  .checkout-legacy-page .tbl-cart td::before {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 800;
    text-align: left;
    white-space: nowrap;
  }

  /* ช่องชื่อสินค้า */
  .checkout-legacy-page .tbl-cart td:nth-child(1) {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding-bottom: 10px;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(1)::before {
    display: none;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(1) * {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .checkout-legacy-page .cart-item-image {
    width: 56px;
    height: 56px;
    margin-right: 0;
    border-radius: 14px;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(2)::before {
    content: "จำนวน";
  }

  .checkout-legacy-page .tbl-cart td:nth-child(3)::before {
    content: "ราคา";
  }

  .checkout-legacy-page .tbl-cart td:nth-child(4)::before {
    content: "รวม";
  }

  .checkout-legacy-page .tbl-cart td:nth-child(5)::before {
    content: "ลบ";
  }

  .checkout-legacy-page .btnRemoveAction {
    width: 38px;
    height: 38px;
    margin-left: auto;
  }

  /* แถวรวมยอด */
  .checkout-legacy-page .tbl-cart tr:last-child {
    background: #f8fbff;
    border-color: rgba(37, 99, 235, 0.14);
  }

  .checkout-legacy-page .tbl-cart tr:last-child td {
    font-weight: 800;
  }

  .checkout-legacy-page .tbl-cart tr:last-child td:nth-child(1) {
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }

  .checkout-legacy-page .tbl-cart tr:last-child td:nth-child(1)::before {
    content: "รวม";
    display: block;
  }

  .checkout-legacy-page .tbl-cart tr:last-child td:nth-child(3)::before {
    content: "ยอดรวม";
  }

  /* OTP */
  .checkout-legacy-page .checkout-otp-toggle,
  .checkout-legacy-page .checkout-otp-link,
  .checkout-legacy-page .checkout-otp-panel__actions .btn-modern,
  .checkout-legacy-page .checkout-otp-panel__actions .btn-primary-modern {
    width: 100%;
  }

  .checkout-legacy-page .checkout-otp-code__slots {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }

  .checkout-legacy-page .checkout-otp-code__slot {
    min-width: 0;
    min-height: 46px;
    font-size: 1rem;
  }
}

@media (max-width: 420px) {
  .checkout-legacy-page .container.checkout-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .checkout-legacy-page .checkout-panel,
  .checkout-legacy-page #shopping-cart.checkout-panel {
    padding: 12px;
    border-radius: 16px;
  }

  .checkout-legacy-page .checkout-panel-heading,
  .checkout-legacy-page .checkout-panel-body {
    padding-left: 12px;
    padding-right: 12px;
  }

  .checkout-legacy-page .tbl-cart tr {
    padding: 12px;
    border-radius: 16px;
  }

  .checkout-legacy-page .tbl-cart td:nth-child(1) {
    grid-template-columns: 50px minmax(0, 1fr);
  }

  .checkout-legacy-page .cart-item-image {
    width: 50px;
    height: 50px;
  }
}