/* =====================================================
   tapanila-chatbot.css
   Tapanilapalvelee.fi – Chat Widget Styles
   ===================================================== */

:root {
  --tp-green:      #2d6a4f;
  --tp-green-dark: #1b4332;
  --tp-green-lite: #52b788;
  --tp-cream:      #f8f5f0;
  --tp-text:       #1c1c1c;
  --tp-muted:      #6b7280;
  --tp-radius:     14px;
  --tp-shadow:     0 8px 32px rgba(0,0,0,0.18);
}

/* --- Floating button --- */
#tp-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tp-green), var(--tp-green-lite));
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(45,106,79,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-transform: translateZ(0); /* ← LISÄÄ TÄMÄ — iOS fix */
  
  /* TILAPÄINEN DEBUG */
  /*  
  outline: 5px solid red;
    background: red !important;
    */
  
}
#tp-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(45,106,79,0.55);
}
#tp-chat-btn svg { width: 30px; height: 30px; fill: #fff;pointer-events: none;  }
#tp-chat-btn .tp-notif {
  position: absolute;
  top: 6px; right: 6px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #f4a261;
  border: 2px solid #fff;
  animation: tp-pulse 2s infinite;
}
@keyframes tp-pulse {
  0%,100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.3); opacity: 0.7; }
}

/* --- Chat panel --- */
#tp-chat-panel {
  position: fixed;
  bottom: 104px;
  right: 28px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--tp-cream);
  border-radius: var(--tp-radius);
  box-shadow: var(--tp-shadow);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.85);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), opacity 0.2s ease;
}
#tp-chat-panel.tp-open {
  transform: scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#tp-chat-header {
  background: linear-gradient(135deg, var(--tp-green-dark), var(--tp-green));
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#tp-chat-header .tp-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--tp-green-lite);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
#tp-chat-header .tp-title { font-family: 'Poppins', serif; font-size: 15px; font-weight: bold; }
#tp-chat-header .tp-subtitle { font-size: 11px; opacity: 0.75; margin-top: 1px; }
#tp-chat-close {
  margin-left: auto;
  background: none; border: none;
  color: rgba(255,255,255,0.7); cursor: pointer;
  font-size: 22px; line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}
#tp-chat-close:hover { color: #fff; }

/* Messages area */
#tp-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#tp-chat-messages::-webkit-scrollbar { width: 5px; }
#tp-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Bubbles */
.tp-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
  animation: tp-fadein 0.25s ease;
}
@keyframes tp-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tp-bubble.tp-bot {
  background: #fff;
  color: var(--tp-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  align-self: flex-start;
}
.tp-bubble.tp-user {
  background: var(--tp-green);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* Typing indicator */
.tp-typing {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 14px;
  background: #fff;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  align-self: flex-start;
  width: fit-content;
}
.tp-typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--tp-green-lite);
  animation: tp-bounce 1.2s infinite;
}
.tp-typing span:nth-child(2) { animation-delay: 0.2s; }
.tp-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tp-bounce {
  0%,80%,100% { transform: translateY(0); }
  40%         { transform: translateY(-7px); }
}

/* Quick replies */
#tp-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 14px 10px;
}
.tp-quick-btn {
  background: #fff;
  border: 1.5px solid var(--tp-green-lite);
  color: var(--tp-green-dark);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.tp-quick-btn:hover {
  background: var(--tp-green);
  color: #fff;
  border-color: var(--tp-green);
}

/* Input area */
#tp-chat-input-row {
  display: flex;
  padding: 10px 12px;
  gap: 8px;
  border-top: 1px solid #e8e4de;
  background: #fff;
  flex-shrink: 0;
}
#tp-chat-input {
  flex: 1;
  border: 1.5px solid #ddd;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  background: var(--tp-cream);
  transition: border-color 0.15s;
  resize: none;
  width: 40%;
}
#tp-chat-input:focus { border-color: var(--tp-green-lite); }
#tp-chat-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--tp-green);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#tp-chat-send:hover { background: var(--tp-green-dark); }
#tp-chat-send svg { width: 18px; height: 18px; fill: #fff; }
#tp-chat-send:disabled { background: #ccc; cursor: default; }

/* Footer branding */
#tp-chat-footer {
  text-align: center;
  padding: 5px;
  font-size: 10px;
  color: var(--tp-muted);
  background: #fff;
  border-top: 1px solid #eee;
}

/* Mobile */
@media (max-width: 420px) {
  #tp-chat-panel { right: 10px; bottom: 90px; width: calc(100vw - 20px); }
  #tp-chat-btn   { right: 16px; bottom: 16px; }
}

/* ===== FORMATTED RESPONSE STYLES ===== */

/* Paragraphs inside bot bubble */
.tp-bubble.tp-bot p.tp-para {
  margin: 0 0 8px 0;
  line-height: 1.55;
}
.tp-bubble.tp-bot p.tp-para:last-child {
  margin-bottom: 0;
}

/* Bold text */
.tp-bubble.tp-bot strong {
  font-weight: 700;
  color: #1b4332;
}

