:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #6b6a65;
  --paper: #f4f1e9;
  --surface: #fffefa;
  --line: #d7d2c6;
  --line-strong: #aaa397;
  --signal: #cf3f24;
  --signal-dark: #9f2e19;
  --success: #146c43;
  --error: #a3291f;
  --shadow: 0 18px 50px rgba(44, 39, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(21, 21, 21, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 32px;
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  font-size: 16px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.page-shell {
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 80px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}

.page-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line-strong);
}

.page-tab {
  position: relative;
  min-height: 54px;
  padding: 12px 18px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  text-align: center;
}

.page-tab::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 3px;
  background: transparent;
  content: "";
}

.page-tab:hover,
.page-tab:focus-visible {
  color: var(--ink);
}

.page-tab.is-active {
  color: var(--ink);
}

.page-tab.is-active::after {
  background: var(--signal);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--signal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -0.035em;
}

h1 {
  font-size: clamp(38px, 6vw, 64px);
  line-height: 0.95;
}

h2 {
  font-size: 32px;
}

h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.connection::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
  content: "";
}

.connection.is-connected::before {
  background: var(--success);
}

.connection.is-error::before {
  background: var(--error);
}

.notice {
  margin-bottom: 18px;
  padding: 13px 16px;
  border: 1px solid var(--line-strong);
  background: #fffaf0;
  line-height: 1.45;
}

.notice.is-error {
  border-color: #d7a49e;
  background: #fff4f2;
  color: var(--error);
}

.notice.is-success {
  border-color: #8cbda5;
  background: #eff9f4;
  color: var(--success);
}

.offer-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(280px, 1.1fr);
  gap: 28px;
  align-items: end;
  margin-bottom: 18px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  background: rgba(255, 254, 250, 0.72);
}

.offer-panel h2 {
  margin-bottom: 7px;
  font-size: 27px;
}

.offer-panel > div > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.offer-search-field {
  z-index: 20;
}

.offer-search-field .customer-results {
  top: calc(100% + 4px);
}

.workflow-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 16px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.workflow-separator::before,
.workflow-separator::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.workflow-heading {
  margin-bottom: 14px;
}

.workflow-heading h2 {
  font-size: 28px;
}

