:root {
  --ink: #123a5a;
  --muted: #5b7085;
  --line: #dbe7f1;
  --soft: #f4f9fd;
  --blue: #28b8f4;
  --green: #22c55e;
  --orange: #ff8a00;
  --navy: #0d334f;
  --radius: 18px;
  --shadow: 0 18px 45px rgba(18, 58, 90, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Prompt", Tahoma, Arial, sans-serif;
  background:
    linear-gradient(rgba(40, 184, 244, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(40, 184, 244, 0.055) 1px, transparent 1px),
    linear-gradient(180deg, #f7fbff 0%, #eef8ff 100%);
  background-size: 48px 48px, 48px 48px, auto;
}

button,
input,
select {
  font: inherit;
}

.qb-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 12px clamp(20px, 5vw, 72px);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.qb-brand img {
  display: block;
  width: 148px;
  height: auto;
}

.qb-nav,
.qb-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.qb-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}

.qb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.qb-btn:hover {
  transform: translateY(-1px);
}

.qb-btn--primary {
  color: #fff;
  background: var(--green);
  box-shadow: 0 12px 28px rgba(34, 197, 94, 0.28);
}

.qb-btn--ghost {
  background: #fff;
  border-color: var(--line);
  box-shadow: 0 6px 16px rgba(18, 58, 90, 0.06);
}

.qb-btn--lg {
  min-height: 54px;
  padding: 0 28px;
}

.qb-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 72px;
}

.qb-builder,
.qb-document {
  display: none;
}

.qb-builder.is-active,
.qb-document.is-active {
  display: block;
}

.qb-hero {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr;
  gap: 22px;
  align-items: stretch;
  margin-bottom: 22px;
}

.qb-hero > div:first-child,
.qb-hero-card,
.qb-panel,
.qb-live,
.qb-document-toolbar,
.qb-paper {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.qb-hero > div:first-child {
  padding: clamp(28px, 5vw, 54px);
  border-radius: 28px;
}

.qb-eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  color: #0ea5e9;
  background: #e0f2fe;
  font-size: 13px;
  font-weight: 900;
}

.qb-hero h1 {
  max-width: 820px;
  margin: 18px 0 12px;
  color: var(--ink);
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1.08;
  letter-spacing: 0;
}

.qb-hero p,
.qb-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.qb-hero-card {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  min-height: 240px;
  padding: 26px;
  border-radius: 28px;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(18, 58, 90, 0.95), rgba(13, 95, 85, 0.95)),
    url("../images/warehouse-shelves-480.webp") center/cover;
}

.qb-hero-card strong {
  color: #fff;
  font-size: 24px;
  line-height: 1.2;
}

.qb-hero-card span {
  color: #d8ecf7;
  line-height: 1.6;
}

.qb-form {
  display: grid;
  gap: 18px;
}

.qb-panel {
  padding: 24px;
  border-radius: 24px;
}

.qb-panel__head {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.qb-panel__head > span {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 16px;
  color: #0ea5e9;
  background: #e0f2fe;
  font-weight: 900;
}

.qb-panel__head h2 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 26px;
  line-height: 1.24;
}

.qb-field-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 800;
}

label span {
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(40, 184, 244, 0.12);
}

.qb-note {
  margin: -4px 0 15px;
  padding: 12px 14px;
  border-radius: 16px;
  color: #7c2d12;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  font-size: 13px;
  line-height: 1.55;
}

.qb-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

.qb-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.qb-table th {
  padding: 14px 12px;
  color: #fff;
  background: var(--ink);
  text-align: left;
  font-size: 13px;
}

