/* Support chat launcher and panel. External file: the site CSP blocks inline styles.
   Colours, type and radii follow assets/style.css (Poppins, #00cbff, 12–20px corners). */

.bsc-chat {
  --bsc-accent: #00cbff;
  --bsc-ink: #04121a;
  /* Light panel so the chat stands out from the dark site (AA contrast on white). */
  --bsc-accent-text: #006a87;
  --bsc-text: #0f172a;
  --bsc-muted: #334155;
  --bsc-dim: #475569;
  --bsc-bg: #ffffff;
  --bsc-bg-2: #f1f5f9;
  --bsc-line: #d5dbe3;
  --bsc-on-accent: #04313f;
  --bsc-lift: 0px;
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 10050;
  font-family: Poppins, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--bsc-text);
  color-scheme: light;
}

/* Cookie banner is full-width at the bottom. Lift the launcher above it. */
body:has(#cookie-consent:not([hidden])) .bsc-chat {
  --bsc-lift: 132px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--bsc-lift));
}

.bsc-chat[hidden],
.bsc-chat [hidden] {
  display: none !important;
}

.bsc-chat button,
.bsc-chat input,
.bsc-chat textarea {
  font-family: inherit;
  font-size: inherit;
}

.bsc-launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--bsc-accent);
  color: var(--bsc-ink);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0, 203, 255, 0.28);
  touch-action: manipulation;
}

.bsc-launcher:hover {
  filter: brightness(1.08);
}

.bsc-launcher svg {
  display: block;
  flex: 0 0 auto;
}

.bsc-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #04121a;
  color: var(--bsc-accent);
  font-size: 12px;
  font-weight: 700;
}

.bsc-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(720px, calc(100dvh - 110px - var(--bsc-lift)));
  max-height: calc(100dvh - 110px - var(--bsc-lift));
  background: var(--bsc-bg);
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 203, 255, 0.16);
  overflow: hidden;
}

.bsc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 14px 18px;
  background: var(--bsc-accent);
  border-bottom: 1px solid rgba(4, 18, 26, 0.12);
}

/* Header bar sits on the accent colour: dark ink text. */
.bsc-chat h2 {
  margin: 0;
  max-width: none;
  color: var(--bsc-ink);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
}

.bsc-case {
  margin: 2px 0 0;
  color: var(--bsc-on-accent);
  font-size: 12px;
}

.bsc-case-nr {
  color: var(--bsc-ink);
  font-weight: 600;
}

.bsc-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(4, 18, 26, 0.35);
  border-radius: 12px;
  background: transparent;
  color: var(--bsc-ink);
  cursor: pointer;
  touch-action: manipulation;
}

.bsc-close:hover {
  border-color: var(--bsc-ink);
  background: rgba(255, 255, 255, 0.35);
  color: var(--bsc-ink);
}

.bsc-error {
  margin: 0;
  padding: 10px 16px;
  background: #fde8ea;
  color: #8a1020;
  font-size: 13px;
}

.bsc-error:empty {
  display: none;
}

.bsc-start,
.bsc-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.bsc-start {
  gap: 12px;
  overflow: auto;
  padding: 16px;
}

.bsc-start form.bsc-field {
  gap: 12px;
}

.bsc-chat p {
  margin: 0;
  color: var(--bsc-muted);
}

.bsc-intro {
  font-size: 14px;
}

.bsc-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bsc-chat label {
  color: var(--bsc-text);
  font-size: 13px;
  font-weight: 600;
}

.bsc-hint {
  color: var(--bsc-dim);
  font-size: 12px;
}

.bsc-chat input[type="email"],
.bsc-chat textarea {
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--bsc-line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--bsc-text);
  line-height: 1.45;
}

.bsc-chat textarea {
  min-height: 88px;
  resize: vertical;
}

.bsc-chat input[type="email"]::placeholder,
.bsc-chat textarea::placeholder {
  color: #64748b;
}

.bsc-consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.bsc-consent input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  flex: 0 0 auto;
  accent-color: var(--bsc-accent);
}

