/* Polly Chat – StepUp Media ApS – v1.0.0 */
#polly-launcher,
#polly-window,
#polly-lightbox,
#polly-emoji-picker {
  --pc-blue:       #d7dfea;
  --pc-blue-dark:  #0675c4;
  --pc-taupe:      #cbb8a2;
  --pc-ink:        #1f1f1f;
  --pc-gray:       #4f4f4f;
  --pc-mist:       #f4f6f9;
  --pc-border:     #e8eaf0;
  --pc-white:      #ffffff;
  --pc-green:      #22c55e;
  --pc-font:       'Jost', -apple-system, BlinkMacSystemFont, sans-serif;
  --pc-font-head:  'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-family: var(--pc-font);
  box-sizing: border-box;
}
#polly-launcher *, #polly-window *, #polly-lightbox *, #polly-emoji-picker * {
  box-sizing: border-box;
}

/* ── Launcher ─────────────────────────────────────────────────── */
#polly-launcher {
  position: fixed !important;
  bottom: 24px !important; right: 24px !important;
  width: 56px !important; height: 56px !important;
  border-radius: 50% !important;
  background: #1f1f1f;
  border: none !important; cursor: pointer !important;
  display: flex !important; align-items: center !important; justify-content: center !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28) !important;
  z-index: 99990 !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding: 0 !important;
}
#polly-launcher:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.38);
}
#polly-launcher svg { width: 26px; height: 26px; }

#polly-dot {
  position: absolute; top: 4px; right: 4px;
  width: 11px; height: 11px;
  background: var(--pc-taupe);
  border-radius: 50%; border: 2px solid var(--pc-white);
  animation: polly-pulse 2.2s infinite;
  display: none;
}
@keyframes polly-pulse {
  0%,100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.4); opacity: 0.65; }
}

/* ── Window ───────────────────────────────────────────────────── */
#polly-window {
  position: fixed !important;
  bottom: 92px !important; right: 24px !important;
  width: 390px !important;
  max-width: calc(100vw - 32px) !important;
  height: 620px !important;
  max-height: calc(100vh - 108px) !important;
  background: var(--pc-white) !important;
  border-radius: 20px !important;
  box-shadow: 0 16px 56px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.06) !important;
  display: -webkit-flex !important; display: flex !important;
  -webkit-flex-direction: column !important; flex-direction: column !important;
  overflow: hidden !important;
  z-index: 99991 !important;
  opacity: 0; pointer-events: none;
  -webkit-transform: translateY(16px) scale(0.96);
          transform: translateY(16px) scale(0.96);
  -webkit-transform-origin: bottom right;
          transform-origin: bottom right;
  -webkit-transition: opacity 0.22s ease, -webkit-transform 0.26s cubic-bezier(0.34,1.4,0.64,1);
          transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.34,1.4,0.64,1);
}
#polly-window.polly-open {
  opacity: 1; pointer-events: auto;
  -webkit-transform: translateY(0) scale(1);
          transform: translateY(0) scale(1);
}

/* ── Header ───────────────────────────────────────────────────── */
.polly-header {
  background: var(--pc-blue);
  padding: 0 16px;
  height: 68px;
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(6,117,196,0.12);
}
.polly-header-back, .polly-header-btn {
  background: none; border: none; cursor: pointer;
  color: var(--pc-gray); padding: 7px; border-radius: 8px;
  display: flex; align-items: center; flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.polly-header-back:hover, .polly-header-btn:hover {
  background: rgba(0,0,0,0.07); color: var(--pc-ink);
}
.polly-header-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--pc-white);
  overflow: hidden; flex-shrink: 0; position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.polly-header-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.polly-header-avatar::after {
  content: '';
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  background: var(--pc-green); border-radius: 50%;
  border: 2px solid var(--pc-blue); z-index: 1;
}
.polly-header-info { flex: 1; min-width: 0; }
.polly-header-name {
  font-family: var(--pc-font-head); font-size: 15px; font-weight: 700;
  color: var(--pc-ink); line-height: 1.2;
}
.polly-header-sub {
  font-size: 11.5px; color: var(--pc-blue-dark); font-weight: 500; margin-top: 1px;
}

/* ── Messages ─────────────────────────────────────────────────── */
.polly-messages {
  flex: 1; overflow-y: auto;
  padding: 20px 16px 8px;
  display: flex; flex-direction: column; gap: 4px;
  scroll-behavior: smooth;
}
.polly-messages::-webkit-scrollbar { width: 3px; }
.polly-messages::-webkit-scrollbar-thumb { background: var(--pc-border); border-radius: 3px; }

.polly-bubble-row { display: flex; align-items: flex-end; gap: 8px; }
.polly-bubble-row + .polly-bubble-row { margin-top: 2px; }
.polly-bubble-row.polly-user + .polly-bubble-row:not(.polly-user),
.polly-bubble-row:not(.polly-user) + .polly-bubble-row.polly-user { margin-top: 12px; }
.polly-bubble-row.polly-user { flex-direction: row-reverse; }

