/* ------------------------------------------------------------------
   Öppet Hus-assistenten — floating visitor chat
   ------------------------------------------------------------------ */

.chat-launcher {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 2px;
  width: min(var(--dock-width, 250px), calc(100vw - 32px));
  min-height: 54px;
  padding: 0 5px 0 16px;
  border: 1px solid rgba(15, 30, 61, 0.12);
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(15, 30, 61, 0.12);
  transition: width 0.3s var(--ease), border-color 0.25s ease,
              background-color 0.25s ease, border-radius 0.25s ease,
              box-shadow 0.25s ease, opacity 0.2s ease;
}

.chat-launcher:hover {
  border-color: var(--line-strong);
  box-shadow: 0 16px 36px rgba(15, 30, 61, 0.16);
}

.chat-launcher:focus-within {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(255, 59, 31, 0.08), 0 12px 30px rgba(15, 30, 61, 0.12);
}

.chat-launcher.is-typing { border-color: var(--line-strong); }

.chat-launcher__open {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.chat-launcher__open svg { width: 22px; height: 22px; }
.chat-launcher__open:hover { color: var(--coral-text); }

.chat-launcher__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0 2px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
.chat-launcher__input::placeholder { color: #667085; }

.chat-launcher__send {
  display: none;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--coral-text);
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.chat-launcher__send svg { width: 16px; height: 16px; }
.chat-launcher__send:hover {
  background: var(--pink-wash);
  color: var(--ink);
}
.chat-launcher.is-typing .chat-launcher__open { display: none; }
.chat-launcher.is-typing .chat-launcher__send { display: grid; }

body.chat-open .chat-launcher,
body.menu-open .chat-launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
}

.chat-panel {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 32px));
  height: min(640px, calc(100dvh - 32px));
  overflow: hidden;
  border: 1px solid rgba(15, 30, 61, 0.18);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 30px 80px rgba(15, 30, 61, 0.26);
  transform-origin: bottom right;
  animation: chatIn 0.35s var(--ease);
}

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

.chat-panel__tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 6px 18px rgba(15, 30, 61, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-panel :focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}

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

.chat-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  flex: 0 0 auto;
  padding: 1.1rem 1.1rem 1rem;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
}

.chat-header::after {
  content: "";
  position: absolute;
  top: -72px;
  right: -34px;
  width: 138px;
  height: 172px;
  border: 1px solid rgba(246, 166, 191, 0.28);
  border-radius: 999px 999px 0 0;
  pointer-events: none;
}

.chat-avatar {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
}

.chat-avatar svg,
.chat-avatar img { width: 40px; height: 40px; object-fit: contain; }

.chat-heading {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding-top: 0.05rem;
}

.chat-kicker {
  margin: 0 0 0.1rem;
  color: var(--pink);
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.chat-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.3rem 0 0;
  color: rgba(247, 241, 230, 0.72);
  font-size: 0.65rem;
  line-height: 1.2;
}

.chat-status__dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: #6bdc96;
  box-shadow: 0 0 0 3px rgba(107, 220, 150, 0.15);
}

.chat-header__actions {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

.chat-icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(247, 241, 230, 0.2);
  border-radius: 50%;
  background: transparent;
  color: var(--paper);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chat-icon-btn:hover {
  background: var(--cream);
  border-color: var(--cream);
  color: var(--ink);
}

.chat-icon-btn svg { width: 14px; height: 14px; }

/* Conversation ----------------------------------------------------- */

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0.9rem 0.4rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 30, 61, 0.25) transparent;
}

.chat-log::-webkit-scrollbar { width: 7px; }
.chat-log::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(15, 30, 61, 0.22);
  background-clip: padding-box;
}

.chat-message {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  max-width: 100%;
}

.chat-message--agent { align-self: flex-start; align-items: flex-start; }
.chat-message--user {
  align-self: flex-end;
  justify-content: flex-end;
  max-width: 90%;
}

.chat-message__avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--pink);
  color: var(--ink);
}

.chat-message__avatar svg,
.chat-message__avatar img { width: 20px; height: 20px; object-fit: contain; }

.chat-panel .chat-message__avatar {
  width: 30px;
  height: 30px;
  background: transparent;
  filter: drop-shadow(0 1px 2px rgba(15, 30, 61, 0.16));
}
.chat-panel .chat-message__avatar img { width: 28px; height: 28px; }

