/**
 * FORRE.NU — Global hjälp-bot ("FORRE-boten")
 * Flytande expert-chatt. FORRE_DARK: 0 radius (utom live-dot/spinner), tokens, tw-bot-* prefix.
 * Placering: NERE TILL VÄNSTER (messenger-FAB äger nere höger).
 */

.tw-bot {
  font-family: var(--font-family), Roboto, sans-serif;
}

/* ── FAB (launcher) ───────────────────────────────────── */
.tw-bot-fab {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 1090;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 50px;
  padding: 0 16px 0 13px;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 0;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-button);
  transition: background var(--transition-speed), transform var(--transition-speed);
}

.tw-bot-fab:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.tw-bot-fab-ic {
  font-size: 18px;
  line-height: 1;
}

.tw-bot-fab-label {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Liten oläst-prick på FAB */
.tw-bot-fab-dot {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface-1);
  display: none;
}

.tw-bot-fab.has-unread .tw-bot-fab-dot {
  display: block;
}

/* Dölj FAB när panelen är öppen */
.tw-bot.is-open .tw-bot-fab {
  display: none;
}

/* ── PROAKTIV NUDGE-BUBBLA ────────────────────────────── */
.tw-bot-nudge {
  position: fixed;
  left: 16px;
  bottom: 74px;
  z-index: 1089;
  max-width: 250px;
  padding: 11px 32px 11px 13px;
  background: var(--surface-2);
  border: 1px solid var(--primary);
  border-radius: 0;
  box-shadow: var(--shadow-dropdown);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  cursor: pointer;
  animation: tw-bot-pop 0.2s ease;
}

.tw-bot-nudge strong {
  color: var(--text-primary);
}

.tw-bot-nudge-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
}

.tw-bot-nudge-x:hover {
  color: var(--text-primary);
}

/* ── PANEL ────────────────────────────────────────────── */
.tw-bot-panel {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 1100;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 90px);
  display: none;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow-hover);
  overflow: hidden;
}

.tw-bot.is-open .tw-bot-panel {
  display: flex;
  animation: tw-bot-pop 0.18s ease;
}

@keyframes tw-bot-pop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── HEADER ───────────────────────────────────────────── */
.tw-bot-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: var(--surface-5);
  border-bottom: 1px solid var(--border-dark);
}

.tw-bot-head-av {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tint-blue);
  border: 1px solid rgba(39, 150, 242, 0.4);
  color: var(--primary);
  font-size: 17px;
}

.tw-bot-head-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tw-bot-head-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.tw-bot-head-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.tw-bot-head-livedot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.tw-bot-head-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: color var(--transition-speed), border-color var(--transition-speed);
}

.tw-bot-head-btn:hover {
  color: var(--text-primary);
  border-color: var(--border);
}

.tw-bot-head-btn.is-muted {
  color: var(--danger);
}

/* ── MUTE-BANNER ──────────────────────────────────────── */
.tw-bot-mutebar {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  font-size: 11.5px;
  color: var(--text-tertiary);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-dark);
}

.tw-bot.is-muted .tw-bot-mutebar {
  display: flex;
}

.tw-bot-mutebar i {
  color: var(--danger);
}

/* ── NAV-TOOLBAR (tillbaka / meny / hem) ──────────────── */
.tw-bot-nav {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-dark);
}

.tw-bot-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-family: var(--font-family), Roboto, sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  text-decoration: none;
  background: var(--surface-4);
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  transition: border-color var(--transition-speed), color var(--transition-speed), background var(--transition-speed);
}

.tw-bot-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--tint-blue);
}

.tw-bot-nav-btn i {
  font-size: 11px;
}

.tw-bot-nav-btn--ghost {
  margin-left: auto;
  background: transparent;
}

/* ── MESSAGES ─────────────────────────────────────────── */
.tw-bot-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-1);
}

.tw-bot-body::-webkit-scrollbar { width: 8px; }
.tw-bot-body::-webkit-scrollbar-thumb { background: var(--border); }

.tw-bot-msg {
  max-width: 86%;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.55;
  border: 1px solid var(--border-dark);
  border-radius: 0;
  animation: tw-bot-pop 0.16s ease;
}

.tw-bot-msg strong { color: var(--text-primary); }

.tw-bot-msg a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}
.tw-bot-msg a:hover { text-decoration: underline; }

/* Klickbara sid-länkar i ett bot-svar */
.tw-bot-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tw-bot-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  color: #fff !important;
  text-decoration: none !important;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 0;
  transition: background var(--transition-speed);
}

.tw-bot-link:hover {
  background: var(--primary-hover);
  text-decoration: none !important;
}

.tw-bot-link i {
  font-size: 11px;
}

