/* Compact Equipment Sales — website chat (app/chat.js). Uses the site's tokens from styles.css: black page, charcoal panels,
   one red accent, condensed-caps headings, system-font text, rounded-square buttons. Desktop: a floating button bottom-right and a
   panel above it. Phone (≤560px): the panel fills the screen and follows the keyboard (visualViewport → --chat-h). */

/* ===== "Ask About This Machine" on product pages — only when the chat is set up */
.sel-pill.ask { flex-basis: 100%; justify-content: center; }
body:not(.chat-on) .sel-pill.ask { display: none; }

/* ===== floating button */
.chat-fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 45;
  display: inline-flex; align-items: center; gap: 9px; height: 54px; padding: 0 22px 0 18px; border-radius: var(--r-pill);
  background: var(--accent-fill); color: #fff; border: 1px solid rgba(255, 255, 255, .12); font: 700 15px var(--font-sans);
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .9);
  transition: background var(--dur), transform 150ms var(--ease), bottom var(--dur) var(--ease);
}
.chat-fab:hover { background: var(--accent-fill-hi); }
.chat-fab:active { transform: scale(.95); }
.chat-fab .ui-i { width: 22px; height: 22px; }
.chat-dot {
  position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; display: grid; place-items: center;
  border-radius: var(--r-pill); background: #fff; color: var(--accent-ink); font: 700 12px/1 var(--font-sans); box-shadow: 0 0 0 3px var(--bg);
}
body.has-tray .chat-fab { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 86px); }
body.sr-attract .chat-fab, body.sr-attract .chat { display: none; }

/* ===== panel */
.chat {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50;
  display: flex; flex-direction: column; width: 392px; height: min(680px, calc(100dvh - 40px)); overflow: hidden;
  background: var(--panel); border: 1px solid var(--hairline-2); border-radius: var(--r-panel);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .95), 0 0 0 1px rgba(0, 0, 0, .6);
  transform-origin: 100% 100%; animation: chat-in var(--dur-slow) var(--ease);
}
@keyframes chat-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
.chat .label { display: block; font: 700 10px/1.2 var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-text); }

.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 12px 12px 16px; border-bottom: 1px solid var(--hairline); flex: none; }
.chat-avatar { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--bg); border: 1px solid var(--hairline-2); }
.chat-avatar .logo { width: 24px; height: 24px; }
.chat-who { flex: 1; min-width: 0; }
.chat-who h2 { margin: 0; font: 700 24px/1 var(--font-display); letter-spacing: .02em; text-transform: uppercase; }
.chat-who p { margin: 3px 0 0; font-size: 12.5px; color: var(--text-muted); }
.chat-x { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 10px; background: var(--raised); border: 1px solid var(--hairline-2); transition: background var(--dur); }
.chat-x:hover { background: var(--raised-hi); } .chat-x .ui-i { width: 18px; height: 18px; }

.chat-threads { display: flex; align-items: center; gap: 6px; flex: none; padding: 10px 14px 0; overflow-x: auto; scrollbar-width: none; }
.chat-threads .label { flex: none; margin-right: 4px; color: var(--text-faint); }
.chat-threads .chat-chip { flex: none; height: 32px; font-size: 12.5px; }
.chat-new { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--accent); }

