/* RackPower Chat widget. All selectors are prefixed to avoid clashing with the theme. */
.rpchat {
  --rpc-accent: #1f4e79;
  --rpc-ink: #1c2530;
  --rpc-muted: #5a6573;
  --rpc-line: #d8dde3;
  --rpc-surface: #ffffff;
  --rpc-panel: #f4f6f8;
  --rpc-ok: #23884a;
  --rpc-warn: #b26a00;
  --rpc-bad: #b3261e;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999990;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--rpc-ink);
}
.rpchat *, .rpchat *::before, .rpchat *::after { box-sizing: border-box; }
.rpchat button { font: inherit; letter-spacing: normal; text-transform: none; margin: 0; }

/* Launcher */
.rpchat .rpchat-launcher {
  width: 58px; height: 58px;
  border: 0; border-radius: 16px;
  background: var(--rpc-accent); color: #fff;
  display: grid; place-items: center;
  cursor: pointer; padding: 0;
  box-shadow: 0 6px 18px rgba(20, 35, 55, .28);
  margin-left: auto;
}
.rpchat .rpchat-launcher:hover { filter: brightness(1.08); }
.rpchat button:focus-visible, .rpchat a:focus-visible, .rpchat textarea:focus-visible {
  outline: 3px solid var(--rpc-accent); outline-offset: 2px;
}
.rpchat .rpchat-launcher:focus-visible { outline-color: #fff; box-shadow: 0 0 0 5px var(--rpc-accent); }

/* Welcome bubble */
.rpchat .rpchat-welcome {
  position: absolute; right: 0; bottom: 70px;
  display: flex; align-items: flex-start; gap: 2px;
  width: max-content; max-width: min(280px, calc(100vw - 32px));
  background: var(--rpc-surface); color: var(--rpc-ink);
  border: 1px solid var(--rpc-line); border-radius: 12px; border-bottom-right-radius: 4px;
  box-shadow: 0 8px 24px rgba(20, 35, 55, .18);
  animation: rpchat-open .2s ease-out;
}
.rpchat .rpchat-welcome[hidden] { display: none; }
.rpchat .rpchat-welcome-text {
  background: none; border: 0; cursor: pointer; text-align: left;
  padding: 11px 4px 11px 14px; color: inherit; font-size: 15px; line-height: 1.35; font-weight: 500;
}
.rpchat .rpchat-welcome-close {
  background: none; border: 0; cursor: pointer; color: var(--rpc-muted);
  width: 30px; height: 30px; margin: 4px 4px 0 0; border-radius: 6px; display: grid; place-items: center; padding: 0; flex: none;
}
.rpchat .rpchat-welcome-close svg { width: 16px; height: 16px; }
.rpchat .rpchat-welcome-close:hover { background: var(--rpc-panel); color: var(--rpc-ink); }
.rpchat.has-welcome .rpchat-launcher { position: relative; }
.rpchat.has-welcome .rpchat-launcher::after {
  content: ""; position: absolute; top: -3px; right: -3px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #5fe08f; border: 2px solid #fff;
}

/* Panel */
.rpchat .rpchat-panel {
  position: absolute; right: 0; bottom: 72px;
  width: 380px; max-width: calc(100vw - 32px);
  height: 600px; max-height: calc(100vh - 110px);
  background: var(--rpc-surface);
  border: 1px solid var(--rpc-line);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(20, 35, 55, .22);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: rpchat-open .16s ease-out;
}
.rpchat .rpchat-panel[hidden] { display: none; }
@keyframes rpchat-open { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.rpchat .rpchat-header {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 10px 12px 16px;
  background: var(--rpc-accent); color: #fff;
}
.rpchat .rpchat-title { flex: 1; display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 16px; }
.rpchat .rpchat-led {
  width: 9px; height: 9px; border-radius: 50%;
  background: #5fe08f;
  box-shadow: 0 0 0 3px rgba(95, 224, 143, .25), 0 0 8px #5fe08f;
}
.rpchat .rpchat-icon-btn {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; padding: 0;
}
.rpchat .rpchat-icon-btn:hover { background: rgba(255, 255, 255, .14); }
.rpchat .rpchat-icon-btn:focus-visible { outline-color: #fff; }

/* Log */
.rpchat .rpchat-log {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  background: var(--rpc-panel);
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
.rpchat .rpchat-msg {
  max-width: 88%; padding: 9px 13px; border-radius: 12px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.rpchat .rpchat-msg p { margin: 0 0 .5em; }
.rpchat .rpchat-msg p:last-child { margin-bottom: 0; }
.rpchat .rpchat-msg ul, .rpchat .rpchat-msg ol { margin: .2em 0 .5em; padding-left: 1.25em; }
.rpchat .rpchat-msg li { margin: .15em 0; }
.rpchat .rpchat-msg code { font-size: .92em; background: rgba(0, 0, 0, .06); padding: 0 .25em; border-radius: 3px; }
.rpchat .rpchat-bot {
  align-self: flex-start; background: var(--rpc-surface);
  border: 1px solid var(--rpc-line); border-bottom-left-radius: 4px;
}
.rpchat .rpchat-bot a { color: var(--rpc-accent); text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }
.rpchat .rpchat-user {
  align-self: flex-end; background: var(--rpc-accent); color: #fff;
  border-bottom-right-radius: 4px; white-space: pre-wrap;
}
.rpchat .rpchat-error { border-color: #e7b7b3; background: #fdf3f2; }
.rpchat .rpchat-intro { display: flex; flex-direction: column; gap: 6px; }
.rpchat .rpchat-privacy { margin: 0 2px; font-size: 12.5px; color: var(--rpc-muted); max-width: 88%; }
.rpchat .rpchat-privacy a { color: inherit; }

.rpchat .rpchat-suggestions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.rpchat .rpchat-chip {
  background: var(--rpc-surface); color: var(--rpc-accent);
  border: 1px solid var(--rpc-accent); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; text-align: left; font-size: 14px;
}
.rpchat .rpchat-chip:hover { background: var(--rpc-accent); color: #fff; }

/* Typing */
.rpchat .rpchat-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.rpchat .rpchat-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--rpc-muted);
  animation: rpchat-blink 1.1s infinite ease-in-out;
}
.rpchat .rpchat-typing span:nth-child(2) { animation-delay: .15s; }
.rpchat .rpchat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes rpchat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Product cards */
.rpchat .rpchat-products { display: flex; flex-direction: column; gap: 6px; max-width: 88%; }
.rpchat a.rpchat-card {
  display: flex; gap: 10px; align-items: center;
  background: var(--rpc-surface); border: 1px solid var(--rpc-line); border-radius: 10px;
  padding: 8px; color: var(--rpc-ink); text-decoration: none;
}
.rpchat a.rpchat-card:hover { border-color: var(--rpc-accent); }
.rpchat .rpchat-card img, .rpchat .rpchat-card-noimg {
  width: 52px; height: 52px; flex: none; object-fit: contain; border-radius: 6px; background: var(--rpc-panel);
}
.rpchat .rpchat-card-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.rpchat .rpchat-card-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.rpchat .rpchat-card-sku { font-size: 12px; color: var(--rpc-muted); }
.rpchat .rpchat-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; }
.rpchat .rpchat-card-price { font-weight: 600; }
.rpchat .rpchat-stock { display: inline-flex; align-items: center; gap: 5px; color: var(--rpc-muted); }
.rpchat .rpchat-stock::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.rpchat .rpchat-stock-in { color: var(--rpc-ok); }
.rpchat .rpchat-stock-back { color: var(--rpc-warn); }
.rpchat .rpchat-stock-out { color: var(--rpc-bad); }

/* Compose */
.rpchat .rpchat-compose {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 10px 6px; border-top: 1px solid var(--rpc-line); background: var(--rpc-surface);
}
.rpchat .rpchat-input {
  flex: 1; resize: none; border: 1px solid var(--rpc-line); border-radius: 10px;
  padding: 9px 11px; font: inherit; font-size: 15px; color: var(--rpc-ink); background: #fff;
  min-height: 40px; max-height: 120px; line-height: 1.4; margin: 0; box-shadow: none;
}
.rpchat .rpchat-input:focus { border-color: var(--rpc-accent); outline: none; }
.rpchat .rpchat-send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 10px;
  background: var(--rpc-accent); color: #fff; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.rpchat .rpchat-send:disabled { opacity: .5; cursor: default; }
.rpchat .rpchat-footer { padding: 0 14px 10px; background: var(--rpc-surface); text-align: right; }
.rpchat .rpchat-link {
  background: none; border: 0; padding: 2px 0; color: var(--rpc-muted);
  font-size: 13px; text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.rpchat .rpchat-link:hover { color: var(--rpc-accent); }
.rpchat .rpchat-link:disabled { opacity: .5; cursor: default; }

/* Phones: full screen */
@media (max-width: 520px) {
  .rpchat { right: 14px; bottom: 14px; }
  .rpchat.is-open .rpchat-launcher { display: none; }
  .rpchat .rpchat-panel {
    position: fixed; inset: 0; width: 100%; max-width: none; height: 100%; max-height: none;
    border-radius: 0; border: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .rpchat .rpchat-header { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .rpchat .rpchat-input { font-size: 16px; } /* stops iOS zooming */
}

@media (prefers-reduced-motion: reduce) {
  .rpchat .rpchat-panel, .rpchat .rpchat-welcome { animation: none; }
  .rpchat .rpchat-typing span { animation: none; opacity: .6; }
}
