/* ---------------------------------------------------------------------------
   Quote template pages and tool (/quote-template, /quote-template/<trade>).
   Layout from docs/quote-generator/wireframe.md. Builds on style.css: its
   colour tokens, .btn, .form-field, .form-hint, .form-error and the
   .dialog-* confirm dialog. The preview's own styles (.qp) come from
   quote-core's QUOTE_PREVIEW_CSS, injected by the tool.
   --------------------------------------------------------------------------- */

/* The Inter subset embedded in the PDF (packages/quote-fonts), so the preview
   matches it. Copied into dist/fonts/ by build.mjs. */
@font-face { font-family: Inter; src: url("/fonts/Inter-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: Inter; src: url("/fonts/Inter-SemiBold.ttf") format("truetype"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: Inter; src: url("/fonts/Inter-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: Inter; src: url("/fonts/Inter-SemiBoldItalic.ttf") format("truetype"); font-weight: 600; font-style: italic; font-display: swap; }

.quote-page {
  padding: 32px 0 64px;
}

/* Wider than the site's 1100 px, so the form and preview halves leave each
   section room for a one-row line from about 1280 px screens up. The header
   and footer widen with it, so their edges line up with the tool's. */
.quote-template .container {
  max-width: 1360px;
}

.quote-page h1 {
  font-size: 2rem;
  line-height: 1.2;
  color: var(--on-surface);
  margin-bottom: 16px;
}

/* !important so the site's own field rules (.form-field input { width: 100% })
   can't make a hidden element take up space. */
.qt-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* The hidden attribute always wins, even over .btn { display: inline-flex }. */
.qt [hidden] {
  display: none !important;
}

/* --- Toolbar --- */

.qt-toolbar {
  position: sticky;
  top: var(--qt-header-height, 0px);
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 12px 0;
  background: var(--background);
  border-bottom: 1px solid var(--outline-variant);
}

.qt-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
}

.qt-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Under the toolbar: what happens to the data, and a way to remove it. */
/* A small amber card (the site's secondary container), centred under the toolbar. */
.qt-privacy {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 8px;
  width: fit-content;
  max-width: 100%;
  margin: 12px auto 0;
  padding: 8px 16px;
  border-radius: 12px;
  background: var(--secondary-container);
  font-size: 0.85rem;
  color: var(--on-surface);
  text-align: center;
}

.qt-privacy .qt-icon {
  width: 16px;
  height: 16px;
}

/* A button, since it acts, styled as a text link. */
.qt-privacy-remove {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

/* Example rates are illustrative, not price guidance (PLAN.md, "Rates"). */
.qt-example-note {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--secondary-container);
  color: var(--on-surface);
  font-size: 0.9rem;
}

.qt-setting {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--on-surface-variant);
}

.qt select,
.qt-field textarea,
.qt-field select,
.qt-lines input,
.qt-lines textarea,
.qt-section-name {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--outline);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--on-surface);
}

/* Our own arrow, as on the dashboard's invite form (.invite-form select in
   style.css): the browser's arrow sits at a different spot in every browser. */
.qt select {
  padding-right: 36px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='%235f6368'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.qt-setting select {
  min-width: 140px;
  max-width: 260px;
}

.qt select:focus,
.qt textarea:focus,
.qt input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-container);
}

.qt .has-error,
.qt .has-error:focus {
  border-color: var(--error);
}

.qt textarea {
  resize: vertical;
  line-height: 1.4;
}

.qt-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: none;
}

/* --- Body: form left, preview right --- */

.qt-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  margin-top: 24px;
}

/* Desktop: start level with the preview page, below the preview's heading. */
.qt-form {
  margin-top: 28px;
}

.qt-block {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.qt-block-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--on-surface-variant);
  margin-bottom: 16px;
}

.qt-field.form-field {
  margin-bottom: 16px;
}

.qt-field input {
  padding: 8px 12px;
  font-size: 0.95rem;
}

