* {
  box-sizing: border-box;
}

:root {
  --brand-accent: #eda300;
  --brand-accent-hover: #d49400;
  --brand-accent-focus: rgba(237, 163, 0, 0.35);
}

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 {
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid #dfdbd1;
}

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

.page-header__bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
}

.page-header__title {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

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

.page-header p {
  margin: 10px 0 0;
  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: var(--brand-accent);
}

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;
}

#items-table th {
  background: var(--brand-accent);
  color: #ffffff;
}

.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;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8f5f1;
}

.line-items-actions label {
  margin: 0;
}

.line-items-actions select {
  min-width: 210px;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand-accent);
  color: #fff;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  background: var(--brand-accent-hover);
}

button:focus-visible {
  outline: 2px solid transparent;
  box-shadow: 0 0 0 3px var(--brand-accent-focus);
}

.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: 980px) {
  .page-header__bar {
    grid-template-columns: 1fr;
    justify-items: start;
    gap: 12px;
  }

  .auth-controls {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .page-header h1 {
    font-size: 24px;
  }

  .page-header__logo {
    height: 48px;
  }

  .page-nav {
    width: 100%;
  }

  .page-nav a {
    flex: 1;
  }

  .signed-in-user {
    max-width: 100%;
  }
}

@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%;
  }
}

.page-nav {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid #ddd7cc;
  border-radius: 999px;
  background: #f7f4ee;
}

.page-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  color: #5c5340;
  border-radius: 999px;
  padding: 8px 14px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.page-nav a:hover {
  background: #ece7dc;
}

.page-nav a[aria-current="page"] {
  background: var(--brand-accent);
  color: #ffffff;
}

.auth-controls {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.signed-in-user {
  font-size: 13px;
  color: #464646;
  background: #f2eee6;
  border: 1px solid #ddd7cc;
  border-radius: 999px;
  padding: 7px 12px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-link,
.button-link--outline,
.button-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border-radius: 999px;
  padding: 8px 14px;
}

.button-link--outline {
  color: #51493a;
  border: 1px solid #d3cebf;
  background: #fff;
}

.button-link--outline:hover {
  background: #f5f3ed;
}

.button-ghost {
  border: 1px solid #d3cebf;
  background: transparent;
  color: #51493a;
}

.button-ghost:hover {
  background: #f5f3ed;
}

.auth-card {
  max-width: 600px;
}

.auth-grid {
  margin-bottom: 16px;
}

button.secondary {
  background: #efefef;
  color: #333;
  border: 1px solid #d7d7d7;
}

button.secondary:hover {
  background: #dfdfdf;
}

.page-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}


body.auth-pending main {
  visibility: hidden;
}
