/* ============================================================
   Texts: the inbox and the automations (views/texts.mjs).

   The inbox reads like a phone's messages app on purpose: the shop's
   own texts on the right in the accent, the customer's on the left on
   a raised surface. Automated texts carry a small label so nobody
   wonders who sent "You are booked in for Thu".
   ============================================================ */

.texts { display: flex; flex-direction: column; gap: var(--s4); min-height: 0; min-width: 0; }
.texts > * { min-width: 0; }

.texts-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4); }
.texts-notice {
  display: inline-flex; align-items: flex-start; gap: var(--s2);
  padding: var(--s2) var(--s3); border: 1px solid var(--line-2); border-radius: var(--r-control);
  background: var(--booked-soft); color: var(--booked-text); font-size: var(--t-13); line-height: 1.45;
  max-width: 62ch;
}
.texts-notice svg { flex: none; margin-top: 2px; }

/* ---------------------------------------------------------- inbox */

.texts-inbox {
  display: grid; grid-template-columns: minmax(260px, 340px) 1fr;
  height: calc(100dvh - 190px); min-height: 460px;
  border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; background: var(--surface);
}

.texts-side { position: relative; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.texts-side-head { display: flex; gap: var(--s2); padding: var(--s3); border-bottom: 1px solid var(--line); }
.texts-search { flex: 1; min-width: 0; }

.texts-list { list-style: none; margin: 0; padding: var(--s1); overflow-y: auto; flex: 1; }
.texts-list-empty { padding: var(--s4); text-align: center; }
.texts-row {
  display: flex; align-items: center; gap: var(--s3); width: 100%; text-align: left;
  padding: var(--s3); border-radius: var(--r-control); color: var(--text-2);
  transition: background var(--duration-fast, 150ms) ease;
}
.texts-row:hover { background: var(--surface-3); }
.texts-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.texts-row.is-on { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.texts-row.is-unread strong { color: var(--text); }
.texts-row.is-unread .texts-row-snippet { color: var(--text); }
.texts-row-text { min-width: 0; gap: 2px; }
.texts-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.texts-row-top strong { font-size: var(--t-14); font-weight: 600; color: var(--text-2); }
.texts-row-when { font-size: var(--t-11); flex: none; font-variant-numeric: tabular-nums; }
.texts-row-snippet { font-size: var(--t-13); color: var(--text-3); }

.texts-avatar {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text-2); font-size: var(--t-12); font-weight: 600; letter-spacing: .02em;
}
.texts-row.is-on .texts-avatar { background: var(--accent); color: var(--text-on-accent); }
.texts-dot { flex: none; width: 8px; height: 8px; border-radius: var(--r-full); background: var(--attention); }
.texts-chip-stop { flex: none; color: var(--attention-text); background: var(--attention-soft); border-color: transparent; }

/* --------------------------------------------------------- thread */

.texts-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--canvas); }
.texts-thread-empty { display: grid; place-items: center; padding: var(--s6); }
.texts-thread-head {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); background: var(--surface);
}
.texts-thread-head strong { font-size: var(--t-15); }
.texts-thread-head .faint { font-size: var(--t-12); font-variant-numeric: tabular-nums; }
.texts-back { display: none; }
.texts-consent { font-size: var(--t-12); color: var(--text-2); }

.texts-log {
  list-style: none; margin: 0; flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s3); padding: var(--s5) var(--s4);
}
.texts-log-empty { margin: auto; }
.texts-msg { display: flex; flex-direction: column; gap: 4px; max-width: min(72%, 520px); }
.texts-msg.is-in { align-self: flex-start; }
.texts-msg.is-out { align-self: flex-end; align-items: flex-end; }

