/* inkpod — AI help desk widget (partials/chat_widget.html + js/chat.js). Tokens only. */

.chat { --chat-gap: max(16px, env(safe-area-inset-right)); --chat-bottom: calc(16px + env(safe-area-inset-bottom)); }

/* ---------- launcher ---------- */
.chat-launcher {
  position: fixed; right: var(--chat-gap); bottom: var(--chat-bottom); z-index: 190;
  display: inline-flex; align-items: center; gap: .55rem;
  min-height: 48px; padding: 0 1.25rem 0 1.05rem; border-radius: var(--r-pill);
  background: var(--ink); color: var(--bone); border: 1px solid var(--ink);
  font: 500 .9rem/1 var(--f-body); letter-spacing: .01em; cursor: pointer;
  box-shadow: var(--shadow-pop); -webkit-tap-highlight-color: transparent;
  transition: transform .25s var(--ease), opacity .2s;
}
.chat-launcher:hover { transform: translateY(-2px); }
.chat-launcher__glyph { color: var(--red); font-size: .95rem; line-height: 1; transition: transform .6s var(--ease); }
.chat-launcher:hover .chat-launcher__glyph { transform: rotate(90deg); }
.chat.is-open .chat-launcher { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* keep clear of the customizer's sticky add-to-cart bar on mobile */
@media (max-width: 960px) {
  body.is-app .chat { --chat-bottom: calc(env(safe-area-inset-bottom) + 84px); }
  /* product page: sit above the sticky buy bar */
  body.page-product .chat { --chat-bottom: calc(env(safe-area-inset-bottom) + 80px); }
  /* form-heavy pages: shrink to an icon so it never covers fields */
  body:is(.page-product, .page-cart, .page-checkout, .page-pay, .page-auth, .page-account, .is-app) .chat-launcher {
    width: 48px; padding: 0; justify-content: center;
  }
  body:is(.page-product, .page-cart, .page-checkout, .page-pay, .page-auth, .page-account, .is-app) .chat-launcher > span:not(.chat-launcher__glyph) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  /* while typing in a page form (soft keyboard up), get out of the way */
  body.is-typing .chat:not(.is-open) .chat-launcher { opacity: 0; pointer-events: none; transform: translateY(8px); }
}

/* ---------- panel ---------- */
.chat-panel {
  position: fixed; right: max(24px, env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 195;
  width: 380px; height: 560px; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
  display: flex; flex-direction: column;
  background: var(--bone); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); overflow: hidden;
  animation: chat-in .32s var(--ease);
}
.chat-panel[hidden] { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(14px) scale(.985); } }
@media (prefers-reduced-motion: reduce) { .chat-panel { animation: none; } .chat-launcher, .chat-launcher__glyph { transition: none; } }

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .95rem .8rem .85rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--bone);
}
.chat-head__text { display: flex; align-items: baseline; gap: .8rem; flex-wrap: wrap; }
.chat-head__title { margin: 0; font: 400 1.7rem/1 var(--f-display); letter-spacing: -.01em; }
.chat-head__title em { font-style: italic; color: var(--red); }
.chat-head__status {
  display: inline-flex; align-items: center; gap: .4rem;
  font: 400 var(--t-label)/1.3 var(--f-mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
}
.chat-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--olive); }
.chat-close { flex: none; width: 44px; height: 44px; }

/* ---------- messages ---------- */
.chat-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: .6rem; padding: 1.1rem 1.1rem .6rem;
  scroll-behavior: smooth;
}
.chat-log:focus-visible { outline-offset: -3px; }
.chat-msg {
  max-width: 86%; padding: .7rem .95rem; border-radius: 16px;
  font-size: .92rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  animation: msg-in .28s var(--ease);
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .chat-msg { animation: none; } .chat-log { scroll-behavior: auto; } }
.chat-msg--assistant { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-msg--user { align-self: flex-end; background: var(--ink); color: var(--bone); border-bottom-right-radius: 4px; }
.chat-msg--note { align-self: center; max-width: 92%; background: none; padding: .2rem .4rem; color: var(--danger); font-size: .82rem; text-align: center; }
.chat-msg a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .16em; font-weight: 500; }
.chat-msg a:hover { text-decoration-thickness: 2px; }

.chat-typing { padding: 0 1.1rem .6rem; }
.chat-typing[hidden] { display: none; }
.chat-typing__dots {
  display: inline-flex; gap: 4px; padding: .8rem .95rem; border-radius: 16px; border-bottom-left-radius: 4px;
  background: var(--paper); border: 1px solid var(--line);
}
.chat-typing__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: chat-dot 1.1s infinite ease-in-out; }
.chat-typing__dots i:nth-child(2) { animation-delay: .15s; }
.chat-typing__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .chat-typing__dots i { animation: none; opacity: .7; } }

/* ---------- quick replies ---------- */
.chat-chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: .2rem 1.1rem .8rem; }
.chat-chips[hidden] { display: none; }
.chat-chip {
  min-height: 40px; padding: 0 .9rem; border-radius: var(--r-pill);
  background: transparent; border: 1px solid var(--line-strong); color: var(--ink);
  font: 400 .84rem/1.2 var(--f-body); cursor: pointer; transition: border-color .2s, background .2s;
}
.chat-chip:hover { border-color: var(--ink); background: var(--paper); }
@media (pointer: coarse) { .chat-chip { min-height: 44px; } }

/* ---------- composer ---------- */
.chat-form {
  display: flex; align-items: flex-end; gap: .5rem;
  margin: 0 .8rem; padding: .35rem .35rem .35rem 1rem;
  background: var(--paper); border: 1px solid var(--line-strong); border-radius: 26px;
  transition: border-color .2s, box-shadow .2s;
}
.chat-form:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(21, 19, 17, .08); }
.chat-input {
  flex: 1; min-width: 0; min-height: 44px; max-height: 120px; padding: .7rem 0; resize: none;
  border: 0; background: transparent; outline: none; font-size: 1rem; line-height: 1.4;
}
.chat-input:focus-visible { outline: none; }
.chat-input::placeholder { color: var(--muted); }
.chat-send {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--ink); color: var(--bone); border: 0; cursor: pointer; transition: transform .2s var(--ease), opacity .2s;
}
.chat-send svg { width: 20px; height: 20px; }
.chat-send:hover { transform: translateX(2px); }
.chat-send[disabled] { opacity: .4; cursor: default; transform: none; }

.chat-foot {
  margin: 0; padding: .55rem 1.1rem .7rem; text-align: center;
  font-size: .72rem; line-height: 1.4; color: var(--muted);
}
.chat-foot a { color: var(--ink-2); }

/* ---------- mobile: full-screen sheet ---------- */
@media (max-width: 560px) {
  .chat-panel {
    inset: 0; right: 0; bottom: 0; width: 100%; height: 100%; max-height: none;
    border: 0; border-radius: 0; box-shadow: none;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    animation-name: chat-sheet-in;
  }
  @keyframes chat-sheet-in { from { transform: translateY(24px); opacity: 0; } }
  .chat-head { padding-left: 1.1rem; }
  .chat-launcher { padding: 0 1.1rem 0 .95rem; }
  .chat-msg { max-width: 90%; }
}
