/*
 * Pickles Web Chat — service-site presentation layer.
 * The launcher geometry and motion mirror automation-saas [data-mini-prompt-form].
 * Keep this file isolated from main.css (ADR 0005).
 */

:host {
  --pc-ink: var(--brand-ink, #1e1e16);
  --pc-ink-soft: color-mix(in srgb, var(--pc-ink) 66%, transparent);
  --pc-off-white: var(--brand-off-white, #f7f6f1);
  --pc-green: var(--brand-pickle-green, #afc70f);
  --pc-leaf: var(--brand-leaf, #8fbf3f);
  --pc-sprout: var(--brand-sprout, #c6d96b);
  --pc-mint: var(--brand-mint, #6fcfae);
  --pc-apricot: var(--brand-apricot, #f79b55);
  --pc-sky: var(--brand-sky, #a8c4e8);
  --pc-sand: var(--brand-sand, #d9c9a0);
  --pc-white: #fff;
  --pc-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --pc-ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--pc-ink);
  font-family:
    'Noto Sans JP',
    -apple-system,
    BlinkMacSystemFont,
    'Hiragino Sans',
    Meiryo,
    sans-serif;
}

.pc-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pc-launcher {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 2147483000;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 36px 52px;
  align-items: center;
  gap: 10px;
  width: min(700px, calc(100vw - 32px));
  min-height: 64px;
  padding: 12px;
  margin: 0;
  isolation: isolate;
  overflow: hidden;
  background: var(--pc-white);
  border: 0;
  border-radius: 999px;
  box-shadow:
    0 8px 12px rgb(16 24 40 / 16%),
    0 20px 60px rgb(30 30 22 / 10%);
  transform: translateX(-50%);
  translate: none;
  transform-origin: bottom center;
  transition:
    opacity 320ms var(--pc-ease-standard),
    visibility 320ms var(--pc-ease-standard),
    transform 420ms var(--pc-ease-out);
  /* Do not retain the keyframe's final opacity/transform. The host state
     selectors must win when the launcher is opened or dismissed. */
  animation: pc-launcher-enter 1.2s var(--pc-ease-out);
}

:host([data-pc-motion-settled='true']) .pc-launcher {
  animation: none;
}

.pc-colored-border {
  position: absolute;
  inset: 0;
  z-index: 0;
  padding: 1px;
  pointer-events: none;
  background-image: radial-gradient(
    transparent,
    transparent,
    #a585ff,
    #ffc2ad,
    #ff9472,
    #f2709c,
    #f9eb57,
    transparent,
    transparent
  );
  background-position: 0% 0%;
  background-size: 300% 300%;
  border-radius: inherit;
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  animation: pc-colored-border 14s linear infinite alternate;
}

.pc-launcher > :not(.pc-colored-border) {
  position: relative;
  z-index: 1;
}

.pc-launcher-mark,
.pc-head-mark {
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  background: var(--pc-off-white);
  border-radius: 999px;
}

.pc-launcher-mark {
  width: 40px;
  height: 40px;
  transition:
    background-color 400ms var(--pc-ease-standard),
    transform 400ms var(--pc-ease-out);
}

.pc-launcher:focus-within .pc-launcher-mark {
  background: color-mix(in srgb, var(--pc-green) 22%, var(--pc-off-white));
  transform: rotate(-5deg) scale(1.04);
}

.pc-launcher-mark img,
.pc-head-mark img,
.pc-restore img {
  display: block;
  width: auto;
  height: 25px;
  object-fit: contain;
}

.pc-launcher-field {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

.pc-launcher-input {
  width: 100%;
  min-width: 0;
  padding: 8px 2px;
  color: var(--pc-ink);
  font: 400 15px/1.5 inherit;
  letter-spacing: 0.01em;
  background: transparent;
  border: 0;
  outline: 0;
}

.pc-launcher-input::placeholder {
  color: var(--pc-ink-soft);
  opacity: 1;
}

.pc-launcher-dismiss,
.pc-close {
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--pc-ink-soft);
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 999px;
  transition:
    color 250ms ease,
    background-color 250ms ease,
    transform 350ms var(--pc-ease-out);
}

.pc-launcher-dismiss {
  width: 36px;
  height: 36px;
}

.pc-launcher-dismiss svg,
.pc-close svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.pc-launcher-dismiss:hover,
.pc-close:hover {
  color: var(--pc-ink);
  background: color-mix(in srgb, var(--pc-ink) 7%, transparent);
  transform: rotate(8deg);
}

.pc-launcher-submit {
  display: grid;
  place-items: center;
  width: 52px;
  height: 40px;
  padding: 0;
  overflow: hidden;
  color: var(--pc-white);
  cursor: pointer;
  background: var(--pc-ink);
  border: 0;
  border-radius: 999px;
  transition:
    background-color 300ms ease,
    transform 400ms var(--pc-ease-out),
    box-shadow 400ms ease;
}

.pc-launcher-submit:hover {
  background: color-mix(in srgb, var(--pc-ink) 88%, var(--pc-green));
  box-shadow: 0 8px 20px rgb(30 30 22 / 22%);
  transform: scale(1.035);
}

.pc-submit-icon {
  position: relative;
  display: block;
  width: 24px;
  height: 24px;
  overflow: hidden;
}

.pc-submit-icon svg {
  position: absolute;
  inset: 0;
  width: 24px;
  height: 24px;
  fill: currentColor;
  transition: transform 400ms var(--pc-ease-standard);
}

.pc-submit-icon-front {
  transform: translateX(0);
}

.pc-submit-icon-back {
  transform: translateX(-100%);
}

.pc-launcher-submit:hover .pc-submit-icon-front {
  transform: translateX(100%);
}

.pc-launcher-submit:hover .pc-submit-icon-back {
  transform: translateX(0);
}

:host([data-pc-open='true']) .pc-launcher,
:host([data-pc-dismissed='true']) .pc-launcher {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 18px) scale(0.92);
  /* The initial reveal animation otherwise keeps its animated opacity and
     transform above the host state while the launcher is being dismissed. */
  animation: none;
}

.pc-restore {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  isolation: isolate;
  overflow: hidden;
  cursor: pointer;
  background: var(--pc-white);
  border: 1px solid color-mix(in srgb, var(--pc-ink) 9%, transparent);
  border-radius: 999px;
  box-shadow:
    0 8px 12px rgb(16 24 40 / 14%),
    0 18px 40px rgb(30 30 22 / 12%);
  animation: pc-restore-in 520ms var(--pc-ease-out) 140ms;
}

.pc-restore-glow {
  position: absolute;
  inset: -80%;
  z-index: -1;
  background: conic-gradient(
    from 90deg,
    var(--pc-green),
    var(--pc-mint),
    var(--pc-sky),
    var(--pc-apricot),
    var(--pc-green)
  );
  opacity: 0.18;
  animation: pc-spin 9s linear infinite;
}

.pc-restore:hover {
  transform: translateY(-3px) scale(1.04);
}

:host([data-pc-dismissed='true'][data-pc-restore-settled='true']) .pc-restore {
  animation: none;
}

:host([data-pc-dismissed='true'][data-pc-restore-settled='true']) .pc-launcher,
:host([data-pc-open='true'][data-pc-panel-settled='true']) .pc-launcher {
  transition: none;
}

.pc-panel {
  position: fixed;
  right: auto;
  bottom: 24px;
  left: 50%;
  z-index: 2147483000;
  width: min(700px, calc(100vw - 32px));
  height: min(720px, calc(100dvh - 48px));
  isolation: isolate;
  overflow: hidden;
  color: var(--pc-ink);
  background:
    linear-gradient(180deg, rgb(255 255 255 / 98%), rgb(247 246 241 / 98%)), var(--pc-white);
  border: 1px solid color-mix(in srgb, var(--pc-ink) 9%, transparent);
  border-radius: 32px;
  box-shadow:
    0 8px 16px rgb(16 24 40 / 10%),
    0 28px 90px rgb(30 30 22 / 20%);
  transform: translateX(-50%);
  translate: none;
  transform-origin: bottom center;
}

:host([data-pc-open='true']) .pc-panel:not([hidden]) {
  animation: pc-panel-in 860ms var(--pc-ease-out) both;
}

:host([data-pc-open='true'][data-pc-panel-settled='true']) .pc-panel:not([hidden]) {
  animation: none;
}

:host([data-pc-open='false']) .pc-panel:not([hidden]) {
  pointer-events: none;
  animation: pc-panel-out 320ms var(--pc-ease-standard) both;
}

.pc-panel-glow {
  position: absolute;
  top: -150px;
  right: -120px;
  z-index: 0;
  width: 360px;
  height: 360px;
  pointer-events: none;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--pc-green) 22%, transparent),
    transparent 68%
  );
  filter: blur(10px);
}

.pc-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

:host([data-pc-open='true']) .pc-shell {
  animation: pc-shell-reveal 620ms var(--pc-ease-out) 180ms both;
}

:host([data-pc-open='true'][data-pc-panel-settled='true']) .pc-shell {
  animation: none;
}

.pc-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 17px 20px;
  color: var(--pc-ink);
  background: rgb(255 255 255 / 78%);
  border-bottom: 1px solid color-mix(in srgb, var(--pc-ink) 8%, transparent);
  backdrop-filter: blur(18px);
}

.pc-head-mark {
  width: 42px;
  height: 42px;
  background: color-mix(in srgb, var(--pc-green) 22%, var(--pc-off-white));
}

.pc-head-copy {
  min-width: 0;
  flex: 1;
}

.pc-title,
.pc-subtitle {
  padding: 0;
  margin: 0;
}

.pc-title {
  overflow: hidden;
  font-family:
    'Baloo 2',
    'Noto Sans JP',
    -apple-system,
    BlinkMacSystemFont,
    'Hiragino Sans',
    sans-serif;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pc-subtitle {
  margin-top: 2px;
  color: var(--pc-ink-soft);
  font-size: 11px;
  line-height: 1.4;
}

.pc-close {
  width: 40px;
  height: 40px;
}

.pc-consent {
  width: min(520px, 100%);
  padding: 32px 28px;
  margin: auto;
  overflow: auto;
}

.pc-consent h2 {
  margin: 0 0 12px;
  font-family:
    'Baloo 2',
    'Noto Sans JP',
    -apple-system,
    BlinkMacSystemFont,
    'Hiragino Sans',
    sans-serif;
  font-size: clamp(21px, 4vw, 26px);
  font-weight: 700;
  line-height: 1.35;
}

.pc-consent p {
  margin: 0 0 16px;
  color: var(--pc-ink-soft);
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-line;
}

.pc-link {
  display: inline-flex;
  align-items: center;
  color: var(--brand-ink-green, #4a5406);
  font-size: 13px;
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.pc-captcha {
  display: grid;
  min-height: 66px;
  margin: 20px 0;
  place-items: center start;
}

.pc-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 18px;
  color: var(--pc-ink);
  font: 700 14px/1.4 inherit;
  cursor: pointer;
  background: var(--pc-green);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--pc-green) 28%, transparent);
  transition:
    transform 350ms var(--pc-ease-out),
    box-shadow 350ms ease,
    opacity 250ms ease;
}

.pc-button:hover:not(:disabled) {
  box-shadow: 0 12px 28px color-mix(in srgb, var(--pc-green) 38%, transparent);
  transform: translateY(-2px);
}

.pc-button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  box-shadow: none;
}

.pc-chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.pc-messages {
  flex: 1;
  min-height: 0;
  padding: 22px;
  overflow: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(
      circle at 12% 10%,
      color-mix(in srgb, var(--pc-sprout) 18%, transparent),
      transparent 24%
    ),
    radial-gradient(
      circle at 88% 88%,
      color-mix(in srgb, var(--pc-sky) 16%, transparent),
      transparent 25%
    ),
    var(--pc-off-white);
  scrollbar-color: color-mix(in srgb, var(--pc-ink) 18%, transparent) transparent;
  scrollbar-width: thin;
}

.pc-message {
  width: fit-content;
  max-width: min(86%, 560px);
  padding: 12px 15px;
  margin: 0 0 12px;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.72;
  white-space: pre-wrap;
  border-radius: 18px;
  animation: pc-message-in 440ms var(--pc-ease-out) both;
}

.pc-user {
  margin-left: auto;
  color: var(--pc-white);
  background: var(--pc-ink);
  border-bottom-right-radius: 6px;
  box-shadow: 0 8px 20px rgb(30 30 22 / 13%);
}

.pc-assistant {
  color: var(--pc-ink);
  background: rgb(255 255 255 / 94%);
  border: 1px solid color-mix(in srgb, var(--pc-ink) 8%, transparent);
  border-bottom-left-radius: 6px;
  box-shadow: 0 8px 24px rgb(30 30 22 / 7%);
}

.pc-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 10px 0 0;
  list-style: none;
}

.pc-sources a {
  display: inline-flex;
  padding: 5px 9px;
  color: var(--brand-ink-green, #4a5406);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  background: color-mix(in srgb, var(--pc-green) 14%, var(--pc-white));
  border-radius: 999px;
}

.pc-form {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  background: rgb(255 255 255 / 92%);
  border-top: 1px solid color-mix(in srgb, var(--pc-ink) 8%, transparent);
  backdrop-filter: blur(16px);
}

.pc-input {
  min-width: 0;
  min-height: 48px;
  max-height: 120px;
  flex: 1;
  padding: 12px 14px;
  color: var(--pc-ink);
  resize: none;
  background: var(--pc-off-white);
  border: 1px solid color-mix(in srgb, var(--pc-ink) 11%, transparent);
  border-radius: 18px;
  outline: 0;
  font: 400 14px/1.55 inherit;
  transition:
    border-color 250ms ease,
    box-shadow 250ms ease,
    background-color 250ms ease;
}

.pc-input:focus {
  background: var(--pc-white);
  border-color: var(--pc-leaf);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc-green) 17%, transparent);
}