.texts-bubble {
  margin: 0; padding: 9px 13px; border-radius: 16px; font-size: var(--t-14); line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.texts-msg.is-in .texts-bubble { background: var(--surface-3); color: var(--text); border-bottom-left-radius: 5px; }
.texts-msg.is-out .texts-bubble { background: var(--accent); color: var(--text-on-accent); border-bottom-right-radius: 5px; }
.texts-msg.is-failed .texts-bubble { background: var(--attention-soft); color: var(--attention-text); }

.texts-meta { display: inline-flex; gap: var(--s2); font-size: var(--t-11); color: var(--text-3); font-variant-numeric: tabular-nums; }
.texts-auto {
  padding: 0 6px; border-radius: var(--r-chip); background: var(--surface-3); color: var(--text-2);
  font-weight: 600; letter-spacing: .02em;
}

/* -------------------------------------------------------- composer */

.texts-compose { padding: var(--s3) var(--s4) var(--s4); border-top: 1px solid var(--line); background: var(--surface); }
.texts-compose-row { display: flex; gap: var(--s2); align-items: flex-end; }
.texts-input { flex: 1; min-width: 0; resize: none; min-height: 44px; max-height: 160px; line-height: 1.45; }
.texts-input:disabled { opacity: .55; cursor: not-allowed; }
.texts-compose .btn-primary { height: 44px; padding: 0 var(--s5); }
.texts-why {
  margin: 0 0 var(--s2); font-size: var(--t-13); color: var(--attention-text);
}
.texts-hint { margin: var(--s2) 0 0; font-size: var(--t-11); }
.texts-count { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------- new conversation */

.texts-pick-pop {
  position: absolute; z-index: 5; top: 56px; left: var(--s3); right: var(--s3);
  display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3);
  background: var(--surface-2); border: 1px solid var(--line-2); box-shadow: 0 18px 40px rgb(0 0 0 / .45);
}
.texts-pick-head { display: flex; align-items: center; justify-content: space-between; }
.texts-pick-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.texts-pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  padding: var(--s2) var(--s3); border-radius: var(--r-control); text-align: left;
}
.texts-pick:hover, .texts-pick:focus-visible { background: var(--surface-3); outline: none; }
.texts-pick .faint { font-size: var(--t-12); }

/* ------------------------------------------------------ automations */

.texts-auto-pane { display: flex; flex-direction: column; gap: var(--s4); max-width: 980px; }
.texts-auto-intro { margin: 0; max-width: 72ch; color: var(--text-2); line-height: 1.55; font-size: var(--t-14); }
.texts-auto-intro strong { color: var(--text); }
.texts-auto-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }

.texts-auto-card { padding: var(--s4) var(--s5); display: flex; flex-direction: column; gap: var(--s4); border-left: 2px solid transparent; }
.texts-auto-card.is-on { border-left-color: var(--won); }
.texts-auto-head { display: flex; gap: var(--s4); align-items: flex-start; }
.texts-auto-head h3 { margin: 0; font-size: var(--t-15); }
.texts-auto-head .faint { margin: 2px 0 0; font-size: var(--t-13); }

.texts-auto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); align-items: start; }
.texts-auto-body { resize: vertical; min-height: 84px; line-height: 1.45; }
.texts-auto-actions { display: flex; gap: var(--s2); margin-top: var(--s2); }
.texts-auto-preview { gap: var(--s2); }
.texts-preview-label { font-size: var(--t-11); text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 600; }
.texts-preview { background: var(--surface-3); color: var(--text); border-bottom-left-radius: 5px; align-self: flex-start; }
.texts-auto-foot { font-size: var(--t-12); line-height: 1.7; }
.texts-auto-foot code {
  padding: 1px 5px; border-radius: 4px; background: var(--surface-3); color: var(--text-2);
  font-size: var(--t-11);
}

/* The switch: a real checkbox, drawn as a track and thumb. */
.texts-switch { position: relative; display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; flex: none; }
.texts-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.texts-switch-track {
  position: relative; width: 38px; height: 22px; border-radius: var(--r-full);
  background: var(--surface-4); border: 1px solid var(--line-3);
  transition: background 160ms ease, border-color 160ms ease;
}
.texts-switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: var(--r-full);
  background: var(--text-2); transition: transform 180ms cubic-bezier(.16, 1, .3, 1), background 160ms ease;
}
.texts-switch input:checked + .texts-switch-track { background: var(--won-soft); border-color: var(--won); }
.texts-switch input:checked + .texts-switch-track::after { transform: translateX(16px); background: var(--won); }
.texts-switch input:focus-visible + .texts-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.texts-switch-label { font-size: var(--t-12); color: var(--text-2); min-width: 2ch; }

@media (prefers-reduced-motion: reduce) {
  .texts-switch-track, .texts-switch-track::after, .texts-row { transition: none; }
}

/* ---------------------------------------------------------- phones */

@media (max-width: 760px) {
  .texts-inbox { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 210px); }
  .texts-inbox.has-open .texts-side { display: none; }
  .texts-inbox:not(.has-open) .texts-thread { display: none; }
  .texts-side { border-right: 0; }
  .texts-back { display: inline-flex; }
  .texts-msg { max-width: 86%; }
  .texts-auto-grid { grid-template-columns: 1fr; }
  .texts-auto-card { padding: var(--s4); }
  .texts-tabs { width: 100%; }
  .texts-tabs button { flex: 1 1 0; min-width: 0; }
}

/* The lead panel's texting line, under Contact. */
.lead-texts-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3);
  margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line);
  font-size: var(--t-13);
}
.lead-texts-row .faint { font-size: var(--t-12); }
.lead-texts-row .btn { margin-left: auto; }

/* ------------------------------------------------- texting setup */