.chat-message__body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 86%;
}

.chat-message--user .chat-message__body {
  max-width: 100%;
  align-items: flex-end;
}

.chat-bubble {
  max-width: 100%;
  padding: 0.65rem 0.78rem;
  border: 1px solid var(--line);
  border-radius: 4px 15px 15px 15px;
  background: var(--cream);
  color: var(--ink);
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chat-bubble p { margin: 0; }

.chat-message--user .chat-bubble {
  border-color: transparent;
  border-radius: 15px 4px 15px 15px;
  background: var(--coral);
  color: var(--ink);
  font-weight: 500;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chat-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 34px;
  padding: 0.42rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.71rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chat-action:hover {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--cream);
}

.chat-action--primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--cream);
}

.chat-action--primary:hover {
  border-color: var(--coral);
  background: var(--coral);
  color: var(--ink);
}

.chat-action svg { width: 11px; height: 11px; flex: none; }

.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chat-chip {
  min-height: 30px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.chat-chip:hover {
  border-color: var(--coral);
  background: var(--pink-wash);
}

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

.chat-typing {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  align-self: flex-start;
}

.chat-typing__bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 0.62rem 0.78rem;
  border: 1px solid var(--line);
  border-radius: 4px 15px 15px 15px;
  background: var(--cream);
}

.chat-typing__bubble span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(15, 30, 61, 0.45);
  animation: chatDot 1.2s ease-in-out infinite;
}

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

/* Composer --------------------------------------------------------- */

.chat-composer {
  flex: 0 0 auto;
  padding: 0.65rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--cream);
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.25rem 0.3rem 0.25rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--paper);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-wrap:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(255, 59, 31, 0.12);
}

.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 30px;
  max-height: 112px;
  padding: 0.35rem 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.4;
  resize: none;
}

.chat-input::placeholder { color: rgba(15, 30, 61, 0.45); }

.chat-send {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--coral);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.chat-send:hover:not(:disabled) {
  background: var(--ink);
  color: var(--cream);
  transform: translateY(-1px);
}

.chat-send:disabled {
  opacity: 0.35;
  cursor: default;
}

.chat-send svg { width: 15px; height: 15px; }

.chat-note {
  margin: 0.45rem 0 0;
  color: rgba(15, 30, 61, 0.65);
  font-size: 0.6rem;
  line-height: 1.35;
  text-align: center;
}

/* Utilities -------------------------------------------------------- */

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

/* Motion ----------------------------------------------------------- */

@keyframes chatIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@keyframes chatPulse {
  0% { opacity: 0.7; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.18); }
}

@keyframes chatDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* Minimal panel skin ---------------------------------------------- */

.chat-panel {
  border-color: rgba(15, 30, 61, 0.12);
  border-radius: 22px;
  background: var(--cream);
  box-shadow: 0 28px 70px rgba(15, 30, 61, 0.22);
}

.chat-header {
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
  color: var(--ink);
  overflow: visible;
}
.chat-header::after { display: none; }

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 48%, rgba(246, 166, 191, 0.42), rgba(246, 166, 191, 0.1) 64%, transparent 74%);
}
.chat-avatar svg,
.chat-avatar img { width: 38px; height: 38px; }

.chat-kicker {
  color: var(--coral-text);
  font-size: 0.5rem;
  letter-spacing: 0.14em;
}
.chat-title {
  font-size: 0.94rem;
  letter-spacing: -0.025em;
}
.chat-status {
  color: #667085;
  font-size: 0.61rem;
}
.chat-status__dot {
  width: 5px;
  height: 5px;
  background: #2f9e5b;
  box-shadow: 0 0 0 2px rgba(47, 158, 91, 0.12);
}

.chat-icon-btn {
  border-color: var(--line);
  color: var(--ink);
}
.chat-icon-btn:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--cream);
}

.chat-panel .chat-log {
  gap: 16px;
  padding: 54px 14px 5px;
  background: #fbfbf8;
}

.chat-panel .chat-message__body { max-width: 84%; }
.chat-panel .chat-message--agent .chat-bubble {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 0.88rem;
  line-height: 1.6;
}
.chat-panel .chat-message--user { max-width: 86%; }
.chat-panel .chat-message--user .chat-bubble {
  padding: 8px 12px;
  border: 1px solid #eaecf0;
  border-radius: 16px 16px 4px 16px;
  background: #f2f4f7;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 400;
}

