/* ============================================================
   K&K TIME STUDIO — AI Chat Widget
   Floating launcher bottom-LEFT (за да не overlap-ва с V/WA
   bottom-right). Стил съвместим с luxury палитрата на сайта.
   ============================================================ */

/* ───────── Welcome tooltip (над chat launcher-а) ───────── */
.kk-chat-tooltip {
  position: fixed;
  bottom: 100px;
  left: 24px;
  max-width: 280px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
  padding: 14px 34px 14px 20px;
  z-index: 9997;
  border-left: 3px solid #c9a961;
  font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}
.kk-chat-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}
.kk-chat-tooltip:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}
/* Стрелка надолу към chat launcher-а */
.kk-chat-tooltip::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 26px;
  width: 14px;
  height: 14px;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.04);
  border-left: none;
}
.kk-chat-tooltip-title {
  font-family: 'Cormorant', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 500;
  color: #1a1a1a;
  margin: 0 0 6px;
  line-height: 1.2;
}
.kk-chat-tooltip-text {
  font-size: 0.82rem;
  line-height: 1.55;
  color: #6b655e;
  margin: 0;
}
.kk-chat-tooltip-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: #b8b0a6;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s;
}
.kk-chat-tooltip-close:hover { color: #1a1a1a; }

/* Dark theme */
:root[data-theme="dark"] .kk-chat-tooltip {
  background: #1a1a1a;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
:root[data-theme="dark"] .kk-chat-tooltip::after { background: #1a1a1a; }
:root[data-theme="dark"] .kk-chat-tooltip-title { color: #f5f1ea; }
:root[data-theme="dark"] .kk-chat-tooltip-text  { color: #a8a098; }
:root[data-theme="dark"] .kk-chat-tooltip-close { color: #6b655e; }
:root[data-theme="dark"] .kk-chat-tooltip-close:hover { color: #f5f1ea; }

/* Mobile — match launcher positioning + iOS safe-area (iPhone home bar).
   env(safe-area-inset-*) се отчита когато <meta viewport-fit="cover">. */
@media (max-width: 480px) {
  .kk-chat-tooltip {
    left: calc(16px + env(safe-area-inset-left, 0px));
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }
  .kk-chat-tooltip::after { left: 22px; }
}

.kk-chat-launcher {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: calc(24px + env(safe-area-inset-left, 0px));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c9a961 0%, #b8944d 100%);
  color: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow:
    0 6px 24px rgba(201, 169, 97, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  z-index: 9998;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border: none;
  padding: 0;
}
.kk-chat-launcher svg {
  width: 28px;
  height: 28px;
  stroke-width: 1.6;
  stroke: #0a0a0a;
  fill: none;
}
.kk-chat-launcher:hover {
  transform: scale(1.08);
  box-shadow:
    0 8px 32px rgba(201, 169, 97, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.kk-chat-launcher.active { display: none; }

.kk-chat-launcher .unread-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}

/* Chat window */
.kk-chat-window {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: calc(24px + env(safe-area-inset-left, 0px));
  width: 380px;
  max-width: calc(100vw - 48px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  height: 560px;
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 16px;
  box-shadow:
    0 18px 56px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(201, 169, 97, 0.18);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
  animation: kkFadeIn 0.28s ease-out;
}
.kk-chat-window.open { display: flex; }

@keyframes kkFadeIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.kk-chat-header {
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
  color: #fff;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  border-bottom: 1px solid rgba(201, 169, 97, 0.25);
}
.kk-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c9a961, #b8944d);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cormorant', Georgia, serif;
  font-weight: 600;
  font-size: 20px;
  color: #1a1a1a;
  flex-shrink: 0;
}
.kk-chat-header-info { flex: 1; min-width: 0; }
.kk-chat-header-info h4 {
  margin: 0;
  font-family: 'Cormorant', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.kk-chat-header-info .status {
  font-size: 0.7rem;
  opacity: 0.75;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.kk-chat-header-info .status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}
.kk-chat-close,
.kk-chat-clear {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.2s, transform 0.2s;
  padding: 4px 8px;
  line-height: 1;
  font-family: inherit;
}
.kk-chat-close { font-size: 20px; }
.kk-chat-close:hover,
.kk-chat-clear:hover { opacity: 1; }
.kk-chat-clear:hover { transform: rotate(-90deg); }

/* Messages */
.kk-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #faf8f5;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kk-chat-messages::-webkit-scrollbar { width: 6px; }
.kk-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(201, 169, 97, 0.3);
  border-radius: 3px;
}

.kk-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-wrap: break-word;
}
.kk-message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #c9a961, #b8944d);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.kk-message.assistant {
  align-self: flex-start;
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #e8e0d0;
  border-bottom-left-radius: 4px;
}
.kk-message.assistant a {
  color: #8a7340;
  font-weight: 500;
  text-decoration: underline;
}
.kk-message.typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e8e0d0;
  padding: 12px 16px;
  border-bottom-left-radius: 4px;
}
.kk-message.typing .dots {
  display: flex;
  gap: 4px;
}
.kk-message.typing .dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9a961;
  animation: kkTypingDot 1.3s infinite ease-in-out;
}
.kk-message.typing .dots span:nth-child(2) { animation-delay: 0.18s; }
.kk-message.typing .dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes kkTypingDot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1);  }
}

/* Input area */
.kk-chat-input-area {
  padding: 14px;
  background: #fff;
  border-top: 1px solid #e8e0d0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.kk-chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #e8e0d0;
  border-radius: 24px;
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
  color: #1a1a1a;
  background: #fff;
}
.kk-chat-input:focus { border-color: #c9a961; }
.kk-chat-input::placeholder { color: #b8b0a6; }

.kk-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c9a961, #b8944d);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
.kk-chat-send svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.kk-chat-send:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(201, 169, 97, 0.4);
}
.kk-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Welcome state */
.kk-chat-welcome {
  text-align: center;
  padding: 28px 20px;
  color: #6b655e;
  font-size: 0.88rem;
}
.kk-chat-welcome h3 {
  color: #1a1a1a;
  margin: 0 0 8px;
  font-family: 'Cormorant', Georgia, serif;
  font-size: 1.4rem;
  font-weight: 500;
}
.kk-chat-welcome p {
  margin: 0;
  line-height: 1.55;
}
.kk-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}
.kk-chat-suggestion {
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e8e0d0;
  border-radius: 20px;
  font-size: 0.83rem;
  cursor: pointer;
  transition: all 0.2s;
  color: #1a1a1a;
  font-family: inherit;
  text-align: left;
}
.kk-chat-suggestion:hover {
  border-color: #c9a961;
  background: rgba(201, 169, 97, 0.06);
  color: #8a7340;
}

/* Mobile (tablet+phone) — compact launcher with safe-area-inset preserved */
@media (max-width: 768px) {
  .kk-chat-launcher {
    width: 56px;
    height: 56px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left:   calc(16px + env(safe-area-inset-left, 0px));
    /* Stronger shadow + cream ring so the gold disc never melts into bright bg images */
    box-shadow:
      0 6px 22px rgba(201, 169, 97, 0.45),
      0 2px 10px rgba(0, 0, 0, 0.35),
      0 0 0 1px rgba(255, 255, 255, 0.18) inset;
  }
  .kk-chat-launcher svg { width: 24px; height: 24px; }
  /* Unread badge — sit on the OUTSIDE edge so it never gets visually swallowed by the gold disc */
  .kk-chat-launcher .unread-dot {
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    border: 2px solid var(--color-bg, #0a0a0a);
  }
}

/* Mobile (≤768px) — chat window takes over the full viewport.
   Header sticks at top, input sticks at bottom, messages scroll between. */
@media (max-width: 768px) {
  .kk-chat-window {
    inset: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0 !important;
    /* Don't carry over the desktop drop-shadow on a full-screen surface */
    box-shadow: none;
    animation: kkSlideUp 0.28s ease-out;
  }
  @keyframes kkSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* Header — sticky top with iPhone notch padding */
  .kk-chat-header {
    position: sticky;
    top: 0;
    z-index: 2;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-left:  calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
  /* Close + clear buttons hit WCAG 44×44 on touch */
  .kk-chat-close,
  .kk-chat-clear {
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
    font-size: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Messages area — leaves room above the sticky input bar */
  .kk-chat-messages {
    padding: 18px 16px 84px;
  }
  .kk-message { max-width: 85%; }

  /* Input area — sticky bottom + safe-area + 16px font (iOS no-zoom) */
  .kk-chat-input-area {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--color-bg, #fff);
    padding: 12px 14px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    padding-left:   calc(14px + env(safe-area-inset-left, 0px));
    padding-right:  calc(14px + env(safe-area-inset-right, 0px));
    border-top: 1px solid #e8e0d0;
  }
  :root[data-theme="dark"] .kk-chat-input-area { background: #0d0d0d; }
  .kk-chat-input {
    font-size: 16px;
    padding: 12px 16px;
  }
  .kk-chat-send {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }
  .kk-chat-send svg { width: 20px; height: 20px; }

  /* Quick-reply / suggestion buttons — comfortable touch targets */
  .kk-chat-suggestions { gap: 10px; margin-top: 18px; }
  .kk-chat-suggestion {
    padding: 12px 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Welcome — slightly more breathing room on the empty state */
  .kk-chat-welcome { padding: 32px 20px; }
  .kk-chat-welcome h3 { font-size: 1.5rem; }
}

/* Dark theme adjustments */
:root[data-theme="dark"] .kk-chat-window {
  background: #0d0d0d;
  box-shadow: 0 18px 56px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(201, 169, 97, 0.2);
}
:root[data-theme="dark"] .kk-chat-messages { background: #121212; }
:root[data-theme="dark"] .kk-message.assistant {
  background: #1a1a1a;
  color: #f5f1ea;
  border-color: rgba(201, 169, 97, 0.15);
}
:root[data-theme="dark"] .kk-message.assistant a { color: #d4b775; }
:root[data-theme="dark"] .kk-message.typing {
  background: #1a1a1a;
  border-color: rgba(201, 169, 97, 0.15);
}
:root[data-theme="dark"] .kk-chat-input-area {
  background: #0d0d0d;
  border-top-color: rgba(201, 169, 97, 0.15);
}
:root[data-theme="dark"] .kk-chat-input {
  background: #1a1a1a;
  color: #f5f1ea;
  border-color: rgba(201, 169, 97, 0.2);
}
:root[data-theme="dark"] .kk-chat-input::placeholder { color: #6b655e; }
:root[data-theme="dark"] .kk-chat-welcome { color: #a8a098; }
:root[data-theme="dark"] .kk-chat-welcome h3 { color: #f5f1ea; }
:root[data-theme="dark"] .kk-chat-suggestion {
  background: #1a1a1a;
  color: #f5f1ea;
  border-color: rgba(201, 169, 97, 0.2);
}
:root[data-theme="dark"] .kk-chat-suggestion:hover {
  color: #d4b775;
  background: rgba(201, 169, 97, 0.08);
}
