/* ==========================================================================
   Tradevane customer pool — manual customer entry form.

   Three native fieldsets share one surface. Each contact occupies a row in
   the same editor, and the save action and its status sit in a sticky footer.
   V2 colours are scoped to #new-customer. Detail and customer-pool styles
   continue to use the workspace palette.

   Controls keep the conventions already defined for .tv-btn / .tv-input:
     fields            40px, 8px radius, brand focus ring (theme.css owns
                       field chrome; this layer only owns widths and rhythm)
     primary action    40px  --tv-control-h-lg
     dense actions     30px  --tv-control-h-sm (add contact, remove contact)
     focus             3px --tv-brand-ring halo on controls
     disabled          opacity .5, cursor not-allowed
   Labels and hints are 13px, fieldset legends 16px. No size in this file is
   below 13px. Every transition has a reduced-motion fallback at the end.

   Sections: 01 form shell · 02 fieldset groups · 03 labels and fields ·
             04 dense actions · 05 contact editor · 06 actions and status ·
             07 responsive · 08 reduced motion
   ========================================================================== */

/* ---- 01 form shell ------------------------------------------------------ */
#new-customer {
  --tv-surface: #fffefa;
  --tv-subtle: #f1f6f0;
  --tv-surface-hover: #edf6ef;
  --tv-border: #dce5de;
  --tv-border-strong: #a5bcb1;
  --tv-control-border: #899f96;
  --tv-text: #172d32;
  --tv-text-2: #365159;
  --tv-text-3: #526663;
  --tv-brand: #08695f;
  --tv-brand-hover: #064d47;
  --tv-brand-soft: #dff4f1;
  --tv-brand-ring: #08695f35;
  --manual-inset: clamp(14px, 2vw, 28px);
}

#new-customer .manual-customer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  width: min(100%, 1100px);
  max-width: none;
  min-width: 0;
  padding: var(--tv-s4) var(--manual-inset) var(--manual-inset);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius-lg);
  background: var(--tv-surface);
  box-shadow: none;
}

#new-customer .manual-customer-form :is(input, select, textarea, button) {
  scroll-margin-block: 76px 112px;
}

/* ---- 02 fieldset groups ------------------------------------------------- */
.manual-customer-block {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--tv-s3) var(--tv-s4);
  min-width: 0;
  margin: 0;
  padding: var(--tv-s3) 0 var(--tv-s5);
  border: 0;
}

.manual-customer-block + .manual-customer-block {
  margin-block-start: var(--tv-s2);
}

.manual-customer-block legend {
  width: 100%;
  padding: 0 0 var(--tv-s2);
  border-block-end: 1px solid var(--tv-border);
  color: var(--tv-text);
  font-size: var(--tv-fs-lg);
  font-weight: 650;
  line-height: 1.35;
}

.manual-customer-block label:has([required]:not(:disabled)) > span { color: var(--tv-text); }

.manual-customer-block .full-field { grid-column: 1 / -1; }
.manual-customer-block [hidden],
#customer-detail #managementInquiryField[hidden] { display: none; }

/* ---- 03 labels and fields ---------------------------------------------- */
.manual-customer-block label { display: grid; gap: var(--tv-s1); align-content: start; min-width: 0; color: var(--tv-text-2); font-size: var(--tv-fs-md); font-weight: 500; line-height: 1.4; }

.manual-customer-block label > span { color: var(--tv-text-2); font-size: var(--tv-fs-md); font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }

.manual-customer-block input,
.manual-customer-block select,
.manual-customer-block textarea { width: 100%; min-width: 0; box-sizing: border-box; }

.manual-customer-block textarea { min-height: 94px; resize: vertical; }

.manual-customer-block [name="inquiryText"] { min-height: 132px; }

/* ---- 04 dense actions --------------------------------------------------- */
.manual-customer-form .ghost.small-button,
.manual-customer-form .button.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--tv-control-h-sm);
  min-height: var(--tv-control-h-sm);
  padding: 0 var(--tv-s3);
  border-radius: var(--tv-radius-sm);
  font-size: var(--tv-fs-md);
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.manual-customer-form .ghost.small-button:hover { background: var(--tv-surface-hover); border-color: var(--tv-border-strong); color: var(--tv-text); }