.tw-bot-msg ul,
.tw-bot-msg ol {
  margin: 7px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 3px;
}

.tw-bot-msg pre {
  margin: 8px 0 0;
  padding: 9px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border-dark);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}

/* bot till vänster, user till höger */
.tw-bot-msg--bot {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-left: 3px solid var(--primary);
}

.tw-bot-msg--user {
  align-self: flex-end;
  background: var(--tint-blue);
  border-color: rgba(39, 150, 242, 0.4);
  color: var(--text-primary);
  font-weight: 600;
}

/* typing-indikator */
.tw-bot-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-dark);
  border-left: 3px solid var(--primary);
}

.tw-bot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: tw-bot-blink 1s infinite ease-in-out;
}
.tw-bot-typing span:nth-child(2) { animation-delay: 0.18s; }
.tw-bot-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes tw-bot-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* ── QUICK REPLIES ────────────────────────────────────── */
.tw-bot-quick {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border-dark);
  max-height: 116px;
  overflow-y: auto;
}

.tw-bot-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  transition: border-color var(--transition-speed), color var(--transition-speed), background var(--transition-speed);
}

.tw-bot-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--tint-blue);
}

.tw-bot-chip i {
  font-size: 10px;
  color: var(--primary);
}

/* ── INPUT ────────────────────────────────────────────── */
.tw-bot-input {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-5);
  border-top: 1px solid var(--border-dark);
}

.tw-bot-input-field {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--surface-4);
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
  transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.tw-bot-input-field::placeholder { color: rgba(255, 255, 255, 0.35); }

.tw-bot-input-field:focus {
  border-color: var(--primary);
  box-shadow: var(--ring-focus);
}

.tw-bot-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 0;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: background var(--transition-speed);
}

.tw-bot-send:hover { background: var(--primary-hover); }
.tw-bot-send:disabled { opacity: 0.5; cursor: default; }

/* ── MOBIL ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .tw-bot-fab-label { display: none; }
  .tw-bot-fab {
    width: 50px;
    padding: 0;
    justify-content: center;
  }

  .tw-bot-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 82vh;
    max-height: 82vh;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  .tw-bot-nudge {
    max-width: calc(100vw - 80px);
  }
}

/* Lyft FAB + nudge ovanför mobil-bottomnav (56px) */
@media (max-width: 768px) {
  body.has-mobile-nav .tw-bot-fab {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 12px);
  }
  body.has-mobile-nav .tw-bot-nudge {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 70px);
  }
}

/* ── Spotlight ─────────────────────────────────────────────
   Boten pekar på ett riktigt element med en pulserande ring.
   Overlay ligger ovanpå allt men släpper igenom klick (pointer-events:none)
   så användaren kan klicka målet direkt genom ringen. Ingen dimning. */
.forre-spot {
  position: fixed;
  z-index: 2147483000;
  pointer-events: none;
  border-radius: 999px;
  box-shadow: 0 0 0 3px var(--primary, #2563eb);
  animation: forreSpotPulse 1.35s ease-out infinite;
  will-change: box-shadow;
}
@keyframes forreSpotPulse {
  0%   { box-shadow: 0 0 0 3px var(--primary, #2563eb), 0 0 0 0 rgba(37, 99, 235, .45); }
  70%  { box-shadow: 0 0 0 3px var(--primary, #2563eb), 0 0 0 18px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 3px var(--primary, #2563eb), 0 0 0 0 rgba(37, 99, 235, 0); }
}
.forre-spot-label {
  position: fixed;
  z-index: 2147483001;
  pointer-events: none;
  max-width: 220px;
  padding: 7px 11px;
  background: var(--primary, #2563eb);
  color: #fff;
  font: 600 12.5px/1.3 var(--font-family, Roboto), sans-serif;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(20, 30, 50, .28);
  white-space: nowrap;
  transform: translate(-50%, -100%) translateY(4px);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
}
.forre-spot-label.is-in { opacity: 1; transform: translate(-50%, -100%); }
.forre-spot-label.is-below { transform: translate(-50%, 0) translateY(-4px); }
.forre-spot-label.is-below.is-in { transform: translate(-50%, 0); }
.forre-spot-label::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: inherit;
  transform: rotate(45deg);
}
.forre-spot-label.is-below::after { bottom: auto; top: -5px; }

/* Knapp i botens svar som triggar spotlighten */
.tw-bot-spotbtn i { color: var(--primary, #2563eb); }

@media (prefers-reduced-motion: reduce) {
  .forre-spot { animation: none; box-shadow: 0 0 0 3px var(--primary, #2563eb), 0 0 0 6px rgba(37, 99, 235, .3); }
}