.qt-field .form-error,
.qt-cell .form-error {
  margin-top: 4px;
  font-size: 0.8rem;
}

.qt-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0 12px;
}

.qt-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.qt-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.qt-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--on-surface-variant);
  margin-bottom: 6px;
}

.qt-logo-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.qt-logo-thumb {
  max-width: 120px;
  max-height: 44px;
  object-fit: contain;
}

.qt-logo-hint {
  margin-top: 0;
}

.qt-file-button {
  cursor: pointer;
}

.qt-file-input:focus-visible + .qt-file-button {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.qt-form-end {
  text-align: right;
  margin-top: 8px;
}

/* --- Sections and lines --- */

.qt-section {
  container-type: inline-size;
  border: 1px solid var(--outline-variant);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.qt-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.qt-section-name {
  flex: 1;
  font-weight: 600;
}

.qt-line {
  display: grid;
  /* Every column fixed except the description, so the heading row lines up with the
     line rows (each is its own grid). The last holds three 28 px row buttons. */
  grid-template-columns: minmax(0, 1fr) 56px 60px 80px 88px;
  gap: 6px;
  align-items: start;
  padding: 6px 0;
  border-top: 1px solid var(--surface-variant);
}

.qt-line-head {
  border-top: 0;
  padding: 0 0 2px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--on-surface-variant);
}

.qt-lines input,
.qt-lines textarea {
  padding: 6px 8px;
  font-size: 0.9rem;
}

/* A heading over an input box starts where the box's text starts: the input's
   8 px padding plus its 1 px border. */
.qt-head-input {
  padding-left: 9px;
}

.qt textarea.qt-desc {
  min-height: 2.25em;
  overflow: hidden; /* grows with its text (tool.js) */
  resize: none;
}

.qt-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Typed numbers start at the left, under their left-aligned heading. */
.qt-lines input.qt-num {
  text-align: left;
}

.qt-cell-label {
  display: none;
}

.qt-row-actions {
  display: flex;
  gap: 2px;
}

.qt-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
}

.qt-icon-button:hover:not(:disabled) {
  background: var(--surface-variant);
}

.qt-icon-button:focus-visible {
  outline: 2px solid var(--primary);
}

.qt-icon-button:disabled {
  opacity: 0.3;
  cursor: default;
}

.qt-add-line {
  padding-left: 0;
  margin-top: 4px;
}

.qt-subtotal {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--surface-variant);
  font-size: 0.9rem;
  color: var(--on-surface-variant);
}

.qt-subtotal-value {
  min-width: 92px;
  text-align: right;
  font-weight: 600;
  color: var(--on-surface);
  font-variant-numeric: tabular-nums;
}

.qt-add-section {
  margin-top: 4px;
}

/* --- Preview --- */

.qt-preview {
  position: sticky;
  top: calc(var(--qt-header-height, 0px) + var(--qt-toolbar-height, 0px) + 16px);
  max-height: calc(100vh - var(--qt-header-height, 0px) - var(--qt-toolbar-height, 0px) - 32px);
  overflow-y: auto;
  border-radius: 4px;
}

/* A fixed height, so the form can start exactly that much lower and its first
   box lines up with the top of the preview page. */
.qt-preview-title {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  height: 20px;
  line-height: 20px;
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}