.qb-table td {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.qb-table input,
.qb-table select {
  min-height: 42px;
  border-radius: 12px;
}

.qb-table input[type="number"] {
  min-width: 92px;
}

.qb-table .qb-readonly {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.qb-remove {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #fecaca;
  border-radius: 12px;
  color: #dc2626;
  background: #fff1f2;
  font-weight: 900;
  cursor: pointer;
}

.qb-remove:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.qb-add {
  margin-top: 14px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px dashed #7dd3fc;
  border-radius: 14px;
  color: #0284c7;
  background: #f0f9ff;
  font-weight: 900;
  cursor: pointer;
}

.qb-live {
  position: sticky;
  bottom: 16px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 24px;
  backdrop-filter: blur(18px);
}

.qb-live div {
  min-height: 70px;
  padding: 13px 16px;
  border-radius: 18px;
  background: #f7fbff;
  border: 1px solid #e2edf6;
}

.qb-live span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.qb-live strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.qb-status {
  min-height: 22px;
  margin: 0;
  color: #dc2626;
  font-weight: 800;
}

.qb-document-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  padding: 18px;
  border-radius: 24px;
}

.qb-document-toolbar h2 {
  margin: 8px 0 0;
  font-size: 32px;
  line-height: 1.2;
}

.qb-paper {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 0;
  border-radius: 24px;
  overflow: hidden;
}

.quote-page {
  background: #fff;
  color: var(--ink);
}

.quote-cover {
  padding: 34px 38px;
  color: #fff;
  background: linear-gradient(145deg, #123a5a, #0f5f55);
}

.quote-cover__top,
.quote-meta,
.quote-total-row,
.quote-signatures {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.quote-cover img {
  width: 150px;
  height: auto;
  filter: brightness(0) invert(1);
}

.quote-cover small {
  display: block;
  color: #b9d7e8;
  font-weight: 800;
}

.quote-cover h1 {
  margin: 34px 0 10px;
  color: #fff;
  font-size: 38px;
  line-height: 1.15;
}

.quote-cover p {
  max-width: 700px;
  margin: 0;
  color: #d8ecf7;
  line-height: 1.7;
}

.quote-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  color: #7c2d12;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  font-weight: 900;
}

.quote-body {
  padding: 30px 38px 38px;
}

.quote-meta {
  margin-bottom: 22px;
}

.quote-meta > div,
.quote-total-card,
.quote-mini-card,
.quote-section {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #f8fbff;
}

.quote-meta > div {
  flex: 1;
  padding: 16px;
}

.quote-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.quote-meta strong,
.quote-mini-card strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 18px;
}

.quote-total-row {
  margin: 20px 0;
}

.quote-total-card {
  flex: 1.25;
  padding: 20px;
  color: #fff;
  background: linear-gradient(145deg, var(--ink), #0f5f55);
}

.quote-total-card strong {
  display: block;
  margin-top: 8px;
  color: #fff;
  font-size: 38px;
  line-height: 1;
}

.quote-total-card span {
  color: #d8ecf7;
}

.quote-mini-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.quote-mini-card {
  padding: 15px;
}

.quote-section {
  margin-top: 16px;
  padding: 18px;
  background: #fff;
}

.quote-section h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.quote-table {
  width: 100%;
  border-collapse: collapse;
}

.quote-table th,
.quote-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.quote-table th {
  color: #fff;
  background: var(--ink);
  font-size: 12px;
}

.quote-table td:last-child,
.quote-table th:last-child {
  text-align: right;
  font-weight: 900;
}

.quote-warning {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  color: #7c2d12;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  line-height: 1.6;
}

.quote-signatures {
  margin-top: 22px;
}

.quote-signatures div {
  flex: 1;
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--muted);
}

.quote-signatures strong {
  display: block;
  margin-top: 44px;
  padding-top: 10px;
  border-top: 1px solid #c9d8e4;
  color: var(--ink);
}

@media (max-width: 920px) {
  .qb-header,
  .qb-nav,
  .qb-document-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .qb-nav,
  .qb-toolbar-actions {
    width: 100%;
  }

  .qb-nav .qb-btn,
  .qb-toolbar-actions .qb-btn,
  .qb-link {
    flex: 1;
  }

  .qb-hero,
  .qb-field-grid,
  .qb-live {
    grid-template-columns: 1fr;
  }

  .qb-live {
    position: static;
  }

  .quote-cover__top,
  .quote-meta,
  .quote-total-row,
  .quote-signatures {
    flex-direction: column;
  }

  .quote-mini-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  html,
  body {
    overflow-x: hidden;
  }

  .qb-header {
    gap: 12px;
    min-height: 0;
    padding: 10px 14px;
  }

  .qb-brand img {
    width: 126px;
  }

  .qb-nav,
  .qb-toolbar-actions {
    display: grid;
    gap: 8px;
  }

  .qb-nav {
    grid-template-columns: 1fr;
  }

  .qb-toolbar-actions {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .qb-link,
  .qb-btn,
  .qb-hero,
  .qb-hero > div:first-child,
  .qb-hero-card,
  .qb-panel,
  .qb-live,
  .qb-document-toolbar {
    min-width: 0;
  }

  .qb-link {
    min-height: 36px;
    text-align: center;
  }

  .qb-btn {
    min-height: 42px;
    padding: 0 12px;
    font-size: 13px;
    line-height: 1.2;
    white-space: normal;
    text-align: center;
  }

  .qb-shell {
    width: 100%;
    max-width: 100%;
    padding: 18px 10px 72px;
    overflow-x: hidden;
  }

  .qb-panel,
  .qb-hero > div:first-child,
  .qb-hero-card,
  .qb-live,
  .qb-document-toolbar {
    border-radius: 18px;
    padding: 18px;
  }

  .qb-builder,
  .qb-document,
  .qb-hero,
  .qb-form,
  .qb-panel,
  .qb-hero > div:first-child,
  .qb-hero-card,
  .qb-live,
  .qb-document-toolbar,
  .qb-paper {
    width: 100%;
    max-width: 100%;
  }

  .qb-panel,
  .qb-hero > div:first-child,
  .qb-hero-card,
  .qb-live,
  .qb-document-toolbar,
  .qb-paper {
    width: 88vw;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
  }

  .qb-hero h1 {
    font-size: 25px;
    max-width: 100%;
    line-break: anywhere;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .qb-hero p,
  .qb-hero-card strong,
  .qb-hero-card span,
  .qb-panel p,
  label span {
    max-width: 100%;
    line-break: anywhere;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .qb-panel__head {
    grid-template-columns: 40px 1fr;
    gap: 10px;
  }

  .qb-panel__head > span {
    width: 38px;
    height: 38px;
    border-radius: 13px;
  }

  .qb-panel__head h2,
  .qb-document-toolbar h2 {
    font-size: 22px;
  }

  .qb-table-wrap {
    margin-inline: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .qb-table,
  .qb-table thead,
  .qb-table tbody,
  .qb-table tr,
  .qb-table td {
    display: block;
  }

  .qb-table {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
  }

  .qb-table thead {
    display: none;
  }

  .qb-table tbody {
    display: grid;
    gap: 12px;
    counter-reset: qb-mobile-row;
  }

  .qb-table tr {
    counter-increment: qb-mobile-row;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: linear-gradient(145deg, #fff 0%, #f6fbff 100%);
    box-shadow: 0 12px 28px rgba(18, 58, 90, 0.08);
  }

  #skuRows tr::before,
  #orderRows tr::before {
    grid-column: 1 / -1;
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 28px;
    padding: 0 11px;
    border-radius: 999px;
    color: #0284c7;
    background: #e0f2fe;
    font-size: 12px;
    font-weight: 900;
  }

  #skuRows tr::before {
    content: "SKU #" counter(qb-mobile-row);
  }

  #orderRows tr::before {
    content: "บรรจุภัณฑ์ #" counter(qb-mobile-row);
  }

  .qb-table td {
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .qb-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    line-height: 1.25;
  }

  #skuRows td:first-child,
  #skuRows td:nth-child(6),
  #skuRows .qb-action-cell,
  #orderRows td:first-child,
  #orderRows td:nth-child(4),
  #orderRows td:nth-child(5),
  #orderRows .qb-action-cell {
    grid-column: 1 / -1;
  }

  .qb-table input,
  .qb-table select,
  .qb-table .qb-readonly {
    min-height: 44px;
    border-radius: 14px;
  }

  .qb-table input[type="number"] {
    min-width: 0;
  }

  .qb-table .qb-readonly {
    padding: 11px 12px;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    white-space: normal;
  }

  .qb-action-cell::before {
    display: none;
  }

  .qb-table .qb-remove {
    width: 100%;
    height: 42px;
    border-radius: 14px;
    font-size: 0;
  }

  .qb-table .qb-remove::before {
    content: "ลบรายการ";
    font-size: 13px;
  }

  .qb-table .qb-remove:disabled::before {
    content: "ลบไม่ได้";
  }

  .qb-live div {
    min-height: 58px;
  }

  .qb-live strong {
    font-size: 20px;
  }

  .quote-cover,
  .quote-body {
    padding: 24px 18px;
  }

  .quote-cover h1 {
    font-size: 28px;
  }
}

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

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

  body {
    background: #fff;
    font-size: 10px;
  }

  .qb-header,
  .qb-builder,
  .qb-document-toolbar {
    display: none !important;
  }

  .qb-shell {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .qb-document,
  .qb-document.is-active {
    display: block !important;
  }

  .qb-paper {
    width: 190mm;
    max-width: 190mm;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    zoom: 0.96;
  }

  .quote-page {
    width: 190mm;
    min-height: auto;
    page-break-after: auto;
  }

  .quote-cover {
    padding: 13mm 12mm 9mm;
  }

  .quote-cover img {
    width: 106px;
  }

  .quote-cover h1 {
    margin: 14px 0 6px;
    font-size: 25px;
    line-height: 1.12;
  }

  .quote-cover p {
    max-width: none;
    font-size: 10.5px;
    line-height: 1.45;
  }

  .quote-cover small {
    font-size: 10px;
  }

  .quote-badge {
    min-height: 24px;
    padding: 0 10px;
    font-size: 10px;
  }

  .quote-body {
    padding: 7mm 12mm 10mm;
  }

  .quote-cover__top,
  .quote-meta,
  .quote-total-row,
  .quote-signatures {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between;
    gap: 10px;
  }

  .quote-meta {
    margin-bottom: 10px;
  }

  .quote-meta > div,
  .quote-signatures div {
    flex: 1 1 0;
  }

  .quote-meta > div {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .quote-label {
    font-size: 9.5px;
  }

  .quote-meta strong,
  .quote-mini-card strong {
    margin-top: 3px;
    font-size: 14px;
  }

  .quote-total-row {
    margin: 10px 0;
  }

  .quote-total-card {
    flex: 1.25 1 0;
    padding: 12px 14px;
    border-radius: 12px;
  }

  .quote-total-card strong {
    margin-top: 5px;
    font-size: 28px;
  }

  .quote-total-card span {
    font-size: 10.5px;
  }

  .quote-mini-grid {
    flex: 1 1 0;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
  }

  .quote-mini-card {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .quote-section {
    margin-top: 10px;
    padding: 11px 12px;
    border-radius: 12px;
    break-inside: auto;
    page-break-inside: auto;
  }

  .quote-section h2 {
    margin-bottom: 7px;
    font-size: 16px;
    break-after: avoid;
  }

  .quote-table th,
  .quote-table td {
    padding: 6px 7px;
    font-size: 10px;
    line-height: 1.32;
  }

  .quote-table th {
    font-size: 9.5px;
  }

  .quote-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .quote-warning {
    margin-top: 10px;
    padding: 9px 11px;
    border-radius: 12px;
    font-size: 10px;
    line-height: 1.45;
  }

  .quote-signatures {
    margin-top: 8px;
  }

  .quote-signatures div {
    min-height: 50px;
    padding: 9px 11px;
    border-radius: 12px;
    font-size: 10px;
  }

  .quote-signatures strong {
    margin-top: 18px;
    padding-top: 6px;
  }

  .quote-meta > div,
  .quote-total-card,
  .quote-mini-card {
    break-inside: avoid;
  }
}
