/* K2M Chat Bot Widget
   Site paleti: pink primary (#E91E63), white bg, dark text (#333)
   Tamamen self-contained; layout CSS'ine bulaşmaz.
*/

:root {
  --k2m-chat-primary: #E91E63;
  --k2m-chat-primary-dark: #C2185B;
  --k2m-chat-bg: #ffffff;
  --k2m-chat-bg-alt: #f6f6f7;
  --k2m-chat-text: #2a2d34;
  --k2m-chat-text-muted: #7a808c;
  --k2m-chat-border: #e6e6ea;
  --k2m-chat-shadow: 0 20px 60px -10px rgba(0,0,0,.20), 0 8px 20px -8px rgba(0,0,0,.10);
  --k2m-chat-radius: 18px;
}

/* ---------- FAB ---------- */
.k2m-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--k2m-chat-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 30px -6px rgba(233,30,99,.55), 0 4px 10px -4px rgba(0,0,0,.25);
  z-index: 999998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, background .2s ease;
  animation: k2m-chat-pulse 2.4s ease-out infinite;
}
.k2m-chat-fab:hover { background: var(--k2m-chat-primary-dark); transform: scale(1.06); }
.k2m-chat-fab:active { transform: scale(0.96); }
.k2m-chat-fab svg { width: 28px; height: 28px; }
.k2m-chat-fab .k2m-chat-fab-close { display: none; }
.k2m-chat-fab.k2m-open .k2m-chat-fab-open { display: none; }
.k2m-chat-fab.k2m-open .k2m-chat-fab-close { display: block; }
.k2m-chat-fab.k2m-open { animation: none; }

/* ---------- Welcome bubble (karşılama balonu) ---------- */
.k2m-chat-welcome {
  position: fixed;
  bottom: 100px;           /* FAB'ın tam üstünde */
  right: 24px;
  max-width: 260px;
  background: #fff;
  color: var(--k2m-chat-text);
  padding: 12px 36px 12px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,.25), 0 4px 12px -4px rgba(0,0,0,.12);
  z-index: 999997;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
  border: 1px solid var(--k2m-chat-border);
}
.k2m-chat-welcome.k2m-show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  animation: k2m-welcome-float 3s ease-in-out 1s infinite;
}
.k2m-chat-welcome::after {
  content: "";
  position: absolute;
  bottom: -7px;
  right: 26px;
  width: 14px; height: 14px;
  background: #fff;
  border-right: 1px solid var(--k2m-chat-border);
  border-bottom: 1px solid var(--k2m-chat-border);
  transform: rotate(45deg);
}
.k2m-chat-welcome-title {
  font-weight: 600;
  color: var(--k2m-chat-primary);
  margin-bottom: 2px;
  font-size: 13px;
}
.k2m-chat-welcome-close {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border: 0; background: transparent;
  color: var(--k2m-chat-text-muted);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.k2m-chat-welcome-close:hover { background: var(--k2m-chat-bg-alt); color: var(--k2m-chat-text); }
.k2m-chat-welcome-close svg { width: 12px; height: 12px; }

@keyframes k2m-welcome-float {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-4px) scale(1); }
}

@media (max-width: 480px) {
  .k2m-chat-welcome { bottom: 86px; right: 16px; max-width: 220px; }
}

@keyframes k2m-chat-pulse {
  0%   { box-shadow: 0 10px 30px -6px rgba(233,30,99,.55), 0 4px 10px -4px rgba(0,0,0,.25), 0 0 0 0 rgba(233,30,99,.45); }
  70%  { box-shadow: 0 10px 30px -6px rgba(233,30,99,.55), 0 4px 10px -4px rgba(0,0,0,.25), 0 0 0 14px rgba(233,30,99,0); }
  100% { box-shadow: 0 10px 30px -6px rgba(233,30,99,.55), 0 4px 10px -4px rgba(0,0,0,.25), 0 0 0 0 rgba(233,30,99,0); }
}

/* ---------- Panel ---------- */
.k2m-chat-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 140px);
  background: var(--k2m-chat-bg);
  border-radius: var(--k2m-chat-radius);
  box-shadow: var(--k2m-chat-shadow);
  z-index: 999999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: k2m-chat-pop .22s ease-out both;
}
.k2m-chat-panel.k2m-visible { display: flex; }

@keyframes k2m-chat-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* Header */
.k2m-chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--k2m-chat-primary) 0%, #D81B60 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}
.k2m-chat-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 38px;
}
.k2m-chat-avatar svg { width: 22px; height: 22px; }
.k2m-chat-title { font-weight: 600; font-size: 15px; line-height: 1.1; letter-spacing: .01em; }
.k2m-chat-subtitle { font-size: 11.5px; opacity: .85; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.k2m-chat-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74,222,128,.7);
  animation: k2m-chat-online 1.8s infinite;
}
@keyframes k2m-chat-online {
  0%,100% { box-shadow: 0 0 0 0 rgba(74,222,128,.6); }
  50%     { box-shadow: 0 0 0 5px rgba(74,222,128,0); }
}
.k2m-chat-header-actions { margin-left: auto; display: flex; gap: 4px; }
.k2m-chat-iconbtn {
  width: 30px; height: 30px;
  border: 0; background: transparent; color: #fff; opacity: .8;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, opacity .15s;
}
.k2m-chat-iconbtn:hover { background: rgba(255,255,255,.15); opacity: 1; }
.k2m-chat-iconbtn svg { width: 16px; height: 16px; }

