/* ============================================================
   KARIN CHAT WIDGET — Tecnomar
   ============================================================ */

#karin-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Toggle button ── */
#karin-toggle {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(48deg, #f97316 0%, #f9731691 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 28px rgba(26,43,92,0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.3s;
  position: relative;
}

#karin-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 36px rgba(26,43,92,0.52);
}

#karin-toggle svg {
  width: 26px;
  height: 26px;
  color: white;
  transition: opacity 0.2s, transform 0.25s;
  flex-shrink: 0;
}

.karin-icon-open  { display: flex; }
.karin-icon-close { display: none; }

#karin-widget.open .karin-icon-open  { display: none; }
#karin-widget.open .karin-icon-close { display: flex; }

/* notification badge */
.chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #E74C3C;
  color: white;
  font-size: 0.68rem;
  font-weight: 800;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2.5px solid white;
  animation: karin-pulse 2.2s ease-in-out infinite;
}

@keyframes karin-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.18); }
}

/* ── Tooltip label ── */
.karin-label {
  position: absolute;
  right: 74px;
  bottom: 14px;
  background: white;
  border-radius: 12px;
  padding: 9px 15px;
  font-size: 0.83rem;
  font-weight: 600;
  color: #1A2B5C;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(26,43,92,0.14);
  pointer-events: none;
  transition: opacity 0.4s, transform 0.4s;
  transform: translateX(0);
}

.karin-label::after {
  content: '';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  border: 8px solid transparent;
  border-left-color: white;
  border-right: 0;
}

.karin-label.hidden { opacity: 0; pointer-events: none; }
#karin-widget.open .karin-label { opacity: 0; pointer-events: none; }

/* ── Chat window ── */
#karin-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 360px;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 24px 64px rgba(26,43,92,0.18), 0 4px 16px rgba(0,0,0,0.07);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.85) translateY(16px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.38s cubic-bezier(0.34,1.56,0.64,1), opacity 0.22s ease;
  max-height: 570px;
}

#karin-widget.open #karin-window {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ── */
.chat-header {
  background: linear-gradient(135deg, #1A2B5C 0%, #2B5CE6 100%);
  padding: 15px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
  position: relative;
  letter-spacing: -0.5px;
}

.chat-avatar img {
  width: 115%;
  height: 115%;
  object-fit: cover;
  object-position: center 15%;
  border-radius: 50%;
  display: block;
  margin: -7.5%;
  clip-path: circle(50% at 50% 50%);
}

.chat-avatar::after {
  content: '';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2ECC71;
  border: 2px solid #1A2B5C;
}

.chat-header-info { flex: 1; min-width: 0; }

.chat-name {
  font-weight: 700;
  font-size: 0.98rem;
  color: white;
  line-height: 1.2;
}

.chat-role {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.68);
  margin-top: 1px;
}

.chat-header-close {
  background: rgba(255,255,255,0.14);
  border: none;
  color: rgba(255,255,255,0.9);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-header-close:hover { background: rgba(255,255,255,0.26); }
.chat-header-close svg { width: 13px; height: 13px; }

/* ── Messages ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 280px;
  max-height: 340px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(26,43,92,0.12); border-radius: 2px; }

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: msgIn 0.22s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.karin { align-self: flex-start; }
.chat-msg.user  { align-self: flex-end; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.86rem;
  line-height: 1.55;
}

.chat-msg.karin .msg-bubble {
  background: #EEF2FF;
  color: #1A2B5C;
  border-bottom-left-radius: 4px;
}

.chat-msg.user .msg-bubble {
  background: linear-gradient(135deg, #1A2B5C, #2B5CE6);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 0.67rem;
  color: #9ca3af;
  margin-top: 4px;
  padding: 0 4px;
}

.chat-msg.user .msg-time { text-align: right; }

/* ── Typing indicator ── */
.karin-typing {
  display: flex;
  align-self: flex-start;
  background: #EEF2FF;
  padding: 13px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  gap: 5px;
  align-items: center;
  animation: msgIn 0.2s ease;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2B5CE6;
  opacity: 0.45;
  animation: karin-bounce 1.3s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

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

/* ── Quick replies ── */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 14px 12px;
  flex-shrink: 0;
}

.qr-btn {
  background: white;
  border: 1.5px solid #2B5CE6;
  color: #2B5CE6;
  padding: 7px 13px;
  border-radius: 20px;
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.14s;
  font-family: inherit;
  line-height: 1;
}

.qr-btn:hover {
  background: #2B5CE6;
  color: white;
  transform: translateY(-1px);
}

/* ── Input area ── */
.chat-input-row {
  border-top: 1px solid rgba(26,43,92,0.07);
  padding: 11px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  background: #fafbff;
}

#karin-input {
  flex: 1;
  border: 1.5px solid rgba(26,43,92,0.13);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 0.86rem;
  font-family: inherit;
  color: #1A2B5C;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
  resize: none;
  min-width: 0;
}

#karin-input:focus {
  border-color: #2B5CE6;
  box-shadow: 0 0 0 3px rgba(43,92,230,0.1);
}

#karin-input.shake {
  border-color: #E74C3C;
  animation: karin-shake 0.32s ease;
}

@keyframes karin-shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-5px); }
  75%       { transform: translateX(5px); }
}

#karin-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1A2B5C, #2B5CE6);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

#karin-send:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 14px rgba(43,92,230,0.42);
}

#karin-send svg { width: 16px; height: 16px; }

/* ── Privacy footer ── */
.chat-privacy {
  text-align: center;
  font-size: 0.67rem;
  color: #b0b8cc;
  padding: 0 16px 10px;
  flex-shrink: 0;
  background: #fafbff;
}

.chat-privacy a { color: #2B5CE6; text-decoration: none; }
.chat-privacy a:hover { text-decoration: underline; }

/* ── Mobile ── */
@media (max-width: 540px) {
  #karin-widget {
    bottom: 16px;
    right: 16px;
  }
  #karin-window {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 88px;
    width: auto;
    max-height: 72vh;
    border-radius: 18px;
    transform-origin: bottom center;
  }
  .chat-messages {
    min-height: 0;
    max-height: calc(72vh - 180px);
    -webkit-overflow-scrolling: touch;
  }
  #karin-input {
    font-size: 16px; /* prepreči iOS auto-zoom */
  }
}

/* iOS scroll lock ko je chat odprt */
body.karin-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}