.qt-preview-title span {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* At full size (wide screens) the page is narrower than its column: centre it,
   so the centred heading sits over it. */
.qt-preview-frame {
  overflow: hidden;
  max-width: 595px;
  margin: 0 auto;
}

.qt-preview-page {
  width: 595px;
  transform-origin: top left;
}

.qt-preview-page .qp {
  border: 1px solid var(--outline-variant);
}

/* --- Mobile: Edit / Preview tabs, bottom bar --- */

.qt-tabs,
.qt-bottom-bar {
  display: none;
}

@media (max-width: 999px) {
  .qt-toolbar {
    position: static;
    border-bottom: 0;
  }

  /* Phones download from the bottom bar. */
  .qt-download-top {
    display: none;
  }

  .qt-tabs {
    position: sticky;
    top: var(--qt-header-height, 0px);
    z-index: 50;
    display: flex;
    background: var(--background);
    border-bottom: 1px solid var(--outline-variant);
  }

  .qt-tab {
    flex: 1;
    padding: 12px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    font: inherit;
    font-weight: 500;
    color: var(--on-surface-variant);
    cursor: pointer;
  }

  .qt-tab[aria-selected="true"] {
    color: var(--primary);
    border-bottom-color: var(--primary);
  }

  .qt-body {
    grid-template-columns: minmax(0, 1fr);
    margin-top: 16px;
  }

  .qt[data-tab="edit"] .qt-preview,
  .qt[data-tab="preview"] .qt-form {
    display: none;
  }

  .qt-preview {
    position: static;
    max-height: none;
  }

  /* The Preview tab already says what this is, so no heading and no offset. */
  .qt-preview-title {
    display: none;
  }

  .qt-form {
    margin-top: 0;
  }

  .qt-form-end {
    display: none;
  }

  .qt-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--outline-variant);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  }

  .qt-bottom-total {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }

  .quote-page {
    padding-bottom: 96px;
  }

  .qt-section-head {
    flex-wrap: wrap;
  }

  /* Three nested boxes (block, section, line) leave little room on a phone. */
  .qt-block {
    padding: 16px 12px;
  }

  .qt-section {
    padding: 8px;
  }
}

@container (max-width: 520px) {
  /* In a narrow section (phones, narrow windows) each line becomes a small card. */
  .qt-line-head {
    display: none;
  }

  .qt-line {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "desc desc"
      "qty unit"
      "rate actions";
    gap: 8px 12px;
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--surface-variant);
    border-radius: 8px;
  }

  .qt-cell-desc { grid-area: desc; }
  .qt-cell-qty { grid-area: qty; }
  .qt-cell-unit { grid-area: unit; }
  .qt-cell-rate { grid-area: rate; }
  .qt-cell-actions { grid-area: actions; align-self: end; }
  .qt-cell-actions .qt-row-actions { justify-content: flex-end; }

  .qt-cell-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--on-surface-variant);
    margin-bottom: 2px;
  }
}

/* --- Page copy around the tool --- */

/* Until the script builds the tool, its place keeps a screen's height, so the
   copy below starts off-screen instead of jumping down when the tool appears
   (layout shift; Lighthouse measured CLS 0.36–0.74 without this). */
#quote-tool {
  min-height: 100vh;
}

/* Links inside running text are underlined, not told apart by colour alone. */
.quote-intro a,
.quote-copy p a {
  text-decoration: underline;
}

/* The intro under the H1, in the guides' lead style. */
.quote-intro {
  max-width: 820px;
  margin-bottom: 8px;
}

.quote-intro p {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--on-background);
  margin-bottom: 12px;
}

/* The copy below the tool uses the guide pages' article styles (.guide-page in
   style.css) in their 700 px column; the quote pages' wider container would
   otherwise stretch it. */
.quote-template .quote-copy .container {
  max-width: 700px;
}

.quote-copy {
  padding-top: 24px;
}

.quote-faq-item h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--on-background);
  margin: 20px 0 4px;
}

.quote-related ul {
  list-style: none;
  padding-left: 0;
}

.quote-related li {
  margin-bottom: 6px;
}

.quote-copy .guide-product {
  margin-top: 40px;
}

/* --- Hub: a card per trade --- */

.quote-cards {
  margin-top: 40px;
}

.quote-cards h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--on-background);
  margin-bottom: 16px;
}

.quote-cards ul {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); /* 3 across on desktop */
  gap: 12px;
}

.quote-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  font-weight: 600;
  color: var(--primary);
}

.quote-card:hover {
  border-color: var(--primary);
  text-decoration: none;
}

.quote-card-sub {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--on-surface-variant);
}

.quote-missing {
  margin-top: 24px;
}