/* Messages */
.k2m-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--k2m-chat-bg-alt);
  scroll-behavior: smooth;
}
.k2m-chat-messages::-webkit-scrollbar { width: 6px; }
.k2m-chat-messages::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 3px; }

.k2m-msg { display: flex; margin-bottom: 12px; gap: 8px; max-width: 100%; }
.k2m-msg-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  max-width: 80%;
  min-width: 0;
}
.k2m-msg.k2m-bot { justify-content: flex-start; }
.k2m-msg.k2m-bot .k2m-msg-bubble {
  background: #fff;
  color: var(--k2m-chat-text);
  border: 1px solid var(--k2m-chat-border);
  border-top-left-radius: 4px;
}
/* Uzun markdown içerikli bot balonu neredeyse full-width kullanabilsin */
.k2m-msg.k2m-bot .k2m-msg-bubble.k2m-msg-md {
  max-width: 95%;
  white-space: normal;
}
.k2m-msg.k2m-user { justify-content: flex-end; }
.k2m-msg.k2m-user .k2m-msg-bubble {
  background: var(--k2m-chat-primary);
  color: #fff;
  border-top-right-radius: 4px;
}
.k2m-msg-error .k2m-msg-bubble {
  background: #fff3f4;
  color: #b00020;
  border: 1px solid #ffd5d9;
}

/* Typing indicator */
.k2m-typing { display: flex; align-items: center; gap: 4px; padding: 12px 14px; }
.k2m-typing span {
  display: inline-block;
  width: 7px; height: 7px;
  background: #9ba2ad; border-radius: 50%;
  animation: k2m-type 1.1s infinite ease-in-out;
}
.k2m-typing span:nth-child(2) { animation-delay: .15s; }
.k2m-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes k2m-type {
  0%, 80%, 100% { transform: scale(0.7); opacity: .5; }
  40%           { transform: scale(1);   opacity: 1;  }
}