/* Section headers (lines ending with :) */
.tp-bubble.tp-bot .tp-header {
  display: block;
  font-weight: 700;
  color: #1b4332;
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Bullet lists */
.tp-bubble.tp-bot ul.tp-list {
  margin: 6px 0 6px 0;
  padding-left: 18px;
  list-style: none;
}
.tp-bubble.tp-bot ul.tp-list li.tp-list-item {
  position: relative;
  padding-left: 10px;
  margin-bottom: 4px;
  line-height: 1.5;
}
.tp-bubble.tp-bot ul.tp-list li.tp-list-item::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #52b788;
}

/* Numbered lists */
.tp-bubble.tp-bot ol.tp-ordered-list {
  margin: 6px 0;
  padding-left: 22px;
}
.tp-bubble.tp-bot ol.tp-ordered-list li.tp-list-item {
  margin-bottom: 4px;
  line-height: 1.5;
}

/* Clickable links */
.tp-bubble.tp-bot a.tp-chat-link {
  color: #2d6a4f;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.tp-bubble.tp-bot a.tp-chat-link:hover {
  color: #1b4332;
}

/* Horizontal divider */
.tp-bubble.tp-bot hr.tp-divider {
  border: none;
  border-top: 1px solid #e0ddd6;
  margin: 8px 0;
}

/* Inline code */
.tp-bubble.tp-bot code.tp-code {
  background: #f0ece4;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: monospace;
}

/* Line breaks inside bubbles */
.tp-bubble.tp-bot br {
  display: block;
  margin-bottom: 4px;
}

/* ===== MESSAGE TIMESTAMP ===== */

.tp-msg-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 84%;
}
.tp-msg-wrapper.tp-bot  { align-self: flex-start; }
.tp-msg-wrapper.tp-user { align-self: flex-end; }

/* Move alignment from bubble to wrapper */
.tp-msg-wrapper .tp-bubble.tp-bot,
.tp-msg-wrapper .tp-bubble.tp-user {
  align-self: unset;
  max-width: 100%;
}

.tp-timestamp {
  font-size: 10px;
  color: #aaa;
  text-align: right;
  margin-top: 3px;
  padding-right: 2px;
  letter-spacing: 0.2px;
}

/* ===== SPEECH TO TEXT ===== */

/* Mic button */
#tp-mic-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid #ddd;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  position: relative;
}
#tp-mic-btn svg {
  width: 18px;
  height: 18px;
  fill: #2d6a4f;
  transition: fill 0.2s;
}
#tp-mic-btn:hover {
  border-color: #2d6a4f;
  background: #d8f3dc;
}

/* Listening state - pulsing red */
#tp-mic-btn.listening {
  border-color: #e63946;
  background: #ffe8ea;
  animation: mic-pulse 1s infinite;
}
#tp-mic-btn.listening svg {
  fill: #e63946;
}
@keyframes mic-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(230,57,70,0.4); }
  50%      { box-shadow: 0 0 0 7px rgba(230,57,70,0); }
}

/* Language selector bar */
#tp-lang-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px 8px;
  background: #fff;
}
#tp-lang-label {
  font-size: 11px;
  color: #aaa;
  margin-right: 2px;
}
.tp-lang-btn {
  background: #fff;
  border: 1.5px solid #ddd;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #999;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}
.tp-lang-btn:hover {
  border-color: #2d6a4f;
  color: #2d6a4f;
}
.tp-lang-btn.active {
  background: #2d6a4f;
  border-color: #2d6a4f;
  color: #fff;
}

/* ===== PAUSE COUNTER & SEND HINT ===== */

/* Pause counter badge next to language buttons */
#tp-pause-counter {
  display: none;
  margin-left: auto;
  background: #74c69d;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.3px;
  transition: background 0.3s;
}

/* Send button flashes green when a pause is detected */
#tp-chat-send.tp-send-hint {
  background: #52b788;
  transform: scale(1.12);
  transition: background 0.15s, transform 0.15s;
}

/* ===== AUTO LINKS IN CHAT BUBBLES ===== */

.tp-bubble.tp-bot a.tp-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #1b4332;
  text-decoration: none;
  border-bottom: 1.5px solid #74c69d;
  padding-bottom: 1px;
  border-radius: 2px;
  transition: all 0.15s ease;
  word-break: break-all;
  font-weight: 500;
}
.tp-bubble.tp-bot a.tp-link:hover {
  background: #d8f3dc;
  border-bottom-color: #2d6a4f;
  color: #1b4332;
  padding: 1px 4px;
  border-radius: 4px;
}

/* Icon before each link type */
.tp-link-icon {
  font-size: 11px;
  flex-shrink: 0;
}

/* URL links — green */
.tp-link-url   { color: #2d6a4f; border-bottom-color: #74c69d; }

/* Email links — blue */
.tp-link-email { color: #1d4e89; border-bottom-color: #90c0f0; }
.tp-link-email:hover { background: #deeeff !important; border-bottom-color: #1d4e89 !important; }

/* Phone links — dark teal */
.tp-link-phone { color: #1b4332; border-bottom-color: #40916c; }
.tp-link-phone:hover { background: #d8f3dc !important; }

/* Map/address links — orange-brown */
.tp-link-map   { color: #7c4a00; border-bottom-color: #f4a261; }
.tp-link-map:hover { background: #fff0e0 !important; border-bottom-color: #e76f51 !important; }
