/* Japan Adventurer Chat — widget styles
 * All rules scoped under .ja-chat-* to avoid theme leakage.
 */

#ja-chat-root {
  --jac-red: #B82105;
  --jac-red-hover: #951a04;
  --jac-dark: #4F4F4F;
  --jac-dark-hover: #3a3a3a;
  --jac-light: #E2E2E2;
  --jac-user-bg: #F4F4F4;
  --jac-bg: #FFFFFF;
  --jac-text: #4F4F4F;
  --jac-text-muted: #7a7a7a;
  --jac-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  --jac-radius: 14px;
  --jac-font-body: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --jac-font-heading: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------- Theme reset (defeat Kadence button overrides) ---------- */

#ja-chat-root, #ja-chat-root * {
  box-sizing: border-box;
}

#ja-chat-root button {
  text-transform: none !important;
  letter-spacing: normal !important;
  font-family: var(--jac-font-body) !important;
  font-weight: 400;
  line-height: 1.4;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: none;
  text-shadow: none;
}

#ja-chat-root svg {
  display: inline-block !important;
  vertical-align: middle;
  fill: currentColor !important;
  flex-shrink: 0;
}

#ja-chat-root svg path {
  fill: currentColor !important;
}

/* ---------- Launcher button ---------- */

.ja-chat-launcher {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px;
  height: 52px !important;
  padding: 0 40px !important;
  border-radius: 12px !important;
  gap: 10px !important;
  background: var(--jac-red) !important;
  color: #fff !important;
  display: inline-flex !important;
  align-items: center;
  gap: 10px;
  box-shadow: var(--jac-shadow);
  z-index: 2147483646;
  transition: transform 0.2s ease, background 0.2s ease;
  font-family: var(--jac-font-heading) !important;
  font-weight: 600 !important;
  font-size: 15px;
}

.ja-chat-launcher:hover {
  background: var(--jac-red-hover) !important;
  transform: translateY(-1px);
}

.ja-chat-launcher:focus-visible {
  outline: 3px solid var(--jac-red);
  outline-offset: 3px;
}

.ja-chat-launcher svg {
  width: 22px !important;
  height: 22px !important;
}

.ja-chat-launcher span {
  white-space: nowrap;
}

.ja-chat-launcher[hidden] {
  display: none !important;
}

/* ---------- Panel container ---------- */

.ja-chat-panel {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px;
  width: 380px;
  height: min(620px, calc(100dvh - 40px));
  background: var(--jac-bg);
  border-radius: var(--jac-radius);
  box-shadow: var(--jac-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483647;
  font-family: var(--jac-font-body);
  font-size: 15px;
  color: var(--jac-text);
  animation: ja-chat-slide-up 0.22s ease-out;
}

@keyframes ja-chat-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ja-chat-panel[hidden] {
  display: none;
}

/* ---------- Header ---------- */

.ja-chat-header {
  background: var(--jac-dark);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.ja-chat-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ja-chat-title {
  font-family: var(--jac-font-heading);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.2;
  margin: 0;
}

.ja-chat-subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

.ja-chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ja-chat-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent !important;
  color: #fff !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.ja-chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12) !important;
}

.ja-chat-icon-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.ja-chat-icon-btn svg {
  width: 18px !important;
  height: 18px !important;
}

/* ---------- Messages area ---------- */

.ja-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
  scroll-behavior: smooth;
}

.ja-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ja-chat-messages::-webkit-scrollbar-thumb {
  background: var(--jac-light);
  border-radius: 3px;
}

.ja-chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.ja-chat-msg p {
  margin: 0 0 8px;
}

.ja-chat-msg p:last-child {
  margin-bottom: 0;
}

.ja-chat-msg ul,
.ja-chat-msg ol {
  margin: 6px 0;
  padding-left: 22px;
}

.ja-chat-msg li {
  margin: 2px 0;
}

.ja-chat-msg a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
  word-break: break-word;
}

.ja-chat-msg code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.9em;
}

.ja-chat-msg-bot {
  background: var(--jac-light);
  color: var(--jac-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.ja-chat-msg-bot a {
  color: var(--jac-red);
}

.ja-chat-msg-user {
  background: var(--jac-user-bg);
  color: var(--jac-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ja-chat-msg-user a {
  color: var(--jac-red);
}

.ja-chat-msg-error {
  background: #fff3f0;
  color: var(--jac-red);
  border: 1px solid #f5c4bb;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  font-size: 13px;
}

/* ---------- Typing indicator ---------- */

.ja-chat-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  align-self: flex-start;
  background: var(--jac-light);
  padding: 12px 14px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.ja-chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--jac-text-muted);
  border-radius: 50%;
  animation: ja-chat-bounce 1.2s infinite ease-in-out;
}

.ja-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ja-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ja-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Suggested starters ---------- */

.ja-chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  background: #fafafa;
}

.ja-chat-starter {
  font-family: var(--jac-font-body);
  font-size: 13px;
  background: #fff;
  color: var(--jac-dark);
  border: 1px solid var(--jac-light);
  border-radius: 18px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ja-chat-starter:hover {
  background: var(--jac-light);
  border-color: #c9c9c9;
}

.ja-chat-starter:focus-visible {
  outline: 2px solid var(--jac-red);
  outline-offset: 1px;
}

/* ---------- Input area ---------- */

.ja-chat-input-wrap {
  padding: 12px;
  border-top: 1px solid var(--jac-light);
  background: #fff;
  flex-shrink: 0;
}

.ja-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--jac-light);
  border-radius: 22px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ja-chat-input-row:focus-within {
  border-color: var(--jac-red);
  box-shadow: 0 0 0 3px rgba(184, 33, 5, 0.12);
}

.ja-chat-textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--jac-font-body);
  font-size: 15px;
  line-height: 1.4;
  color: var(--jac-text);
  background: transparent;
  padding: 6px 0;
  max-height: 120px;
  min-height: 22px;
}

.ja-chat-textarea::placeholder {
  color: var(--jac-text-muted);
}

.ja-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--jac-red) !important;
  color: #fff !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.ja-chat-send:hover:not(:disabled) {
  background: var(--jac-red-hover) !important;
}

.ja-chat-send:disabled {
  background: var(--jac-light) !important;
  color: var(--jac-text-muted) !important;
  cursor: not-allowed;
}

.ja-chat-send svg {
  width: 18px !important;
  height: 18px !important;
}

.ja-chat-counter {
  font-size: 11px;
  color: var(--jac-text-muted);
  text-align: right;
  margin-top: 4px;
  padding: 0 6px;
  min-height: 14px;
}

.ja-chat-counter.is-warning {
  color: var(--jac-red);
}

/* ---------- Mobile (<768px): full-screen ---------- */

@media (max-width: 767px) {
  .ja-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    animation: ja-chat-slide-up-mobile 0.22s ease-out;
  }

  @keyframes ja-chat-slide-up-mobile {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .ja-chat-launcher {
    bottom: calc(16px + env(safe-area-inset-bottom));
    right: 16px;
    height: 48px !important;
    padding: 0 32px !important;
    border-radius: 12px !important;
    font-size: 14px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .ja-chat-panel,
  .ja-chat-launcher,
  .ja-chat-typing span {
    animation: none;
    transition: none;
  }
}
