/* Start a change order and Print / PDF from a work order — the office side
   (Work Orders 1.29, B8 and B9).
   js/service-ticket-co.js paints the CO chip, the Change orders list, the
   Start change order buttons and the "Start a change order" dialog.
   js/service-ticket-print.js paints the Print / PDF menu and the Completion
   report dialog (the print windows carry their own styles).
   .p86-co-from-wo is the "From work order" card in the change order editor.
   Tokens and fallbacks match css/styles.css. */

/* ── the CO chip (row head and beside the status) ────────────────────────── */
.p86-st-co-chip {
  display: inline-block; flex: 0 0 auto; vertical-align: middle;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px; line-height: 1.4;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border, #333); color: var(--text-dim, #aaa);
}
.p86-st-co-chip.is-draft { color: var(--purple, #8b5cf6); border-color: var(--purple, #8b5cf6); background: rgba(139, 92, 246, 0.10); }
.p86-st-co-chip.is-approved { color: var(--green, #059669); border-color: var(--green, #059669); background: rgba(5, 150, 105, 0.10); }
.p86-st-statusctl + .p86-st-co-chip,
.p86-st-meta-v .p86-st-co-chip { margin-left: 6px; }

/* ── the Change orders list ─────────────────────────────────────────────── */
.p86-st-cos { margin: 4px 0 10px; }
.p86-st-co-note {
  text-transform: none; letter-spacing: 0; font-weight: 400;
  color: var(--text-dim, #888); margin-left: 6px;
}
.p86-st-co-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  border: 1px solid var(--border, #333); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 6px;
  background: var(--surface2, rgba(255, 255, 255, 0.03));
  font-size: 12.5px; color: var(--text, #fff);
}
.p86-st-co-num { font-weight: 700; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.p86-st-co-title { flex: 1 1 160px; min-width: 0; overflow-wrap: anywhere; }
.p86-st-co-state {
  flex: 0 0 auto; font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  padding: 1px 7px; border-radius: 999px;
  color: var(--text-dim, #aaa); border: 1px solid var(--border, #333);
}
.p86-st-co-state.is-draft { color: var(--purple, #8b5cf6); border-color: var(--purple, #8b5cf6); }
.p86-st-co-state.is-approved,
.p86-st-co-state.is-applied { color: var(--green, #059669); border-color: var(--green, #059669); }
.p86-st-co-row .p86-st-co-open { flex: 0 0 auto; padding: 4px 10px; font-size: 12px; }

/* ── Start change order on a suggestion, a building note or a problem ───── */
.p86-st-co-srcwrap { margin-top: 6px; }
.p86-st-co-src {
  display: inline-flex; align-items: center; gap: 4px;
  font: inherit; font-size: 11.5px; font-weight: 600; line-height: 1.3;
  padding: 3px 9px; margin: 0 0 0 6px; border-radius: 999px; cursor: pointer;
  color: var(--accent, #4f8cff); background: transparent;
  border: 1px solid var(--accent, #4f8cff);
}
.p86-st-co-srcwrap .p86-st-co-src { margin-left: 0; }
.p86-st-co-src:hover { background: rgba(79, 140, 255, 0.10); }
.p86-st-co-src.is-linked {
  color: var(--purple, #8b5cf6); border-color: var(--purple, #8b5cf6);
}
span.p86-st-co-src.is-linked { cursor: default; }

/* ── the "Start a change order" dialog ─────────────────────────────────── */
.p86-st-co-modal { width: min(640px, 100%); }
.p86-st-co-sub { font-size: 12.5px; color: var(--text-dim, #999); line-height: 1.45; margin-bottom: 4px; }
.p86-st-co-modal input[type="number"],
.p86-st-co-modal input[type="text"],
.p86-st-co-modal textarea {
  width: 100%; background: var(--input-bg, #101014); color: var(--text, #fff);
  border: 1px solid var(--border, #333); border-radius: 6px;
  padding: 8px 10px; font-size: 13px; font-family: inherit;
}
.p86-st-co-help { font-size: 11.5px; color: var(--text-dim, #888); margin: -2px 0 8px; }
.p86-st-co-empty { font-size: 12.5px; color: var(--text-dim, #888); font-style: italic; }
.p86-st-co-group { margin-bottom: 10px; }
.p86-st-co-group-head { font-size: 12px; font-weight: 600; color: var(--text, #fff); margin-bottom: 5px; }
.p86-st-co-photos { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.p86-st-co-photo {
  position: relative; display: block; aspect-ratio: 1 / 1; max-width: 100%;
  border-radius: 6px; overflow: hidden; cursor: pointer;
  border: 2px solid var(--border, #333); background: var(--surface2, rgba(255, 255, 255, 0.04));
}
.p86-st-co-photo.is-on { border-color: var(--accent, #4f8cff); }
.p86-st-co-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.p86-st-co-photo input {
  position: absolute; top: 5px; left: 5px; z-index: 1;
  width: 18px; height: 18px; margin: 0; accent-color: var(--accent, #4f8cff);
}
.p86-st-co-nothumb {
  display: flex; align-items: center; justify-content: center; height: 100%;
  font-size: 11px; color: var(--text-dim, #888);
}
.p86-st-co-err,
.p86-st-cr-err {
  margin-top: 10px; padding: 8px 10px; border-radius: 6px; font-size: 12.5px;
  color: var(--red, #dc2626); border: 1px solid var(--red, #dc2626); background: rgba(220, 38, 38, 0.08);
}
.p86-st-co-dupe {
  margin-top: 10px; padding: 9px 11px; border-radius: 6px; font-size: 12.5px;
  color: var(--text, #fff); border: 1px solid var(--yellow, #d97706); background: rgba(217, 119, 6, 0.10);
}
.p86-st-co-dupe-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ── Print / PDF menu ─────────────────────────────────────────────────────── */
.p86-st-print-wrap { position: relative; display: inline-flex; }
.p86-st-print-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 60;
  min-width: 260px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: var(--panel-bg, #141419); border: 1px solid var(--border, #333);
  border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.p86-st-print-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  font: inherit; font-size: 13px; line-height: 1.35;
  padding: 8px 10px; border: 0; border-radius: 6px;
  color: var(--text, #fff); background: transparent;
}
.p86-st-print-item:hover,
.p86-st-print-item:focus-visible { background: var(--surface2, rgba(255, 255, 255, 0.06)); outline: none; }
.p86-st-print-name { font-weight: 600; }
.p86-st-print-hint { color: var(--text-dim, #999); }

/* ── the Completion report dialog ─────────────────────────────────────────── */
.p86-st-cr-modal { width: min(620px, 100%); }
.p86-st-cr-title { font-size: 13px; color: var(--text-dim, #999); margin-bottom: 8px; overflow-wrap: anywhere; }
.p86-st-cr-status { font-size: 13px; color: var(--text, #fff); line-height: 1.45; margin-bottom: 6px; }
.p86-st-cr-status:not(.is-approved) { color: var(--yellow, #d97706); }
.p86-st-cr-counts { font-size: 12.5px; color: var(--text, #fff); }
.p86-st-cr-missing { font-size: 12.5px; color: var(--yellow, #d97706); margin-top: 4px; }
.p86-st-cr-notes {
  display: flex; align-items: center; gap: 8px; margin: 10px 0 4px;
  font-size: 13px; color: var(--text, #fff); cursor: pointer;
}
.p86-st-cr-money {
  margin: 8px 0; padding: 7px 10px; border-radius: 6px; font-size: 12.5px;
  color: var(--text, #fff); border: 1px solid var(--yellow, #d97706); background: rgba(217, 119, 6, 0.10);
}
.p86-st-cr-printrow { margin: 10px 0 4px; }
.p86-st-cr-send { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border, #333); }
.p86-st-cr-sendrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.p86-st-cr-sendrow input,
.p86-st-cr-linkrow input {
  width: 100%; background: var(--input-bg, #101014); color: var(--text, #fff);
  border: 1px solid var(--border, #333); border-radius: 6px;
  padding: 7px 9px; font-size: 13px; font-family: inherit;
}
.p86-st-cr-sendacts { margin: 10px 0 2px; }
.p86-st-cr-sendacts .ee-btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.p86-st-cr-result {
  margin-top: 10px; padding: 9px 11px; border-radius: 6px;
  border: 1px solid var(--green, #059669); background: rgba(5, 150, 105, 0.08);
}
.p86-st-cr-result-line { font-size: 13px; color: var(--text, #fff); margin-bottom: 6px; }
.p86-st-cr-linkrow { display: flex; gap: 8px; align-items: center; }
.p86-st-cr-linkrow input { flex: 1 1 auto; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.p86-st-cr-shares { margin-top: 12px; }
.p86-st-cr-share {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 6px 0; border-bottom: 1px solid var(--border, #333);
  font-size: 12.5px; color: var(--text, #fff);
}
.p86-st-cr-share-text { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.p86-st-cr-share .p86-st-cr-revoke { flex: 0 0 auto; padding: 4px 10px; font-size: 12px; }

/* ── From work order, in the change order editor (js/change-order-editor.js) ── */
.p86-co-from-wo {
  border: 1px solid var(--border, #333); border-left: 3px solid var(--purple, #8b5cf6);
  border-radius: 8px; padding: 10px 12px; margin: 10px 0;
  background: var(--surface2, rgba(255, 255, 255, 0.03));
}
.p86-co-from-wo-lbl {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-dim, #888); margin-bottom: 4px;
}
.p86-co-from-wo-title { font-size: 13px; font-weight: 600; color: var(--text, #fff); overflow-wrap: anywhere; }
.p86-co-from-wo-thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin: 8px 0; }
.p86-co-from-wo-thumbs button {
  display: block; padding: 0; margin: 0; border: 0; border-radius: 4px; overflow: hidden;
  aspect-ratio: 1 / 1; max-width: 100%; cursor: zoom-in; background: var(--surface, #1a1a20);
}
.p86-co-from-wo-thumbs img { display: block; width: 100%; height: 100%; object-fit: cover; }
.p86-co-from-wo-more {
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--text-dim, #999);
  border: 1px dashed var(--border, #333); border-radius: 4px; aspect-ratio: 1 / 1;
}

/* ── phones ────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  #job-service-tickets .p86-st-actions .p86-st-print-wrap,
  #job-service-tickets .p86-st-actions .p86-st-co-start { flex: 1 1 0; min-width: 0; }
  #job-service-tickets .p86-st-actions .p86-st-print-wrap .ee-btn { flex: 1 1 auto; width: 100%; }
  .p86-st-print-menu { right: auto; left: 0; }
}
@media (max-width: 480px) {
  .p86-st-co-back, .p86-st-cr-back { padding: 16px; align-items: flex-start; }
  .p86-st-co-modal, .p86-st-cr-modal { width: 100%; padding: 16px; }
  .p86-st-co-photos { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .p86-st-cr-sendrow { grid-template-columns: 1fr; }
  .p86-st-cr-linkrow { flex-wrap: wrap; }
  .p86-st-co-row .p86-st-co-open { margin-left: auto; }
}