.chat-about { display: flex; align-items: center; gap: 12px; flex: none; margin: 10px 12px 0; padding: 8px 14px 8px 8px; background: var(--bg); border: 1px solid var(--hairline); border-radius: 12px; }
.chat-pic { display: grid; place-items: center; width: 64px; height: 48px; flex: none; overflow: hidden; border-radius: 12px; background: var(--raised); }
.chat-pic img { width: 100%; height: 100%; object-fit: contain; scale: 1.25; }
.chat-pic img.plate { background: var(--plate); scale: 1; object-fit: cover; }
.chat-pic svg { width: 70%; height: 70%; color: var(--text-muted); }
.chat-about-t { display: flex; flex-direction: column; min-width: 0; }
.chat-about-t b { font: 700 24px/1 var(--font-display); text-transform: uppercase; }
.chat-about-t span:last-child { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== conversation */
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 6px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.chat-log { display: flex; flex-direction: column; gap: 3px; margin: 0; padding: 0; list-style: none; }
.chat-msg { position: relative; display: flex; flex-direction: column; }
.chat-msg p {
  max-width: 84%; margin: 0; padding: 10px 14px; border-radius: 12px; font: 500 14.5px/1.45 var(--font-sans);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-msg.me p { align-self: flex-end; background: var(--accent-fill); color: #fff; }
.chat-msg.them p { align-self: flex-start; margin-left: 30px; background: var(--raised); color: var(--text); }
.chat-msg.me.end p { border-bottom-right-radius: 6px; }
.chat-msg.them.end p { border-bottom-left-radius: 6px; }
.chat-msg.end { margin-bottom: 8px; }
.chat-msg.sending p { opacity: .7; }
.chat-msg.failed p { background: var(--raised-hi); color: var(--text); outline: 1px solid var(--accent); }
.chat-mini { position: absolute; left: 0; bottom: 20px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--bg); border: 1px solid var(--hairline-2); }
.chat-msg.end:not(:has(.chat-time)) .chat-mini { bottom: 0; }
.chat-mini .logo { width: 14px; height: 14px; }
.chat-time { margin: 4px 6px 0; font-size: 11px; color: var(--text-faint); }
.chat-msg.me .chat-time { align-self: flex-end; }
.chat-msg.them .chat-time { margin-left: 36px; }
.chat-retry { font: 700 11px var(--font-sans); color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
.chat-event {
  display: flex; align-items: center; gap: 7px; align-self: center; max-width: 92%; margin: 6px 0 10px; padding: 6px 13px 6px 9px;
  border: 1px solid var(--hairline-2); border-radius: 12px; font-size: 12.5px; line-height: 1.35; color: var(--text-muted);
}
.chat-event .ui-i { width: 15px; height: 15px; color: var(--text); }
.chat-loading { padding: 18px 4px; color: var(--text-muted); font-size: 13px; text-align: center; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 7px; margin: 4px 0 8px 30px; }

/* ===== optional cards (after the first message) */
.chat-cards { display: grid; gap: 10px; padding-bottom: 4px; }
.chat-cards:empty { display: none; }
.chat-card { padding: 14px; background: var(--bg); border: 1px solid var(--hairline-2); border-radius: 14px; }
.chat-card > p, .chat-card form > p:first-child { margin: 0 0 12px; font-size: 14px; line-height: 1.45; }
.chat-contact { display: grid; gap: 8px; }
.chat-contact label { display: grid; gap: 4px; }
.chat-contact label span { font: 700 12px var(--font-sans); color: var(--text-muted); }
.chat-contact input {
  width: 100%; height: 46px; padding: 0 14px; background: var(--panel); color: var(--text); border: 1px solid var(--hairline-2);
  border-radius: 12px; font: 500 16px var(--font-sans); outline: none; transition: border-color var(--dur), box-shadow var(--dur);
}
.chat-contact input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(226, 38, 28, .22); }
.chat-contact input::placeholder { color: var(--text-faint); }
.chat-card-acts { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.chat-card-acts .btn { height: 42px; padding: 0 22px; }
.chat-card-err { margin: 0 0 6px; font-size: 13px; color: #ffb3b3; }
.chat-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 15px; border-radius: var(--r-pill);
  background: var(--raised); border: 1px solid var(--hairline-2); color: var(--text); font: 700 13.5px/1.2 var(--font-sans); text-align: left;
  transition: background var(--dur), border-color var(--dur), transform 150ms var(--ease);
}
.chat-chip:hover { background: var(--raised-hi); border-color: rgba(255, 255, 255, .3); }
.chat-chip:active { transform: scale(.96); }
.chat-chip:disabled, .chat-card .btn:disabled { opacity: .5; }
.chat-skip { min-height: 36px; margin-top: 6px; padding: 0 4px; font: 600 13px var(--font-sans); color: var(--text-muted); text-decoration: underline; text-underline-offset: 3px; border-radius: 6px; }
.chat-card-acts .chat-skip { margin-top: 0; }
.chat-skip:hover { color: var(--text); }
.chat-later { display: inline-flex; align-items: center; gap: 6px; justify-self: center; min-height: 36px; padding: 0 12px; border-radius: var(--r-pill); font: 700 12.5px var(--font-sans); color: var(--text-muted); transition: color var(--dur), background var(--dur); }
.chat-later:hover { color: var(--text); background: var(--raised); }
.chat-later .ui-i { width: 15px; height: 15px; }

/* ===== composer */
.chat-err { flex: none; margin: 0; padding: 8px 18px 0; font-size: 13px; color: #ffb3b3; }
.chat-form { display: flex; align-items: flex-end; gap: 8px; flex: none; padding: 10px 12px 8px; border-top: 1px solid var(--hairline); }
.chat-form textarea {
  flex: 1; min-width: 0; height: 48px; min-height: 48px; max-height: 132px; padding: 12px 16px; resize: none; scrollbar-width: thin;
  background: var(--bg); color: var(--text); border: 1px solid var(--hairline-2); border-radius: 14px;
  font: 500 16px/1.3 var(--font-sans); outline: none; transition: border-color var(--dur), box-shadow var(--dur);
}
.chat-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(226, 38, 28, .22); }
.chat-form textarea::placeholder { color: var(--text-faint); }
.chat-send { display: grid; place-items: center; width: 48px; height: 48px; flex: none; border-radius: 10px; background: var(--accent-fill); color: #fff; transition: background var(--dur), transform 150ms var(--ease); }
.chat-send:hover { background: var(--accent-fill-hi); } .chat-send:active { transform: scale(.93); }
.chat-send .ui-i { width: 21px; height: 21px; }
.chat-foot { flex: none; margin: 0; padding: 0 16px 12px; font-size: 11px; line-height: 1.35; color: var(--text-faint); text-align: center; }

/* ===== phone: icon-only button; the chat takes the whole screen and sits above the keyboard */
@media (max-width: 560px) {
  .chat-fab { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); width: 58px; height: 58px; padding: 0; justify-content: center; }
  .chat-fab-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .chat-fab .ui-i { width: 26px; height: 26px; }
  .chat {
    inset: var(--chat-top, 0) 0 auto 0; width: 100%; height: var(--chat-h, 100dvh); border: 0; border-radius: 0; box-shadow: none;
    animation-name: chat-up;
  }
  @keyframes chat-up { from { opacity: 0; transform: translateY(24px); } }
  .chat-head { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .chat-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .chat-msg p { max-width: 86%; }
  body.chat-is-open { overflow: hidden; }
}