.pc-send {
  gap: 7px;
  width: auto;
  min-width: 92px;
  min-height: 48px;
  padding-inline: 18px;
  box-shadow: none;
}

.pc-send svg {
  fill: currentColor;
}

:host([data-state='sending']) .pc-send,
:host([data-state='streaming']) .pc-send {
  pointer-events: none;
  animation: pc-send-pulse 1.15s ease-in-out infinite;
}

.pc-status {
  min-height: 22px;
  padding: 3px 16px 7px;
  margin: 0;
  overflow: hidden;
  color: var(--pc-ink-soft);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--pc-white);
}

.pc-powered {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 12px 8px;
  color: var(--pc-ink-soft);
  font-size: 10px;
  letter-spacing: 0.04em;
  background: var(--pc-white);
}

.pc-powered img {
  display: block;
  width: auto;
  height: 16px;
  object-fit: contain;
}

.pc-launcher:focus-visible,
.pc-launcher-input:focus-visible,
.pc-launcher-submit:focus-visible,
.pc-launcher-dismiss:focus-visible,
.pc-restore:focus-visible,
.pc-close:focus-visible,
.pc-link:focus-visible,
.pc-button:focus-visible,
.pc-input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--pc-sky) 80%, var(--pc-ink));
  outline-offset: 3px;
}

