*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #efebe3;
  color: #1a1a1a;
  line-height: 1.4;
}

.app {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.panel {
  background: #f7f4ee;
  border-right: 1px solid #d9d3c6;
  padding: 1rem 1rem 1.5rem;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}

.panel h1 {
  margin: 0;
  font-size: 1.35rem;
  color: #1a1a1a;
  line-height: 1.25;
}

.panel .subtitle {
  margin: 0.4rem 0 0.75rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: #555;
}

.easy-tip {
  background: #ebe4d4;
  border: 1px solid #d4c9b0;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  margin: 0 0 1rem;
  font-size: 0.92rem;
  color: #3a3a3a;
  line-height: 1.4;
}

.easy-tip strong {
  color: #6b643f;
}

.field {
  margin-bottom: 0.85rem;
}

.field label {
  display: block;
  font-size: 0.86rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: #333;
  letter-spacing: 0;
  text-transform: none;
}

.field input,
.field textarea,
.order-items-table input,
.order-items-table textarea {
  width: 100%;
  padding: 0.8rem 0.85rem;
  border: 1.5px solid #c9c2b4;
  border-radius: 10px;
  background: #fff;
  color: #111;
  font: inherit;
  font-size: 16px; /* stops iPhone zoom on focus */
  line-height: 1.35;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field textarea:focus,
.order-items-table input:focus,
.order-items-table textarea:focus {
  outline: 2px solid #8b8356;
  border-color: #8b8356;
  background: #fff;
}

.field textarea,
.order-items-table textarea {
  min-height: 0;
  height: auto;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  field-sizing: content;
}

.field-group {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #ddd5c5;
}

.field-group h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 800;
  color: #6b643f;
  text-transform: none;
  letter-spacing: 0;
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
  font-size: 1rem;
  line-height: 1.35;
  padding: 0.65rem 0.75rem;
  background: #fff;
  border: 1.5px solid #c9c2b4;
  border-radius: 10px;
}

.checkbox-field input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  flex-shrink: 0;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1rem;
}

.actions-below-preview {
  margin-top: 1.1rem;
  padding: 1rem 0 calc(1.25rem + env(safe-area-inset-bottom));
  border-top: 1px solid #d0c9ba;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.95rem 1rem;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
}

.btn-primary {
  background: #8b8356;
  color: #fff;
}

.btn-primary:hover {
  background: #7a7349;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-message {
  background: #0a7ea4;
  color: #fff;
}

.btn-message:hover {
  background: #086987;
}

.btn-message:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: #fff;
  color: #222;
  border: 1.5px solid #c9c2b4;
}

.status {
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 0.92rem;
  color: #2f6b3a;
  min-height: 1.2rem;
  font-weight: 600;
}

.status.error {
  color: #b42318;
}

.preview-wrap {
  padding: 1rem 1rem 2rem;
  overflow-y: auto;
  background: #e6e1d6;
}

.preview-note {
  max-width: 1224px;
  margin: 0 auto 0.75rem;
  font-size: 0.92rem;
  color: #555;
}

.page-wrap {
  max-width: 1224px;
  margin: 0 auto 1.25rem;
  position: relative;
}

.page-wrap.updating img {
  opacity: 0.55;
}

.page-wrap img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  transition: opacity 0.2s ease;
  background: #fff;
}

.page-label {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: rgba(26, 26, 26, 0.75);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  z-index: 2;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.order-items-scroll {
  overflow-x: visible;
  margin-top: 0.35rem;
}

.order-items-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.65rem;
  font-size: 0.95rem;
  min-width: 0;
}

.order-items-table th {
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  color: #6b643f;
  padding: 0.25rem 0.35rem;
  border-bottom: none;
  text-transform: none;
  letter-spacing: 0;
}

.order-items-table td {
  padding: 0.2rem 0.25rem;
  vertical-align: top;
}

.order-items-table .col-qty,
.order-items-table .col-uom {
  width: 4.2rem;
}

.order-items-table .col-sku {
  width: 6rem;
}

.order-items-table .col-price,
.order-items-table .col-amount {
  width: 5.5rem;
}

.order-row-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #6b643f;
  padding-top: 0.5rem !important;
}

.field-hint {
  margin: -0.2rem 0 0.65rem;
  font-size: 0.88rem;
  color: #666;
  line-height: 1.4;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  padding: 0.55rem 0.85rem;
  color: #3f3b28;
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  background: #fff;
  border: 1.5px solid #c9c2b4;
  border-radius: 999px;
  line-height: 1.2;
}

.back-link:active {
  opacity: 0.75;
  background: #faf8f3;
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
    height: auto;
    border-right: none;
    padding: 0.85rem 1rem 1.25rem;
  }

  .back-link {
    position: sticky;
    top: 0;
    z-index: 40;
    margin-left: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .actions-below-preview {
    margin-top: 0.85rem;
  }

  /* Stack line-item tables into readable cards */
  .order-items-table thead {
    display: none;
  }

  .order-items-table,
  .order-items-table tbody {
    display: block;
    width: 100%;
  }

  .order-items-table tr {
    display: block;
    width: 100%;
    background: #fff;
    border: 1.5px solid #c9c2b4;
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .order-items-table tr:has(.order-row-label) {
    background: transparent;
    border: none;
    padding: 0.15rem 0.1rem 0;
    margin-bottom: 0;
  }

  .order-items-table td {
    display: block;
    width: 100%;
    padding: 0.35rem 0;
  }

  .order-items-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #555;
    margin-bottom: 0.25rem;
  }

  .order-items-table .col-qty,
  .order-items-table .col-uom,
  .order-items-table .col-sku,
  .order-items-table .col-price,
  .order-items-table .col-amount,
  .order-items-table .col-desc {
    width: 100%;
  }

  .preview-wrap {
    padding: 0.75rem 0.75rem 2rem;
  }

  .preview-note {
    font-size: 0.9rem;
  }
}