/* Input */
.k2m-chat-input {
  border-top: 1px solid var(--k2m-chat-border);
  padding: 10px 10px 12px;
  display: flex;
  gap: 8px;
  background: #fff;
  align-items: flex-end;
}
.k2m-chat-input textarea {
  flex: 1;
  border: 1px solid var(--k2m-chat-border);
  background: var(--k2m-chat-bg-alt);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 42px;
  transition: border-color .15s, background .15s;
}
.k2m-chat-input textarea:focus { border-color: var(--k2m-chat-primary); background: #fff; }
.k2m-chat-send {
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  background: var(--k2m-chat-primary);
  color: #fff;
  cursor: pointer;
  flex: 0 0 42px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s, opacity .15s;
}
.k2m-chat-send:hover:not(:disabled) { background: var(--k2m-chat-primary-dark); }
.k2m-chat-send:disabled { background: #d4d4d8; cursor: not-allowed; }
.k2m-chat-send svg { width: 18px; height: 18px; }
.k2m-chat-hint {
  padding: 6px 14px 8px;
  font-size: 10.5px;
  color: var(--k2m-chat-text-muted);
  background: #fff;
  border-top: 1px solid var(--k2m-chat-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.k2m-chat-hint > span { flex: 1; min-width: 0; }
.k2m-chat-endbtn {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--k2m-chat-primary);
  background: transparent;
  border: 1px solid var(--k2m-chat-primary);
  border-radius: 12px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.k2m-chat-endbtn:hover { background: var(--k2m-chat-primary); color: #fff; }
.k2m-chat-endbtn[hidden] { display: none; }

/* Mobile */
@media (max-width: 480px) {
  .k2m-chat-panel {
    right: 8px; left: 8px; width: auto;
    bottom: 90px;
    height: calc(100vh - 120px);
  }
  .k2m-chat-fab { bottom: 16px; right: 16px; }
}

/* ─── Markdown içerikli bot balonu ─────────────────────────── */
.k2m-msg-md { line-height: 1.55; }
.k2m-msg-md > *:first-child { margin-top: 0; }
.k2m-msg-md > *:last-child { margin-bottom: 0; }
.k2m-msg-md h1, .k2m-msg-md h2, .k2m-msg-md h3,
.k2m-msg-md h4, .k2m-msg-md h5, .k2m-msg-md h6 {
  margin: 14px 0 6px; font-weight: 600; line-height: 1.3;
}
.k2m-msg-md h1 { font-size: 17px; }
.k2m-msg-md h2 { font-size: 16px; }
.k2m-msg-md h3 { font-size: 15px; }
.k2m-msg-md h4, .k2m-msg-md h5, .k2m-msg-md h6 { font-size: 14px; }
.k2m-msg-md p { margin: 6px 0; }
.k2m-msg-md ul, .k2m-msg-md ol { margin: 6px 0; padding-left: 20px; }
.k2m-msg-md li { margin: 3px 0; }
.k2m-msg-md li > p { margin: 0; }
.k2m-msg-md strong { font-weight: 600; }
.k2m-msg-md em { font-style: italic; }
.k2m-msg-md hr { border: 0; border-top: 1px solid var(--k2m-chat-border); margin: 12px 0; }
.k2m-msg-md a { color: #3a3782; text-decoration: underline; word-break: break-all; }
.k2m-msg-md blockquote {
  margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--k2m-chat-border);
  background: #f7f7fa; color: #555; border-radius: 3px;
}
.k2m-msg-md code {
  font-family: Menlo, Consolas, monospace; font-size: 12.5px;
  background: rgba(58,55,130,.08); padding: 1px 5px; border-radius: 3px;
}
.k2m-msg-md pre {
  background: #1e1e2a; color: #eaeaf0; padding: 10px 12px; border-radius: 6px;
  overflow-x: auto; margin: 8px 0; font-size: 12.5px; line-height: 1.5;
}
.k2m-msg-md pre code { background: transparent; padding: 0; color: inherit; }

/* Tablo — sığmazsa yatay scroll, cell içeriği kırıldıkça kır */
.k2m-msg-md .k2m-table-wrap {
  max-width: 100%; overflow-x: auto; margin: 8px 0;
  border: 1px solid var(--k2m-chat-border); border-radius: 4px;
}
.k2m-msg-md .k2m-table-wrap::-webkit-scrollbar { height: 6px; }
.k2m-msg-md .k2m-table-wrap::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.k2m-msg-md table {
  width: 100%; border-collapse: collapse; font-size: 12px;
  table-layout: auto;
}
.k2m-msg-md thead { background: #f0effa; }
.k2m-msg-md th, .k2m-msg-md td {
  border: 1px solid var(--k2m-chat-border); padding: 5px 8px; text-align: left;
  vertical-align: top; word-break: break-word; overflow-wrap: anywhere;
  min-width: 70px; max-width: 220px;
}
.k2m-msg-md th { font-weight: 600; color: #3a3782; white-space: nowrap; }
.k2m-msg-md td { line-height: 1.4; }

/* Kod blokları da yatay scroll + küçük font */
.k2m-msg-md pre { max-width: 100%; overflow-x: auto; font-size: 11.5px; }

/* Başlıklardaki emojiler baş tarafta kalsın ve wrap olsun */
.k2m-msg-md h1, .k2m-msg-md h2, .k2m-msg-md h3 { word-break: break-word; }

/* ─── Pre-chat form ─────────────────────────────────────── */
.k2m-chat-prechat {
  display: none;
  flex-direction: column;
  padding: 18px 20px;
  overflow-y: auto;
  background: #fafaff;
}
.k2m-chat-prechat.k2m-visible { display: flex; }
.k2m-chat-prechat.k2m-visible ~ .k2m-chat-messages { display: none; }
.k2m-prechat-intro { margin-bottom: 14px; }
.k2m-prechat-title { font-size: 17px; font-weight: 600; color: var(--k2m-chat-text); }
.k2m-prechat-subtitle { font-size: 13px; color: var(--k2m-chat-text-muted); margin-top: 4px; }
.k2m-prechat-row { display: flex; gap: 8px; }
.k2m-prechat-row .k2m-prechat-field { flex: 1; min-width: 0; }
.k2m-prechat-field { margin-bottom: 10px; }
.k2m-prechat-field label {
  display: block; font-size: 11px; color: #666; font-weight: 500;
  margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px;
}
.k2m-prechat-field input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--k2m-chat-border);
  border-radius: 6px; font-size: 13px; font-family: inherit;
  background: #fff; transition: border-color .15s;
}
.k2m-prechat-field input:focus { outline: none; border-color: var(--k2m-chat-primary); }
.k2m-prechat-field input.invalid { border-color: #e53935; background: #fff5f5; }
.k2m-prechat-error { color: #c62828; font-size: 12px; min-height: 14px; margin: 4px 0 8px; }
.k2m-prechat-submit {
  width: 100%; padding: 10px; border: none; border-radius: 6px;
  background: var(--k2m-chat-primary); color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.k2m-prechat-submit:hover { opacity: .9; }
.k2m-prechat-submit:disabled { background: #ccc; cursor: not-allowed; }
.k2m-prechat-legal { font-size: 10.5px; color: #999; margin-top: 10px; line-height: 1.45; }