.manual-customer-form .ghost.small-button:active { background: var(--tv-subtle); }

.manual-customer-form .ghost.small-button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.manual-customer-form .ghost.small-button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- 05 contact editor -------------------------------------------------- */
/* Legend row: contact heading on the left, the add action on the right. */
.contacts-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--tv-s2) var(--tv-s3);
}

.manual-contact-list { display: grid; grid-column: 1 / -1; min-width: 0; }

.manual-contact-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--tv-s2) var(--tv-s3);
  align-items: end;
  min-width: 0;
  padding: var(--tv-s2) 0;
}

.manual-contact-row + .manual-contact-row {
  margin-block-start: var(--tv-s2);
  padding-block-start: var(--tv-s3);
  border-block-start: 1px solid var(--tv-border);
}

.manual-contact-row label { display: grid; gap: var(--tv-s1); align-content: start; min-width: 0; color: var(--tv-text-2); font-size: var(--tv-fs-md); font-weight: 500; }

.manual-contact-row label > span { color: var(--tv-text-3); font-size: var(--tv-fs-md); font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }

.manual-contact-row input { width: 100%; min-width: 0; box-sizing: border-box; }

/* The primary-contact checkbox sits on the same 40px line as the fields. */
.manual-contact-row > .manual-contact-primary {
  display: flex;
  grid-column: 1 / -2;
  align-items: center;
  gap: var(--tv-s2);
  min-height: var(--tv-control-h-md);
  min-width: 0;
  color: var(--tv-text-2);
  font-size: var(--tv-fs-md);
  font-weight: 500;
}

.manual-contact-primary:has(input:checked) > span { color: var(--tv-brand); font-weight: 650; }

.manual-contact-row > .manual-contact-primary span { color: var(--tv-text-2); font-size: var(--tv-fs-md); font-weight: 500; }

.manual-contact-row > .manual-contact-primary input { flex: none; width: 16px; min-width: 16px; height: 16px; margin: 0; }

.manual-customer-form .ghost.manual-contact-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  grid-column: -2 / -1;
  height: var(--tv-control-h-sm);
  min-height: var(--tv-control-h-sm);
  padding: 0 var(--tv-s3);
  border-color: var(--tv-danger-border);
  border-radius: var(--tv-radius-sm);
  background: var(--tv-surface);
  color: var(--tv-danger);
  font-size: var(--tv-fs-md);
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.manual-customer-form .ghost.manual-contact-remove:hover { border-color: var(--tv-danger); background: var(--tv-danger-bg); color: var(--tv-danger); }

.manual-customer-form .ghost.manual-contact-remove:active { background: var(--tv-danger-bg); }

.manual-customer-form .ghost.manual-contact-remove:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.manual-customer-form .ghost.manual-contact-remove:disabled { opacity: .5; cursor: not-allowed; }

.detail-inquiry { display: flex; flex-direction: column; gap: var(--tv-s2); margin-top: var(--tv-s3); padding: var(--tv-s3); border: 1px solid var(--tv-info-border); border-radius: var(--tv-radius); background: var(--tv-info-bg); }

.detail-inquiry p { max-height: 220px; margin: 0; overflow: auto; color: var(--tv-text-2); font-size: var(--tv-fs-md); line-height: 1.65; white-space: pre-wrap; }

.pool-acquisition--inquiry { border-color: var(--tv-warning-border); background: var(--tv-warning-bg); color: var(--tv-warning); }

.pool-acquisition--search_discovery { border-color: var(--tv-info-border); background: var(--tv-info-bg); color: var(--tv-info); }

.customer-timeline-body { padding-block-start: var(--tv-s3); }
.customer-timeline-controls { display: flex; justify-content: flex-end; margin-block-end: var(--tv-s2); }
.customer-timeline-list {
  display: flex;
  flex-direction: column;
  gap: var(--tv-s1);
  max-block-size: min(62vh, 36rem);
  overflow-y: auto;
  scrollbar-gutter: stable;
}
.customer-timeline-list:focus-visible { outline-offset: -2px; }