.work-area {
  display: grid;
  grid-template-columns: minmax(0, 760px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

form,
.preview-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

form {
  padding: 30px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 18px;
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset:disabled {
  opacity: 0.58;
}

.field {
  position: relative;
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.025em;
}

.optional {
  color: var(--muted);
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  outline: 0;
  background: #fff;
  color: var(--ink);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input,
select {
  height: 48px;
  padding: 0 13px;
}

textarea {
  min-height: 112px;
  padding: 13px;
  line-height: 1.5;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(21, 21, 21, 0.08);
}

input::placeholder,
textarea::placeholder {
  color: #969188;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  padding-right: 44px;
}

.search-mark {
  position: absolute;
  top: 50%;
  right: 14px;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 26px;
  transform: translateY(-54%);
  pointer-events: none;
}

.customer-results {
  position: absolute;
  z-index: 10;
  top: calc(100% - 18px);
  right: 0;
  left: 0;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--ink);
  background: #fff;
  box-shadow: 0 16px 28px rgba(21, 21, 21, 0.14);
}

.customer-option {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.customer-option:last-child {
  border-bottom: 0;
}

.customer-option:hover,
.customer-option:focus {
  outline: 0;
  background: var(--paper);
}

.customer-option strong,
.customer-option span {
  display: block;
}

.customer-option strong {
  margin-bottom: 3px;
}

.customer-option span,
.empty-result {
  color: var(--muted);
  font-size: 12px;
}

.empty-result {
  margin: 0;
  padding: 14px;
}

.invoice-items-section {
  min-width: 0;
}

.invoice-items-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 13px;
}

.invoice-items-heading > span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  text-transform: uppercase;
}

#invoiceItems,
#offerPriceItems {
  display: grid;
  gap: 12px;
}

.offer-content {
  min-height: 420px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.offer-price-item {
  padding: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.offer-price-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.offer-price-item-fields {
  display: grid;
  grid-template-columns:
    minmax(260px, 2.5fr)
    minmax(64px, 0.55fr)
    minmax(90px, 0.8fr)
    minmax(120px, 1fr)
    minmax(72px, 0.65fr);
  gap: 9px;
}

.offer-price-item-fields label {
  font-size: 10px;
}

.invoice-item {
  position: relative;
  padding: 17px;
  border: 1px solid var(--line);
  background: #fff;
}

.invoice-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 13px;
}

.invoice-item-number {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.remove-item-button {
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.remove-item-button:hover {
  color: var(--error);
}

.invoice-item textarea {
  min-height: 82px;
}

.invoice-item-fields {
  display: grid;
  grid-template-columns: 0.8fr 1fr 1.2fr 0.8fr;
  gap: 10px;
  margin-top: 12px;
}

.invoice-item-fields label {
  font-size: 11px;
}

.invoice-item-total {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
}

.invoice-item-total strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.add-item-button {
  width: 100%;
  margin-top: 10px;
  border-style: dashed;
}

.field-hint,
.submit-hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.input-suffix {
  position: relative;
}

.input-suffix input {
  padding-right: 52px;
}

.input-suffix span {
  position: absolute;
  top: 50%;
  right: 13px;
  color: var(--muted);
  font-size: 13px;
  transform: translateY(-50%);
  pointer-events: none;
}

.calculation {
  margin: 28px 0 20px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.calculation > div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.calculation strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.calculation .calculation-total {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--ink);
  font-size: 16px;
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 11px 17px;
  border: 1px solid transparent;
  border-radius: 0;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.button-primary {
  width: 100%;
  background: var(--signal);
  color: #fff;
}

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

.button-secondary {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--paper);
}

.button-send {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.button-send:hover:not(:disabled) {
  background: #383632;
}

.preview-panel {
  position: sticky;
  top: 22px;
  padding: 22px;
}

.preview-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.draft-label {
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.draft-label.is-final {
  border-color: var(--success);
  color: var(--success);
}

.pdf-frame-wrap {
  position: relative;
  height: 520px;
  border: 1px solid var(--line);
  background: var(--paper);
}

#pdfFrame,
#offerPdfFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.pdf-loading {
  position: absolute;
  inset: 50% auto auto 50%;
  margin: 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  transform: translate(-50%, -50%);
}

.preview-actions {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.send-dialog {
  width: min(560px, calc(100% - 28px));
  max-height: calc(100vh - 36px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(21, 21, 21, 0.28);
}

.send-dialog::backdrop {
  background: rgba(21, 21, 21, 0.64);
  backdrop-filter: blur(2px);
}

.send-dialog-form {
  padding: 28px;
  border: 0;
  box-shadow: none;
}

.send-dialog-head {
  margin-bottom: 24px;
}

.send-dialog-head h2 {
  margin-bottom: 10px;
}

.send-dialog-head > p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.send-dialog-form .field + .field {
  margin-top: 18px;
}

.send-dialog-warning {
  margin-top: 20px;
  padding: 11px 13px;
  border-left: 3px solid var(--signal);
  background: #fff3ef;
  color: var(--signal-dark);
  font-size: 13px;
  line-height: 1.45;
}

.send-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 10px;
  margin-top: 22px;
}

.send-dialog-actions .button {
  width: 100%;
}

.offer-confirmation {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 14px;
}

.offer-confirmation dt {
  color: var(--muted);
}

.offer-confirmation dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1180px) {
  .offer-panel,
  .work-area {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 24px, 1120px);
    padding-top: 30px;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  form,
  .preview-panel {
    padding: 20px;
  }

  fieldset {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .pdf-frame-wrap {
    height: 430px;
  }

  .send-dialog-form {
    padding: 21px;
  }

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

  .invoice-item-fields {
    grid-template-columns: 1fr 1fr;
  }

  .offer-price-item-fields {
    grid-template-columns: 1fr 1fr;
  }

  .offer-price-description {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

.page-header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-identity {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.auth-signout {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-signout:hover {
  color: var(--ink);
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(21, 21, 21, 0.55);
}

.auth-gate[hidden] {
  display: none;
}

.auth-gate-card {
  width: min(420px, 100%);
  padding: 34px 32px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-gate-card h2 {
  margin: 8px 0 12px;
  font-size: 24px;
}

.auth-gate-message {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.5;
}