.chat-panel .chat-actions { margin-top: 8px; }
.chat-panel .chat-action {
  min-height: 30px;
  padding: 0.3rem 0.6rem;
  border-color: var(--line);
  background: var(--cream);
  color: var(--ink);
  font-size: 0.66rem;
}
.chat-panel .chat-action:hover {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--cream);
}
.chat-panel .chat-action--primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--cream);
}
.chat-panel .chat-action--primary:hover {
  border-color: var(--coral);
  background: var(--coral);
  color: var(--ink);
}

.chat-panel .chat-chips { margin-top: 7px; }
.chat-panel .chat-chip {
  min-height: 26px;
  padding: 0.25rem 0.5rem;
  border-color: var(--line);
  color: #667085;
  font-size: 0.62rem;
}
.chat-panel .chat-chip:hover {
  border-color: var(--line-strong);
  background: var(--cream);
  color: var(--ink);
}

.chat-panel .chat-typing__bubble {
  border: 0;
  border-radius: 12px;
  background: #f2f4f7;
}

.chat-panel .chat-composer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--cream);
}
.chat-panel .chat-input-wrap {
  padding: 5px 5px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(15, 30, 61, 0.07);
}
.chat-panel .chat-input-wrap:focus-within {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(255, 59, 31, 0.07), 0 8px 20px rgba(15, 30, 61, 0.07);
}
.chat-panel .chat-input {
  min-height: 28px;
  padding: 4px 0;
  font-size: 0.84rem;
}
.chat-panel .chat-input::placeholder { color: #667085; }
.chat-panel .chat-send {
  width: 34px;
  height: 34px;
  background: var(--ink);
  color: #fff;
}
.chat-panel .chat-send:hover:not(:disabled) {
  background: var(--coral);
  color: var(--ink);
}
.chat-panel .chat-send:disabled { opacity: 0.25; }
.chat-panel .chat-send svg { width: 14px; height: 14px; }
.chat-panel .chat-note {
  margin-top: 7px;
  color: #667085;
  font-size: 0.58rem;
}

/* Responsive ------------------------------------------------------- */

@media (max-width: 720px) {
  body.chat-open { overflow: hidden; }

  .chat-launcher {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .chat-launcher.is-collapsed {
    width: 54px;
    height: 54px;
    min-height: 54px;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-color: rgba(15, 30, 61, 0.1);
    border-radius: 50%;
    background: var(--cream);
    box-shadow: 0 1px 2px rgba(15, 30, 61, 0.06),
                0 10px 24px rgba(15, 30, 61, 0.12);
  }
  .chat-launcher.is-collapsed:hover {
    border-color: rgba(15, 30, 61, 0.1);
    background: var(--cream);
    box-shadow: 0 1px 2px rgba(15, 30, 61, 0.06),
                0 10px 24px rgba(15, 30, 61, 0.12);
  }
  .chat-launcher.is-collapsed .chat-launcher__input,
  .chat-launcher.is-collapsed .chat-launcher__send { display: none !important; }
  .chat-launcher.is-collapsed .chat-launcher__open {
    width: 54px;
    height: 54px;
    background: transparent;
    color: var(--ink);
  }
  .chat-launcher.is-collapsed .chat-launcher__open svg {
    width: 26px;
    height: 26px;
  }

  .chat-panel {
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform-origin: bottom center;
    animation-name: chatInMobile;
  }

  .chat-panel__tools {
    top: calc(10px + env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
  }

  .chat-panel .chat-log { padding-top: 66px; }

  .chat-log {
    padding-left: max(0.9rem, env(safe-area-inset-left));
    padding-right: max(0.9rem, env(safe-area-inset-right));
  }

  .chat-composer {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  .chat-message__body { max-width: 84%; }
  .chat-bubble { font-size: 0.88rem; }
}

@keyframes chatInMobile {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: none; }
}

/* Reserve space for the fixed launcher below the footer's final row. */
.footer { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

@media (prefers-reduced-motion: reduce) {
  .chat-panel { animation: none; }
  .chat-launcher[data-nudge="true"]::before { animation: none; opacity: 0; }
  .chat-typing__bubble span { animation: none; opacity: 0.6; }
  .chat-launcher,
  .chat-send,
  .chat-action,
  .chat-chip { transition: none; }
}