.bsc-consent label {
  color: var(--bsc-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

.bsc-chat a {
  color: var(--bsc-accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bsc-chat a:hover {
  color: #004e63;
}

/* Turnstile runs invisibly; it only takes space if Cloudflare asks for interaction. */
.bsc-turnstile {
  min-height: 0;
}

.bsc-turnstile:not(:empty) {
  margin-top: 6px;
}

.bsc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bsc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.bsc-btn-primary {
  background: var(--bsc-accent);
  color: var(--bsc-ink);
}

.bsc-btn-primary:hover {
  filter: brightness(1.08);
}

.bsc-btn-ghost {
  background: transparent;
  border-color: #94a3b8;
  color: var(--bsc-text);
}

.bsc-btn-ghost:hover {
  border-color: var(--bsc-accent-text);
  color: var(--bsc-accent-text);
}

.bsc-chat button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.bsc-log-wrap {
  flex: 1;
  min-height: 120px;
  overflow: auto;
  padding: 16px;
}

.bsc-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bsc-empty {
  color: var(--bsc-dim);
  font-size: 14px;
}

.bsc-msg {
  max-width: 88%;
  /* Short messages ("hej") still read as a proper bubble. */
  min-width: 132px;
  min-height: 52px;
  box-sizing: border-box;
  padding: 12px 16px;
  border: 1px solid var(--bsc-line);
  border-radius: 16px;
}

.bsc-msg-visitor {
  align-self: flex-end;
  background: var(--bsc-accent);
  border-color: var(--bsc-accent);
}

.bsc-msg-support {
  align-self: flex-start;
  background: #eef1f5;
}

.bsc-msg-who {
  display: block;
  margin-bottom: 4px;
  color: var(--bsc-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bsc-msg-text {
  margin: 0;
  color: var(--bsc-text);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.bsc-msg time {
  display: block;
  margin-top: 6px;
  color: var(--bsc-dim);
  font-size: 11px;
}

.bsc-foot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 16px;
}

.bsc-status {
  padding: 10px 12px;
  border-radius: 12px;
  background: #e6f9ff;
  color: #0f3a47;
  font-size: 13px;
}

.bsc-status[data-state="fallback"] {
  background: #fff1e0;
  color: #7a3e00;
}

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

.bsc-chat :focus-visible {
  outline: 2px solid var(--bsc-accent-text);
  outline-offset: 2px;
}

.bsc-launcher:focus-visible {
  outline-color: #f4f6fb;
  outline-offset: 3px;
}

@media (max-width: 640px) {
  .bsc-chat.is-open .bsc-launcher {
    display: none;
  }

  .bsc-chat.is-open .bsc-panel {
    position: fixed;
    right: 12px;
    left: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    top: max(12px, env(safe-area-inset-top, 0px));
    width: auto;
    height: auto;
    max-height: none;
  }

  body:has(#cookie-consent:not([hidden])) .bsc-chat {
    --bsc-lift: 210px;
  }
}

@media (max-width: 380px) {
  .bsc-launcher-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .bsc-launcher {
    padding: 0;
    width: 56px;
    height: 56px;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bsc-chat *,
  .bsc-chat *::before,
  .bsc-chat *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (forced-colors: active) {
  .bsc-launcher,
  .bsc-panel,
  .bsc-btn,
  .bsc-close,
  .bsc-msg {
    border: 1px solid CanvasText;
  }
}

@media print {
  .bsc-chat {
    display: none !important;
  }
}

.bsc-status[hidden] {
  display: none;
}

/* Delivery receipt under the visitor's latest message. */
.bsc-msg-receipt {
  display: block;
  margin-top: 4px;
  color: var(--bsc-on-accent);
  font-size: 11px;
  text-align: right;
}

.bsc-msg-receipt[data-read="true"] {
  color: var(--bsc-ink);
  font-weight: 600;
}

/* Typing indicator, shown on the support side. */
.bsc-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  min-width: 132px;
  box-sizing: border-box;
  margin-top: 10px;
  padding: 12px 16px;
  border: 1px solid var(--bsc-line);
  border-radius: 16px;
  background: #eef1f5;
  color: var(--bsc-text);
  font-size: 13px;
}

.bsc-typing[hidden] {
  display: none;
}

.bsc-typing-dots {
  display: inline-flex;
  gap: 3px;
}

.bsc-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.3;
  animation: bsc-typing-dot 1.2s infinite ease-in-out;
}

.bsc-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.bsc-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bsc-typing-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .bsc-typing-dots span { animation: none; opacity: 0.7; }
}

/* Continued chat: add email later, or start a new conversation. */
.bsc-add-email {
  margin-top: 8px;
  font-size: 13px;
  color: var(--bsc-text);
}

.bsc-add-email[hidden] {
  display: none;
}

.bsc-add-email summary {
  cursor: pointer;
  color: var(--bsc-accent-text);
}

.bsc-add-email .bsc-field {
  margin-top: 8px;
}

.bsc-foot-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
}

.bsc-new-chat {
  display: block;
  margin: 0 0 0 auto;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--bsc-dim);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

.bsc-new-chat:hover,
.bsc-new-chat:focus-visible {
  color: var(--bsc-text);
}

/* Visitor bubbles sit on the accent colour: dark ink text (AA). */
.bsc-msg-visitor .bsc-msg-text,
.bsc-msg-visitor .bsc-msg-who,
.bsc-msg-visitor time {
  color: var(--bsc-ink);
}

/* Close button sits on the accent header: focus ring in ink. */
.bsc-head :focus-visible {
  outline-color: var(--bsc-ink);
}

/* Onboarding: local greetings above the conversation. */
.bsc-greet {
  margin-bottom: 10px;
}

.bsc-consent label {
  color: var(--bsc-text);
}
