:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #647083;
  --line: #d9dee8;
  --surface: #ffffff;
  --wash: #f4f6f9;
  --accent: #e85735;
  --accent-dark: #ba3d21;
  --warning: #fff5dc;
  --warning-ink: #765018;
  --danger: #fff0ef;
  --danger-ink: #a9322a;
  --success: #edf8f1;
  --success-ink: #246a42;
}

* {
  box-sizing: border-box;
}

*[hidden] {
  display: none !important;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--wash);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Noto Sans Thai", "Noto Sans", sans-serif;
  line-height: 1.55;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

.app-shell {
  width: min(100% - 24px, 620px);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 0 calc(32px + env(safe-area-inset-bottom));
}

.brand-header {
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  line-height: 1.2;
}

.intro {
  margin-bottom: 0;
  color: var(--muted);
}

.demo-banner,
.status-panel,
fieldset,
.result-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.demo-banner,
.status-panel {
  margin-bottom: 14px;
  padding: 12px 14px;
  font-size: 0.9rem;
}

.demo-banner {
  border-color: #eed29b;
  background: var(--warning);
  color: var(--warning-ink);
  font-weight: 700;
}

.status-panel[data-tone="blocked"] {
  border-color: #f0b6b0;
  background: var(--danger);
  color: var(--danger-ink);
}

.status-panel[data-tone="ready"] {
  border-color: #b6dec5;
  background: var(--success);
  color: var(--success-ink);
}

fieldset {
  min-width: 0;
  margin: 14px 0;
  padding: 18px;
}

legend {
  padding: 0 7px;
  font-weight: 800;
}

label,
.section-help,
.field-help {
  color: var(--muted);
  font-size: 0.92rem;
}

.quantity-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.quantity-control {
  display: grid;
  grid-template-columns: minmax(52px, 1fr) minmax(72px, 1.2fr) minmax(52px, 1fr);
  align-items: stretch;
  width: min(100%, 260px);
  overflow: hidden;
  border: 1px solid #b8c0cf;
  border-radius: 12px;
  background: #fff;
}

.quantity-button,
.item-count {
  display: grid;
  min-height: 52px;
  place-items: center;
}

.quantity-button {
  border: 0;
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.5rem;
  font-weight: 800;
}

.quantity-button:first-child {
  border-right: 1px solid #d8dde7;
}

.quantity-button:last-child {
  border-left: 1px solid #d8dde7;
}

.quantity-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.item-count {
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
}

.quantity-button:focus-visible {
  outline: 3px solid rgba(232, 87, 53, 0.2);
  outline-offset: -3px;
}

.item-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.item-card {
  min-width: 0;
  padding: 15px 13px;
  border: 1px solid #e2e6ee;
  border-radius: 14px;
  background: #fbfcfe;
}

.item-heading {
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.item-card .section-help {
  margin-top: 16px;
}

.section-help,
.field-help {
  margin: 6px 0 12px;
}

.combobox {
  position: relative;
  display: flex;
  align-items: stretch;
  margin-top: 6px;
}

.combobox input {
  width: 100%;
  min-height: 52px;
  padding: 12px 52px 12px 14px;
  border: 1px solid #b8c0cf;
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
}

.combobox input:focus {
  outline: 3px solid rgba(232, 87, 53, 0.2);
  border-color: var(--accent);
}

.combobox-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 48px;
  height: 52px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.25rem;
}

.combobox-options {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  max-height: min(290px, 45vh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(23, 32, 51, 0.14);
}

.brand-option,
.empty-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 14px;
}

.brand-option {
  cursor: pointer;
}

.brand-option:hover,
.brand-option.active {
  background: #fff2ed;
}

.brand-option[aria-selected="true"] {
  font-weight: 800;
}

.brand-option small {
  color: var(--muted);
  white-space: nowrap;
}

.combobox-toggle:focus-visible,
.quantity-button:focus-visible,
.primary-button:focus-visible,
.photo-card:focus-within,
.photo-card input:focus-visible {
  outline: 3px solid rgba(232, 87, 53, 0.28);
  outline-offset: 2px;
}

.empty-option {
  color: var(--muted);
}

.price-preview {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--success);
  color: var(--success-ink);
  font-weight: 800;
}

.price-preview.review {
  background: var(--warning);
  color: var(--warning-ink);
}

.field-error,
.form-error {
  margin: 8px 0 0;
  color: var(--danger-ink);
  font-size: 0.9rem;
}

.photo-grid {
  display: grid;
  gap: 10px;
}

.photo-card {
  display: grid;
  gap: 10px;
  min-height: 170px;
  padding: 13px;
  border: 1px dashed #b8c0cf;
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
}

.photo-slot-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.photo-slot-label {
  font-weight: 700;
}

.photo-slot-requirement {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: right;
}

.photo-actions,
.photo-manage-actions,
.camera-actions {
  display: grid;
  gap: 8px;
}

