/* ======================================================================
   PIPELINE — the owner's Requests screen (js/screens/requestsPipeline.js)
   and the quotation studio modal (js/screens/quoteStudio.js).

     .pipe-toolbar   view toggle + stage chips
     .kanban         four stage columns of .lead-card
     .leads-table    the same leads as rows
     .drawer         the contractor / request slideout
     .qmodal         the two-pane quotation studio
     .quote-doc      the printable document (also the live preview)
   ====================================================================== */
:root {
  --stage-new: #f59e0b;
  --stage-quoted: #2563eb;
  --stage-booked: #16a34a;
  --stage-closed: #9ca3af;
  --wa: #22c55e;
}

.pipe { padding: 10px 16px 24px; }
.pipe-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.pipe-toolbar .chips { flex: 1; }
.seg-toggle { display: inline-flex; border: 1px solid var(--color-divider); border-radius: 6px; overflow: hidden; background: #fff; }
.seg-toggle button {
  border: 0; background: transparent; padding: 7px 12px; cursor: pointer; font-family: var(--font-heading);
  font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--color-neutral-700);
}
.seg-toggle button + button { border-left: 1px solid var(--color-divider); }
.seg-toggle button.on { background: var(--steel-900); color: var(--brand-300); }

/* ---- Kanban ---------------------------------------------------------------- */
.kanban { display: grid; gap: 12px; grid-template-columns: 1fr; }
.kanban-col {
  background: var(--color-neutral-100); border: 1px solid var(--color-divider); border-radius: 8px;
  padding: 10px; min-height: 120px; display: flex; flex-direction: column; gap: 10px;
}
.kanban-col.is-over { outline: 2px dashed var(--brand-500); outline-offset: -4px; background: var(--brand-100); }
.kanban-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px; border-bottom: 3px solid var(--color-divider); }
.kanban-col[data-stage="new"] .kanban-head { border-color: var(--stage-new); }
.kanban-col[data-stage="quoted"] .kanban-head { border-color: var(--stage-quoted); }
.kanban-col[data-stage="booked"] .kanban-head { border-color: var(--stage-booked); }
.kanban-col[data-stage="closed"] .kanban-head { border-color: var(--stage-closed); }
.kanban-head h2 { margin: 0; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.kanban-count { margin-left: auto; font-size: 12px; background: #fff; border: 1px solid var(--color-divider); border-radius: 999px; padding: 1px 8px; }
.kanban-empty { font-size: 12px; color: var(--color-neutral-600); padding: 10px 4px; }

.lead-card { background: #fff; border: 1px solid var(--color-divider); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 7px; cursor: grab; }
.lead-card:active { cursor: grabbing; }
.lead-card.dragging { opacity: .5; }
.lead-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lead-company { font-family: var(--font-heading); font-weight: 600; font-size: 15px; line-height: 1.15; }
.lead-verified { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; color: var(--brand-700); background: var(--brand-100); border: 1px solid var(--brand-300); padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.lead-urgent { font-size: 10.5px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.lead-machine { display: flex; align-items: center; gap: 8px; }
.lead-thumb { width: 52px; height: 36px; border-radius: 4px; object-fit: cover; border: 1px solid var(--color-divider); background: var(--color-neutral-100); flex: none; display: grid; place-items: center; color: var(--color-neutral-500); }
.lead-thumb svg { width: 60%; }
.lead-machine b { font-size: 13px; }
.lead-machine small { display: block; font-size: 11px; color: var(--color-neutral-600); }
.lead-conflict { font-size: 11.5px; color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; padding: 4px 8px; border-radius: 6px; }
.lead-scope { display: flex; flex-wrap: wrap; gap: 4px; }
.lead-scope span { font-size: 11px; background: var(--color-neutral-100); border: 1px solid var(--color-divider); padding: 2px 7px; border-radius: 3px; color: var(--color-neutral-800); }
.lead-scope .scope-pass { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.lead-msg { font-size: 12px; color: var(--color-neutral-700); line-height: 1.4; }
.lead-estimate { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--color-neutral-700); border-top: 1px dashed var(--color-divider); padding-top: 6px; }
.lead-estimate b { font-family: var(--font-heading); font-size: 15px; color: var(--steel-900); }
.lead-meta { font-size: 11px; color: var(--color-neutral-600); }
.lead-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lead-actions .btn { min-height: 32px; font-size: 11.5px; padding: 2px 10px; letter-spacing: .04em; gap: 5px; }
.lead-actions .btn svg { width: 14px; height: 14px; }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; font-weight: 700; }
.btn-wa:hover { background: #16a34a; }
.stage-select { font: inherit; font-size: 12px; padding: 5px 26px 5px 9px; border: 1px solid var(--color-divider); border-radius: 999px; background: #fff; cursor: pointer; min-height: 32px; }
.stage-select[data-stage="new"] { border-color: var(--stage-new); color: #92400e; }
.stage-select[data-stage="quoted"] { border-color: var(--stage-quoted); color: #1d4ed8; }
.stage-select[data-stage="booked"] { border-color: var(--stage-booked); color: #15803d; }
.stage-select[data-stage="closed"] { color: var(--color-neutral-600); }

/* ---- Table ----------------------------------------------------------------- */
.leads-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--color-divider); border-radius: 8px; overflow: hidden; }
.leads-table th { text-align: left; font-family: var(--font-heading); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--color-neutral-600); padding: 8px 10px; border-bottom: 1px solid var(--color-divider); background: var(--color-neutral-100); }
.leads-table td { padding: 10px; border-bottom: 1px solid var(--color-divider); vertical-align: top; font-size: 12.5px; }
.leads-table tr:last-child td { border-bottom: 0; }

/* ---- Drawer ---------------------------------------------------------------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgb(20 24 29 / 45%); z-index: 70; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); z-index: 71; background: #fff;
  box-shadow: -8px 0 30px rgb(15 23 42 / 18%); display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--color-divider); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-close { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--color-neutral-600); }
.drawer-body { overflow: auto; padding: 14px 18px 24px; display: grid; gap: 14px; }
.drawer-sec { border: 1px solid var(--color-divider); border-radius: 8px; padding: 12px 14px; }
.drawer-sec h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--color-neutral-600); }
.drawer-sec .kv { font-size: 13px; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.drawer-actions .btn { min-height: 40px; font-size: 13px; gap: 6px; }
.drawer-actions .btn svg { width: 16px; height: 16px; }
.trn-ok { color: #15803d; } .trn-missing { color: var(--color-neutral-600); }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.doc-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.doc-kind { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; background: var(--color-neutral-100); border: 1px solid var(--color-divider); padding: 2px 6px; border-radius: 3px; }
.doc-item a { color: var(--brand-700); text-decoration: underline; }
.notes-area { width: 100%; min-height: 90px; font: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid var(--color-divider); border-radius: 6px; resize: vertical; }
.notes-foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; color: var(--color-neutral-600); }
.route-line { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; margin-top: 8px; align-items: center; }
.quote-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.quote-history li { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; border-bottom: 1px solid var(--color-divider); padding-bottom: 6px; }
.quote-history li:last-child { border-bottom: 0; }

/* ---- Quotation studio modal ----------------------------------------------- */
.qmodal-backdrop { position: fixed; inset: 0; background: rgb(20 24 29 / 55%); z-index: 80; }
.qmodal {
  position: fixed; inset: 0; z-index: 81; background: #fff; display: flex; flex-direction: column;
}
.qmodal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--color-divider); }
.qmodal-head h2 { margin: 0; font-size: 18px; }
.qmodal-head small { display: block; font-size: 11.5px; color: var(--color-neutral-600); }
.qmodal-body { flex: 1; overflow: auto; display: grid; gap: 14px; padding: 14px 18px; }
.qpane { display: grid; gap: 12px; align-content: start; }
.qcard { border: 1px solid var(--color-divider); border-radius: 8px; padding: 12px 14px; background: #fff; }
.qcard h3 { margin: 0 0 10px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--steel-900); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qgrid .field-wide { grid-column: 1 / -1; }
.qcard .input { min-height: 36px; font-size: 13px; background: #fff; }
.qcard label { font-size: 11.5px; color: var(--color-neutral-700); display: block; margin-bottom: 4px; }
.qtoggle { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; cursor: pointer; }
.qtoggle input { width: 16px; height: 16px; accent-color: var(--brand-500); margin: 0; }
.qtotals { display: grid; gap: 4px; font-size: 13px; }
.qtotals div { display: flex; justify-content: space-between; }
.qtotals .grand { font-family: var(--font-heading); font-size: 17px; border-top: 1px solid var(--color-divider); padding-top: 6px; margin-top: 2px; }

.term { border: 1px solid var(--color-divider); border-radius: 8px; padding: 10px 12px; }
.term.off { opacity: .55; }
.term-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.term-head b { font-size: 13px; }
.term-switch { position: relative; width: 40px; height: 22px; flex: none; }
.term-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.term-switch span { position: absolute; inset: 0; background: var(--color-neutral-400); border-radius: 999px; cursor: pointer; transition: background .15s; }
.term-switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.term-switch input:checked + span { background: var(--brand-500); }
.term-switch input:checked + span::after { transform: translateX(18px); }
.term-vars { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: end; }
.term-vars label { font-size: 11px; color: var(--color-neutral-700); display: flex; flex-direction: column; gap: 3px; }
.term-vars .input { min-height: 32px; font-size: 12.5px; width: 92px; padding: 4px 8px; }
.term-vars select.input { width: auto; max-width: 100%; }
.term-vars .wide { width: 100%; }
.term-vars .wide select { width: 100%; }
.term-text { font-size: 12px; color: var(--color-neutral-700); margin-top: 8px; line-height: 1.45; }
.pill-set { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }

.qpreview { border: 1px solid var(--color-divider); border-radius: 8px; background: var(--color-neutral-100); padding: 14px; }
.qpreview-tabs { display: inline-flex; border: 1px solid var(--color-divider); border-radius: 6px; overflow: hidden; background: #fff; margin-bottom: 10px; }
.qpreview-tabs button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-family: var(--font-heading); font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--color-neutral-700); }
.qpreview-tabs button + button { border-left: 1px solid var(--color-divider); }
.qpreview-tabs button.on { background: var(--steel-900); color: var(--brand-300); }
.qpaper { background: #fff; border: 1px solid var(--color-divider); padding: 18px; box-shadow: 0 1px 3px rgb(15 23 42 / 8%); }
.qwa { white-space: pre-wrap; font-size: 12.5px; line-height: 1.5; background: #e7fbe9; border: 1px solid #bbf7d0; border-radius: 10px; padding: 12px 14px; font-family: var(--font-body); }
.qmodal-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 18px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--color-divider); background: #fff; }
.qmodal-foot .btn { min-height: 42px; font-size: 13px; gap: 6px; }
.qmodal-foot .btn svg { width: 16px; height: 16px; }
.qmodal-foot .spacer { flex: 1; }
.qmodal-foot .qsaved { font-size: 11.5px; color: var(--color-neutral-600); }

/* The printable document, as previewed (print CSS lives in quote.js). */
.quote-doc { font-size: 11.5px; line-height: 1.45; color: #111827; }
.quote-doc .qd-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #111827; padding-bottom: 10px; }
.quote-doc .qd-brand { font-size: 17px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-family: var(--font-heading); }
.quote-doc .qd-sub { font-size: 10.5px; color: #4b5563; margin-top: 2px; }
.quote-doc .qd-meta { text-align: right; font-size: 11px; }
.quote-doc .qd-title { font-size: 14px; font-weight: 700; letter-spacing: .12em; margin-bottom: 4px; font-family: var(--font-heading); }
.quote-doc .qd-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 12px 0; }
.quote-doc .qd-label { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #6b7280; margin-bottom: 3px; }
.quote-doc .qd-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.quote-doc .qd-table th, .quote-doc .qd-table td { border: 1px solid #d1d5db; padding: 6px 8px; text-align: left; }
.quote-doc .qd-table th { background: #f3f4f6; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
.quote-doc .qd-table .num { text-align: right; white-space: nowrap; }
.quote-doc .qd-table tfoot td { font-weight: 600; }
.quote-doc .qd-total td { background: #fef3c7; font-size: 13px; }
.quote-doc .qd-terms { margin-top: 14px; }
.quote-doc .qd-terms ol { margin: 4px 0 0; padding-left: 18px; }
.quote-doc .qd-terms li { margin-bottom: 4px; }
.quote-doc .qd-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 26px; font-size: 11px; }
.quote-doc .qd-line { border-top: 1px solid #111827; height: 30px; margin-top: 26px; }
.quote-doc .qd-foot { margin-top: 18px; font-size: 10px; color: #6b7280; text-align: center; border-top: 1px solid #e5e7eb; padding-top: 6px; }

/* ---- Layout ---------------------------------------------------------------- */
@media (min-width: 900px) {
  .kanban { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .pipe { max-width: var(--content-max); margin: 0 auto; width: 100%; padding: 14px var(--content-gutter) 40px; }
  .qmodal { inset: 24px; border-radius: 10px; overflow: hidden; }
  .qmodal-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .qpreview { position: sticky; top: 0; align-self: start; max-height: calc(100vh - 220px); overflow: auto; }
}