.texting-setup { display: flex; flex-direction: column; gap: var(--s4); max-width: 880px; }
.texting-card { padding: var(--s5) var(--s6); display: flex; flex-direction: column; gap: var(--s5); }
.texting-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); }
.texting-head h2 { margin: 0; font-size: var(--t-21); letter-spacing: -.01em; }
.texting-head .faint { margin: var(--s1) 0 0; max-width: 60ch; font-size: var(--t-14); line-height: 1.5; }

.texting-note {
  display: flex; gap: var(--s2); align-items: flex-start; margin: 0;
  padding: var(--s3); border-radius: var(--r-control);
  background: var(--attention-soft); color: var(--attention-text); font-size: var(--t-14);
}
.texting-note svg { flex: none; margin-top: 2px; }

.texting-group { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.texting-group legend {
  padding: 0 0 var(--s3); font-size: var(--t-11); font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
}
.texting-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4) var(--s4); }
.texting-grid-address { grid-template-columns: 2fr 1.2fr .6fr .8fr; }
.texting-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.texting-field > label { font-size: var(--t-13); font-weight: 500; color: var(--text-2); }
.texting-field.is-check { grid-column: 1 / -1; }
.texting-field.is-check .check { align-items: flex-start; line-height: 1.45; font-size: var(--t-14); color: var(--text); }
.texting-field.is-check .check input { margin-top: 2px; }
.texting-legal_name, .texting-form_url, .texting-privacy_url { grid-column: 1 / -1; }
.texting-hint { font-size: var(--t-12); line-height: 1.4; }
.texting-error { font-size: var(--t-12); color: var(--attention-text); min-height: 0; }
.texting-error:empty { display: none; }

.texting-docs { display: flex; flex-direction: column; gap: var(--s2); }
.texting-doc {
  display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4);
  border: 1px dashed var(--line-3); border-radius: var(--r-control); background: var(--surface-2);
}
.texting-doc.is-done { border-style: solid; border-color: var(--won); background: var(--won-soft); }
.texting-doc-icon {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border-radius: var(--r-full); background: var(--surface-3); color: var(--text-2);
}
.texting-doc.is-done .texting-doc-icon { background: var(--won); color: var(--canvas); }
.texting-doc .faint { font-size: var(--t-12); }

.texting-privacy { margin: 0; font-size: var(--t-12); }
.texting-actions { display: flex; justify-content: flex-end; gap: var(--s2); flex-wrap: wrap; }
.texting-actions.is-left { justify-content: flex-start; }

.texting-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.texting-steps li { display: flex; gap: var(--s3); align-items: flex-start; color: var(--text-3); }
.texting-steps li.is-done { color: var(--text); }
.texting-steps .faint { font-size: var(--t-12); }
.texting-step-dot {
  display: grid; place-items: center; width: 20px; height: 20px; flex: none; margin-top: 1px;
  border-radius: var(--r-full); border: 1.5px solid var(--line-3);
}
.texting-steps li.is-done .texting-step-dot { border-color: var(--won); background: var(--won); color: var(--canvas); }

.texting-summary {
  display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s5); margin: 0;
  padding-top: var(--s4); border-top: 1px solid var(--line); font-size: var(--t-13);
}
.texting-summary dt { color: var(--text-3); }
.texting-summary dd { margin: 0; color: var(--text); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.texting-review { border-left: 2px solid var(--booked); }
.texting-review-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.texting-review-actions .input { flex: 1 1 220px; min-width: 0; height: 28px; font-size: var(--t-13); }

@media (max-width: 760px) {
  .texting-card { padding: var(--s4); }
  .texting-grid, .texting-grid-address { grid-template-columns: 1fr; }
  .texting-head { flex-direction: column-reverse; gap: var(--s2); }
  .texting-summary { grid-template-columns: 1fr; gap: 2px; }
  .texting-summary dd { margin-bottom: var(--s2); }
  .texting-actions .btn { flex: 1 1 0; }
}

/* --------------------------------------- Montar's Texting screen */

.tq { display: flex; flex-direction: column; gap: var(--s4); max-width: 920px; }
.tq-intro { margin: 0; color: var(--text-2); font-size: var(--t-14); line-height: 1.55; max-width: 72ch; }
.tq-intro strong { color: var(--text); }
.tq-group .card-head { display: flex; align-items: baseline; justify-content: space-between; }
.tq-list { list-style: none; margin: 0; padding: 0 var(--s2) var(--s2); }
.tq-row {
  display: flex; align-items: center; gap: var(--s4); width: 100%; padding: var(--s3);
  border-radius: var(--r-control); text-align: left;
}
.tq-row:hover { background: var(--surface-3); }
.tq-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tq-main { min-width: 0; gap: 2px; }
.tq-main .faint { font-size: var(--t-12); }
.tq-when { flex: none; font-size: var(--t-12); font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .tq-when { display: none; } }