.photo-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.photo-actions button,
.photo-manage-actions button,
.secondary-button {
  min-height: 48px;
  padding: 9px 10px;
  border: 1px solid #b8c0cf;
  border-radius: 10px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.photo-actions button:first-child,
.primary-button {
  background: #fff2ed;
  border-color: #e8a28f;
  color: #8b321f;
}

.photo-actions button:disabled,
.photo-manage-actions button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.photo-actions button:focus-visible,
.photo-manage-actions button:focus-visible,
.secondary-button:focus-visible,
.camera-close:focus-visible,
.camera-actions button:focus-visible {
  outline: 3px solid rgba(232, 87, 53, 0.28);
  outline-offset: 2px;
}

.visually-hidden-input {
  display: none !important;
}

.photo-empty {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: var(--wash);
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.photo-preview {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.photo-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
  background: #eef1f5;
}

.photo-preview-meta {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.terms-section {
  margin: 18px 0 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.terms-section h2 {
  margin-bottom: 10px;
  font-size: 1.12rem;
}

.terms-list {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding-left: 21px;
  color: var(--muted);
  font-size: 0.9rem;
}

.terms-list li {
  padding-left: 3px;
}

.terms-list strong {
  color: var(--ink);
}

.terms-list p {
  margin: 3px 0 0;
}

.terms-acceptance {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 10px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.terms-acceptance input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

[data-photo-status] {
  color: var(--muted);
  font-size: 0.84rem;
}

.photo-manage-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.camera-modal {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(23, 32, 51, 0.72);
}

.camera-dialog {
  display: grid;
  gap: 12px;
  width: min(100%, 520px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 16px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(23, 32, 51, 0.3);
}

.camera-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.camera-dialog-header h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.camera-close {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #b8c0cf;
  border-radius: 10px;
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}

.camera-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.camera-status[data-tone="error"] {
  color: var(--danger-ink);
}

.camera-status[data-tone="ready"] {
  color: var(--success-ink);
}

.camera-viewer {
  display: grid;
  min-height: 180px;
  overflow: hidden;
  place-items: center;
  border-radius: 12px;
  background: #0d1320;
}

.camera-viewer video,
.camera-viewer img {
  display: block;
  width: 100%;
  max-height: min(54vh, 430px);
  object-fit: contain;
}

.camera-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.camera-actions .primary-button {
  width: 100%;
  min-height: 50px;
  margin-top: 0;
}

.camera-actions .secondary-button {
  width: 100%;
}

#camera-review-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-panel {
  margin: 14px 0;
  padding: 18px;
  border-color: #b6dec5;
  background: var(--success);
}

.receipt-shell {
  max-width: 680px;
}

.receipt-card {
  padding: 24px 20px;
  border: 1px solid #b6dec5;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(23, 32, 51, 0.08);
}

.receipt-success-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 14px;
  place-items: center;
  border-radius: 50%;
  background: var(--success);
  color: var(--success-ink);
  font-size: 2rem;
  font-weight: 900;
}

.receipt-card h1 {
  margin-bottom: 8px;
}

.receipt-lead {
  color: var(--muted);
}

.receipt-meta {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  padding: 14px;
  border-radius: 12px;
  background: var(--wash);
}

.receipt-meta div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.receipt-meta dt {
  color: var(--muted);
}

.receipt-meta dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.receipt-section,
.receipt-price-summary {
  margin-top: 20px;
}

.receipt-section h2,
.receipt-price-summary h2 {
  margin-bottom: 10px;
  font-size: 1.12rem;
}

.receipt-items {
  display: grid;
  gap: 10px;
}

.receipt-item {
  padding: 13px;
  border: 1px solid #e2e6ee;
  border-radius: 12px;
  background: #fbfcfe;
}

.receipt-item h3,
.receipt-item p {
  margin-bottom: 4px;
}

.receipt-brand {
  font-weight: 800;
}

.receipt-price-summary {
  padding: 15px;
  border: 1px solid #eed29b;
  border-radius: 12px;
  background: var(--warning);
  color: var(--warning-ink);
}

.receipt-total {
  margin-bottom: 8px;
  font-size: 1.08rem;
  font-weight: 900;
}

.receipt-price-notice {
  margin: 10px 0 0;
  font-size: 0.9rem;
}

.receipt-complete {
  margin: 22px 0 4px;
  color: var(--success-ink);
  font-size: 1.1rem;
  font-weight: 900;
}

.receipt-terms-note {
  color: var(--muted);
  font-size: 0.8rem;
}

.receipt-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.receipt-actions .secondary-button {
  display: grid;
  place-items: center;
  min-height: 50px;
  text-decoration: none;
  text-align: center;
}

.result-panel h2 {
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.result-panel p {
  margin-bottom: 4px;
}

.fallback-note {
  margin-top: 12px;
  color: var(--warning-ink);
  font-size: 0.9rem;
}

.primary-button {
  width: 100%;
  min-height: 56px;
  margin-top: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-footer {
  padding-top: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.app-footer p {
  margin-bottom: 3px;
}

@media (min-width: 540px) {
  .photo-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .photo-card {
    min-height: 160px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: calc(100% - 20px);
  }

  fieldset {
    margin: 12px 0;
    padding: 15px 13px;
    border-radius: 14px;
  }

  legend {
    max-width: 92%;
  }

  .brand-option,
  .empty-option {
    align-items: flex-start;
    min-height: 52px;
    padding: 12px;
  }

  .brand-option small {
    max-width: 42%;
    white-space: normal;
    text-align: right;
  }

  .photo-card {
    min-height: 0;
    padding: 14px 12px;
  }

  .item-card {
    padding: 14px 11px;
  }

  .photo-slot-heading {
    display: block;
  }

  .photo-slot-requirement {
    display: block;
    margin-top: 2px;
    text-align: left;
  }

  .photo-actions button,
  .photo-manage-actions button {
    min-height: 50px;
  }

  #camera-review-actions {
    grid-template-columns: 1fr;
  }

  .receipt-card {
    padding: 20px 14px;
  }

  .receipt-meta div {
    display: grid;
    gap: 1px;
  }

  .receipt-meta dd {
    text-align: left;
  }

  .receipt-actions {
    grid-template-columns: 1fr;
  }
}