.customer-timeline-event { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: var(--tv-s2); padding: var(--tv-s2) 0; }

.customer-timeline-event:not(:last-child)::before { content: ""; position: absolute; left: 8px; top: 28px; bottom: -10px; width: 1px; background: var(--tv-border); }

.customer-timeline-dot { width: 9px; height: 9px; margin: 6px 0 0 4px; border: 2px solid var(--tv-surface); border-radius: var(--tv-radius-full); background: var(--tv-brand); box-shadow: 0 0 0 1px var(--tv-brand); }

.customer-timeline-event--mail .customer-timeline-dot { background: var(--tv-info); box-shadow: 0 0 0 1px var(--tv-info); }

.customer-timeline-event--whatsapp .customer-timeline-dot { background: var(--tv-success); box-shadow: 0 0 0 1px var(--tv-success); }

.customer-timeline-event--research .customer-timeline-dot { background: var(--tv-warning); box-shadow: 0 0 0 1px var(--tv-warning); }

.customer-timeline-event header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--tv-s2); }

.customer-timeline-event header span { flex: 0 0 auto; color: var(--tv-text-3); font-size: var(--tv-fs-sm); }

.customer-timeline-event p { margin: 3px 0 0; color: var(--tv-text-2); font-size: var(--tv-fs-md); line-height: 1.55; overflow-wrap: anywhere; }

/* ---- 06 actions and status --------------------------------------------- */
.manual-customer-actions {
  position: sticky;
  inset-block-end: max(var(--tv-s3), env(safe-area-inset-bottom));
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--tv-s2) var(--tv-s4);
  min-width: 0;
  padding: var(--tv-s2) var(--tv-s3);
  border: 1px solid var(--tv-border-strong);
  border-radius: var(--tv-radius);
  background: #f8fbf4f5;
  box-shadow: 0 3px 7px #172d3212, 0 12px 28px -16px #172d3245;
}

.manual-customer-actions .button {
  grid-column: 2;
  grid-row: 1;
  background: var(--tv-brand);
  border-color: var(--tv-brand);
  color: var(--tv-on-brand);
  height: var(--tv-control-h-lg);
  min-height: var(--tv-control-h-lg);
  margin-top: 0;
  padding: 0 var(--tv-s6);
  border-radius: var(--tv-radius);
  font-size: var(--tv-fs-body);
  font-weight: 600;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.manual-customer-actions .button:hover { background: var(--tv-brand-hover); border-color: var(--tv-brand-hover); }

.manual-customer-actions .button:active { background: var(--tv-brand-hover); border-color: var(--tv-brand-hover); box-shadow: none; }

.manual-customer-actions .button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.manual-customer-actions .button:disabled { opacity: .55; cursor: not-allowed; }

.manual-customer-actions .form-status {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  margin: 0;
  color: var(--tv-text-3);
  font-family: var(--tv-font);
  font-size: var(--tv-fs-md);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* ---- 07 responsive ------------------------------------------------------ */
@media (max-width: 1040px) {
  .manual-customer-block { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
  .manual-contact-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .manual-customer-block { grid-template-columns: minmax(0, 1fr); }
  .manual-customer-actions { grid-template-columns: minmax(0, 1fr); }
  .manual-customer-actions .button { grid-column: 1; min-height: 44px; }
  .manual-customer-actions .form-status { grid-row: auto; }
  .manual-customer-form .ghost.small-button,
  .manual-customer-form .ghost.manual-contact-remove { min-height: 44px; }
  .customer-timeline-event header { flex-wrap: wrap; }
}

@media (max-width: 430px) {
  .manual-contact-row { grid-template-columns: minmax(0, 1fr); }
  .manual-contact-row > .manual-contact-primary { grid-column: 1; }
}

@media (max-height: 480px) {
  .manual-customer-actions { position: static; }
}

/* ---- 08 reduced motion -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .manual-customer-form *,
  .manual-customer-form *::before,
  .manual-customer-form *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
