* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", Arial, sans-serif;
  background: #f5f3ef;
  color: #1c1c1c;
}

.container {
  max-width: 1100px;
  margin: 40px auto;
  padding: 0 24px 60px;
}

.page-header h1 {
  margin: 0;
  font-size: 32px;
}

.page-header__title {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header__logo {
  height: 60px;
  width: auto;
  object-fit: contain;
  flex: 0 0 auto;
}

.page-header p {
  margin: 8px 0 24px;
  color: #555;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  font-weight: 600;
  font-size: 14px;
  gap: 6px;
}

label.debug-toggle {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  margin-bottom: 16px;
}

label.debug-toggle input {
  width: 16px;
  height: 16px;
  accent-color: #e27023;
}

input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #d9d9d9;
  font-size: 14px;
}

.rich-editor {
  margin-top: 8px;
}

.terms-toolbar {
  border: 1px solid #d9d9d9;
  border-radius: 10px 10px 0 0;
  background: #f7f5f2;
}

.terms-editor {
  border: 1px solid #d9d9d9;
  border-top: none;
  border-radius: 0 0 10px 10px;
  min-height: 140px;
  background: #fff;
  font-size: 14px;
}

.terms-editor .ql-editor {
  min-height: 140px;
  padding: 12px;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.item-input-wrapper {
  position: relative;
}

.autocomplete-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  z-index: 10;
}

.autocomplete-results.is-open {
  display: block;
}

.autocomplete-portal {
  position: fixed;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.14);
  padding: 6px 0;
  min-width: 420px;
  max-width: 640px;
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 9999;
}

.autocomplete-portal.is-open {
  display: block;
}

.autocomplete-result {
  width: 100%;
  background: transparent;
  border: none;
  padding: 12px 14px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-size: 13px;
  color: #1c1c1c;
}

.resultRow {
  align-items: flex-start;
  min-height: 56px;
}

.resultMeta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.resultCode {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.resultDesc {
  font-size: 12px;
  color: #555;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.resultPrice {
  font-weight: 600;
  white-space: nowrap;
  align-self: center;
}

.autocomplete-result.is-active,
.autocomplete-result:hover {
  background: #f3efe9;
}

.autocomplete-empty {
  padding: 8px 12px;
  font-size: 13px;
  color: #666;
}

.table-wrapper {
  overflow-x: auto;
  padding-right: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 0;
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid #ececec;
}

th {
  background: #f8f5f1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}

.description-col {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

#items-table th.description-col,
#items-table td.description-col {
  width: 42%;
}

#items-table th.qty-col,
#items-table td.qty-col {
  width: 80px;
  text-align: right;
}

#items-table th.unit-price-col,
#items-table td.unit-price-col {
  width: 120px;
  text-align: right;
}

#items-table input {
  width: 100%;
}

/* Prevent right-edge clipping of actions button while retaining table layout. */
.actions-col {
  width: 90px;
  min-width: 90px;
}

.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.line-items-actions {
  display: flex;
  gap: 10px;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  background: #e27023;
  color: #fff;
}

.line-item-actions {
  text-align: right;
}

.remove-line-item {
  background: transparent;
  color: #c0392b;
  border: 1px solid #e0b4ae;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  min-height: 40px;
  min-width: 40px;
}

.remove-line-item:hover {
  background: #fbeaea;
}

button.primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.totals {
  max-width: 280px;
  margin-left: auto;
  margin-top: 16px;
  border-top: 1px solid #e6e6e6;
  padding-top: 12px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.totals-row--grand {
  font-size: 18px;
  font-weight: 700;
}

.hint {
  margin-top: 12px;
  color: #555;
}

.extended {
  text-align: right;
}

.catalog-search input {
  max-width: 420px;
}

.catalog-results {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.catalog-result {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  background: #f9f6f1;
  border-radius: 10px;
}

.catalog-result__desc {
  margin-top: 4px;
  font-size: 13px;
  color: #555;
}

.catalog-result__price {
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 700px) {
  .container {
    margin-top: 20px;
  }

  button.primary {
    font-size: 15px;
  }
}

/* Mobile preview breakpoint: adjust as needed for line items table. */
@media (max-width: 768px) {
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #items-table {
    min-width: 720px;
  }
}

@media (max-width: 600px) {
  #items-table {
    min-width: 0;
  }

  #items-table thead {
    display: none;
  }

  #items-table tbody tr {
    display: block;
    border: 1px solid #ececec;
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 4px 0;
  }

  #items-table tbody td {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
  }

  #items-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
    color: #666;
    flex: 0 0 auto;
  }

  #items-table tbody td:last-child {
    border-bottom: none;
  }

  #items-table td.line-item-actions {
    align-items: flex-end;
  }

  #items-table td.line-item-actions::before {
    content: "";
  }

  #items-table input {
    min-width: 0;
    width: 100%;
  }
}