.polly-bubble-avatar-sm {
  width: 26px; height: 26px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0;
  margin-bottom: 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.polly-bubble-avatar-sm img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.polly-bubble-row.polly-stack .polly-bubble-avatar-sm { visibility: hidden; }

.polly-bubble-wrap { display: flex; flex-direction: column; max-width: calc(100% - 42px); }
.polly-bubble-row.polly-user .polly-bubble-wrap { align-items: flex-end; }

.polly-bubble {
  padding: 10px 14px; border-radius: 18px;
  font-size: 14px; line-height: 1.55; font-weight: 400;
  word-break: break-word; white-space: pre-wrap; display: inline-block;
}
.polly-bubble.polly-bot {
  background: var(--pc-mist); color: var(--pc-ink);
  border-bottom-left-radius: 5px;
}
.polly-bubble.polly-user-msg {
  background: var(--pc-blue-dark); color: var(--pc-white);
  border-bottom-right-radius: 5px;
}
.polly-bubble-row.polly-stack .polly-bubble.polly-bot  { border-top-left-radius: 5px; }
.polly-bubble-row.polly-stack .polly-bubble.polly-user-msg { border-top-right-radius: 5px; }

.polly-bubble-time {
  font-size: 10px; color: #bbb; margin-top: 4px;
  padding: 0 2px; font-weight: 300;
}
.polly-bubble-row.polly-user .polly-bubble-time { text-align: right; }

.polly-bubble-img {
  max-width: 220px; max-height: 200px; border-radius: 14px;
  object-fit: cover; display: block; cursor: zoom-in;
}

/* ── Typing ───────────────────────────────────────────────────── */
.polly-typing-row { display: flex; align-items: flex-end; gap: 8px; margin-top: 8px; }
.polly-typing-bubble {
  background: var(--pc-mist); border-radius: 18px; border-bottom-left-radius: 5px;
  padding: 12px 16px; display: flex; gap: 5px; align-items: center;
}
.polly-typing-paw {
  height: 16px; width: auto; display: inline-block;
  animation: polly-paw 1.4s infinite;
}
.polly-typing-paw:nth-child(2) { animation-delay: 0.2s; }
.polly-typing-dots { display: flex; gap: 5px; align-items: center; padding: 2px 0; }
.polly-typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #9aa4ad;
  animation: polly-dot-bounce 1.2s ease-in-out infinite;
}
.polly-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.polly-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes polly-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}
.polly-typing-icon { width: 22px; height: 22px; object-fit: contain; animation: polly-dot-bounce 1.2s ease-in-out infinite; }
@keyframes polly-paw {
  0%,100% { transform: translateY(0) rotate(0deg); opacity: 0.3; }
  25%     { transform: translateY(-5px) rotate(-10deg); opacity: 1; }
  50%     { transform: translateY(0) rotate(0deg); opacity: 0.6; }
}

/* ── Chips ────────────────────────────────────────────────────── */
.polly-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 0 4px; margin-left: 34px;
}
.polly-chip {
  background: var(--pc-white);
  border: 1.5px solid var(--pc-blue-dark);
  border-radius: 20px; padding: 6px 14px;
  font-family: var(--pc-font); font-size: 12.5px; font-weight: 500;
  color: var(--pc-blue-dark); cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.polly-chip:hover { background: var(--pc-blue); transform: translateY(-1px); }

/* ── Footer ───────────────────────────────────────────────────── */
.polly-footer {
  position: relative; /* forankrer emoji-pickeren til footeren, ikke vinduet */
  flex-shrink: 0;
  border-top: 1px solid var(--pc-border);
  background: var(--pc-white);
  padding: 10px 12px 12px;
  position: relative;
}

.polly-input-box {
  border: 1.5px solid #d8dde6;
  border-radius: 16px;
  padding: 8px 10px 6px;
  background: #f7f8fa;
  transition: border-color 0.15s ease;
}
.polly-input-box:focus-within {
  border-color: #a0aabb;
  background: #fff;
}

#polly-img-preview {
  display: none; padding: 8px 0 4px; position: relative;
}
#polly-img-preview img { max-height: 72px; border-radius: 10px; object-fit: cover; }
.polly-remove-img {
  position: absolute; top: 4px; left: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.55); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #fff;
}