@keyframes pc-launcher-enter {
  0% {
    visibility: hidden;
    opacity: 0;
    transform: translate(-50%, 180%) scaleX(0.5);
  }
  38% {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, 0) scaleX(0.5);
  }
  100% {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, 0) scaleX(1);
  }
}

@keyframes pc-colored-border {
  to {
    background-position: 100% 100%;
  }
}

@keyframes pc-panel-in {
  0% {
    opacity: 1;
    border-radius: 44px;
    transform: translate(-50%, 18px) scale(0.92);
  }
  48% {
    opacity: 1;
    border-radius: 36px;
    transform: translate(-50%, -3px) scale(1.008);
  }
  100% {
    opacity: 1;
    border-radius: 32px;
    transform: translate(-50%, 0) scale(1);
  }
}

@keyframes pc-panel-out {
  from {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  to {
    visibility: hidden;
    opacity: 0;
    transform: translate(-50%, 18px) scale(0.92);
  }
}

@keyframes pc-shell-reveal {
  from {
    opacity: 0.28;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pc-restore-in {
  from {
    opacity: 1;
    transform: translateY(18px) scale(0.72) rotate(-8deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

@keyframes pc-message-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pc-send-pulse {
  0%,
  100% {
    opacity: 0.66;
    transform: scale(0.98);
  }
  50% {
    opacity: 1;
    transform: scale(1.02);
  }
}

@keyframes pc-spin {
  to {
    transform: rotate(1turn);
  }
}

@media (max-width: 768px) {
  .pc-launcher {
    bottom: 12px;
    grid-template-columns: 36px minmax(0, 1fr) 34px 48px;
    gap: 7px;
    width: calc(100vw - 24px);
    min-height: 60px;
    padding: 10px;
  }

  .pc-launcher-mark {
    width: 36px;
    height: 36px;
  }

  .pc-launcher-mark img {
    height: 22px;
  }

  .pc-launcher-input {
    font-size: 14px;
  }

  .pc-launcher-dismiss {
    width: 34px;
    height: 34px;
  }

  .pc-launcher-submit {
    width: 48px;
    height: 38px;
  }

  .pc-panel {
    bottom: 8px;
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
    border-radius: 26px;
  }

  .pc-head {
    padding: 13px 14px;
  }

  .pc-consent {
    padding: 24px 20px;
  }

  .pc-messages {
    padding: 16px 13px;
  }

  .pc-message {
    max-width: 91%;
    font-size: 13px;
  }

  .pc-form {
    gap: 7px;
    padding: 10px;
  }

  .pc-send {
    min-width: 50px;
    padding-inline: 14px;
  }

  .pc-send span {
    display: none;
  }

  .pc-powered {
    min-height: 32px;
  }

  .pc-restore {
    right: 12px;
    bottom: 12px;
  }
}

@media (max-width: 420px) {
  .pc-subtitle {
    display: none;
  }

  .pc-head-mark {
    width: 38px;
    height: 38px;
  }

  .pc-title {
    font-size: 15px;
  }

  .pc-launcher-input {
    padding-inline: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pc-launcher,
  .pc-launcher-mark,
  .pc-launcher-submit,
  .pc-launcher-dismiss,
  .pc-colored-border,
  .pc-restore,
  .pc-restore-glow,
  .pc-panel,
  .pc-shell,
  .pc-close,
  .pc-message,
  .pc-send,
  .pc-input {
    scroll-behavior: auto;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