.polly-input {
  width: 100%; border: none; outline: none; background: transparent;
  font-family: var(--pc-font); font-size: 14px; color: var(--pc-ink);
  resize: none; line-height: 1.5;
  min-height: 22px; max-height: 110px; overflow-y: auto;
  padding: 2px 0; display: block;
}
.polly-input::placeholder { color: #9aa; }

.polly-toolbar {
  display: flex; align-items: flex-end;
  margin-top: 8px; gap: 4px;
}
.polly-tool-btn {
  background: none; border: none; cursor: pointer;
  color: #9aa; padding: 6px; border-radius: 8px;
  display: flex; align-items: center; flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.polly-tool-btn:hover { color: var(--pc-blue-dark); background: var(--pc-mist); }
.polly-tool-btn svg { width: 18px; height: 18px; display: block; flex-shrink: 0; }
.polly-toolbar-spacer { flex: 1; }

.polly-send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--pc-blue-dark); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.polly-send-btn:hover { background: #055ca8; }
.polly-send-btn:active { transform: scale(0.93); }
.polly-send-btn:disabled { background: var(--pc-border); cursor: default; }
.polly-send-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.polly-branding {
  text-align: center; padding: 7px 0 0;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  font-size: 10.5px; color: #1f1f1f; font-weight: 400; letter-spacing: 0.04em;
}
.polly-branding a { display: flex; align-items: center; text-decoration: none; }
.polly-branding img { height: 22px; width: auto; opacity: 0.85; transition: opacity 0.15s; }
.polly-branding a:hover img { opacity: 1; }

/* ── Emoji picker ─────────────────────────────────────────────── */
#polly-emoji-picker {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px); left: 0;
  width: 300px;
  background: var(--pc-white);
  border: 1px solid var(--pc-border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.13);
  z-index: 100;
  flex-direction: column;
}
#polly-emoji-picker.polly-ep-show { display: flex; }

.polly-ep-search { padding: 10px 10px 6px; border-bottom: 1px solid var(--pc-border); }
.polly-ep-search input {
  width: 100%; border: 1px solid var(--pc-border); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; outline: none; background: var(--pc-mist);
}
.polly-ep-cats {
  display: flex; gap: 2px; padding: 6px 8px;
  border-bottom: 1px solid var(--pc-border); overflow-x: auto;
}
.polly-ep-cats::-webkit-scrollbar { display: none; }
.polly-ep-cat {
  background: none; border: none; cursor: pointer;
  font-size: 16px; padding: 4px 6px; border-radius: 6px;
  opacity: 0.55; transition: opacity 0.15s, background 0.15s; flex-shrink: 0;
}
.polly-ep-cat:hover, .polly-ep-cat.polly-ep-active { opacity: 1; background: var(--pc-mist); }
.polly-ep-grid {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 1px; padding: 6px 8px 10px;
  max-height: 180px; overflow-y: auto;
}
.polly-ep-grid::-webkit-scrollbar { width: 3px; }
.polly-ep-grid::-webkit-scrollbar-thumb { background: var(--pc-border); border-radius: 3px; }
.polly-ep-emoji {
  background: none; border: none; cursor: pointer;
  font-size: 20px; padding: 4px; border-radius: 6px;
  line-height: 1; text-align: center;
  transition: background 0.12s, transform 0.1s;
}
.polly-ep-emoji:hover { background: var(--pc-mist); transform: scale(1.2); }

/* ── Lightbox ─────────────────────────────────────────────────── */
#polly-lightbox {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.82); z-index: 999999;
  align-items: center; justify-content: center;
}
#polly-lightbox.polly-lb-show { display: flex; }
#polly-lightbox img { max-width: 90vw; max-height: 88vh; border-radius: 12px; }
#polly-lightbox-close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.15); border: none; cursor: pointer;
  color: #fff; padding: 8px; border-radius: 50%; display: flex; align-items: center;
}

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #polly-launcher {
    position: fixed;
    bottom: 20px;
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    right: 16px;
    z-index: 2147483647; /* Højest mulige z-index – overskriver alt */
    -webkit-transform: translateZ(0); /* Tving GPU-lag i Safari */
            transform: translateZ(0);
  }
  /* Lukket: fylder ikke skærmen, men beholder animerbar tilstand */
  #polly-window {
    bottom: 0; right: 0; left: 0; top: 0;
    width: 100%; max-width: 100%;
    height: 100%; max-height: 100%;
    height: 100dvh; max-height: 100dvh; /* dvh: korrekt højde i Safari med adresselinje */
    border-radius: 0;
    overflow: hidden;
    z-index: 2147483646; /* Én under launcheren */
    /* Skjul via clip så layout ikke blokerer launcheren */
    -webkit-clip-path: inset(100% 0 0 0);
            clip-path: inset(100% 0 0 0);
    -webkit-transition: opacity 0.22s ease,
                        -webkit-transform 0.26s cubic-bezier(0.34,1.4,0.64,1),
                        -webkit-clip-path 0s 0.26s;
            transition: opacity 0.22s ease,
                        transform 0.26s cubic-bezier(0.34,1.4,0.64,1),
                        clip-path 0s 0.26s;
    /* Nulstil desktop transform-origin på mobil */
    -webkit-transform-origin: bottom center;
            transform-origin: bottom center;
  }
  #polly-window.polly-open {
    -webkit-clip-path: inset(0 0 0 0);
            clip-path: inset(0 0 0 0);
    -webkit-transition: opacity 0.22s ease,
                        -webkit-transform 0.26s cubic-bezier(0.34,1.4,0.64,1),
                        -webkit-clip-path 0s 0s;
            transition: opacity 0.22s ease,
                        transform 0.26s cubic-bezier(0.34,1.4,0.64,1),
                        clip-path 0s 0s;
  }
  #polly-emoji-picker {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
  }
  .polly-input {
    font-size: 16px; /* forhindrer iOS auto-zoom */
  }
  .polly-tool-btn {
    padding: 10px;
    min-width: 44px; min-height: 44px;
  }
  .polly-send-btn {
    width: 44px; height: 44px;
  }
  .polly-footer {
    padding-bottom: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }
}
