/* === Modern Chat Widget (drop-in replacement) === */
/* Design goals:
   - Mobile-first, full-screen sheet with safe-area insets
   - Desktop: floating card with glassy look
   - Smooth open/close feel (even if JS sadece display toggle yapıyorsa)
   - A11y: focus states, large touch targets, prefers-reduced-motion
   - Dark mode support (prefers-color-scheme) */

:root {
  --c-bg: #0b1020;
  --c-surface: #0f172a;
  --c-surface-2: #111827;
  --c-text: #e5e7eb;
  --c-subtle: #9ca3af;
  --c-primary: #2563eb;
  --c-border: #1f2937;
  --c-ring: rgba(37, 99, 235, .45);

  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 10px;

  --shadow-1: 0 10px 30px rgba(0,0,0,.25);
  --shadow-2: 0 20px 60px rgba(0,0,0,.35);

  --fw-semibold: 600;
  --fw-bold: 700;

  --gap: 10px;
  --pad: 12px;

  --bot-bg: #0b1224;
  --me-bg: #2563eb;
  --me-text: #ffffff;

  --launcher-size: 56px;
}

/* Light mode fallback (explicit) */
@media (prefers-color-scheme: light) {
  :root {
    --c-bg: #f8fafc;
    --c-surface: #ffffff;
    --c-surface-2: #f3f4f6;
    --c-text: #111827;
    --c-subtle: #6b7280;
    --c-primary: #2563eb;
    --c-border: #e5e7eb;
    --c-ring: rgba(37, 99, 235, .35);

    --bot-bg: #ffffff;
    --me-bg: #2563eb;
    --me-text: #ffffff;
  }
}

/* Smoothen fonts slightly */
.chat-wrap, .chat-launcher, .bubble, .chat-input input, .chat-input button {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === Launcher Button === */
.chat-launcher{
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 9998;

  display: inline-grid;
  place-items: center;
  width: var(--launcher-size);
  height: var(--launcher-size);

  border: none;
  border-radius: 999px;
  cursor: pointer;

  background: linear-gradient(180deg, var(--c-primary), #1745b5);
  color: #fff;
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-1);
  transition: transform .15s ease, box-shadow .2s ease, opacity .2s ease;
}
.chat-launcher:hover { transform: translateY(-1px) scale(1.02); box-shadow: var(--shadow-2); }
.chat-launcher:active { transform: scale(.98); }
.chat-launcher:focus { outline: none; box-shadow: 0 0 0 4px var(--c-ring), var(--shadow-2); }

/* === Wrapper / Card === */
.chat-wrap{
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(var(--launcher-size) + 20px);
  width: min(380px, calc(100vw - 24px));
  max-height: min(72vh, 640px);

  display: none;       /* JS açık/kapalı yönetiyor */
  flex-direction: column;

  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  backdrop-filter: saturate(120%) blur(6px);

  animation: chat-pop .18s ease-out both;
}

@keyframes chat-pop {
  from { transform: translateY(6px) scale(.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* === Header === */
.chat-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;

  background: linear-gradient(180deg, var(--c-surface-2), var(--c-surface));
  color: var(--c-text);
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
}
.chat-header .title{
  font-weight: var(--fw-bold);
  font-size: 14px;
  letter-spacing: .2px;
}
.chat-header .sub{
  font-size: 12px;
  color: var(--c-subtle);
  margin-top: 2px;
}
.chat-close{
  background: transparent;
  color: var(--c-text);
  border: 1px solid var(--c-border);
  width: 34px; height: 34px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.chat-close:hover{ background: var(--c-surface-2); transform: scale(1.02); }
.chat-close:active{ transform: scale(.96); }
.chat-close:focus{ outline: none; box-shadow: 0 0 0 3px var(--c-ring); }

/* === Body / Messages === */
.chat-body{
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  overflow-y: auto;
  height: 48vh;
  background:
    radial-gradient(1200px 300px at 80% -10%, rgba(37,99,235,.08), transparent 60%),
    var(--c-surface-2);
  scrollbar-width: thin;
  scrollbar-color: var(--c-border) transparent;
}
.chat-body::-webkit-scrollbar { width: 10px; }
.chat-body::-webkit-scrollbar-thumb {
  background: var(--c-border);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

/* Bubbles */
.bubble{
  max-width: 78%;
  width: fit-content;
  padding: 10px 12px;
  border-radius: 14px;
  margin: 4px 0;
  line-height: 1.4;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
  border: 1px solid var(--c-border);
  background: var(--bot-bg);
  color: var(--c-text);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.bubble.bot { background: var(--bot-bg); }
.bubble.me {
  margin-left: auto;
  background: var(--me-bg);
  color: var(--me-text);
  border-color: transparent;
}

/* Message tails (subtle) */
.bubble.bot::after,
.bubble.me::after{
  content: "";
  position: absolute;
  bottom: -2px;
  width: 10px; height: 10px;
  transform: rotate(45deg);
}
.bubble.bot::after{
  left: 12px;
  background: var(--bot-bg);
  border-left: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
}
.bubble.me::after{
  right: 12px;
  background: var(--me-bg);
}

/* Typing indicator */
.typing{
  font-size: 12px;
  color: var(--c-subtle);
  margin: 6px 4px 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.typing::after{
  content: "•••";
  letter-spacing: 2px;
  animation: dots 1.1s infinite steps(3, end);
}
@keyframes dots {
  0% { opacity: .3; }
  50% { opacity: 1; }
  100% { opacity: .3; }
}

/* === Input Area === */
.chat-input{
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--c-border);
  background: linear-gradient(180deg, var(--c-surface), var(--c-surface-2));
}
.chat-input input{
  flex: 1;
  padding: 12px 12px;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.chat-input input::placeholder{ color: var(--c-subtle); }
.chat-input input:focus{
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-ring);
  background: color-mix(in srgb, var(--c-surface) 92%, var(--c-primary));
}

.chat-input button{
  min-width: 96px;
  padding: 12px 14px;
  background: linear-gradient(180deg, var(--c-primary), #1e50c2);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, filter .15s ease;
  box-shadow: 0 8px 18px rgba(37,99,235,.25);
}
.chat-input button:hover{ transform: translateY(-1px); box-shadow: 0 12px 26px rgba(37,99,235,.35); }
.chat-input button:active{ transform: translateY(0); filter: brightness(.96); }
.chat-input button:focus{ outline: none; box-shadow: 0 0 0 4px var(--c-ring); }

/* === Mobile: Full-screen sheet === */
@media (max-width: 600px){
  .chat-wrap{
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .chat-header{
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .chat-input{
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .chat-body{
    height: auto;
    min-height: 0;
    flex: 1 1 auto;
    background:
      radial-gradient(1200px 300px at 70% -10%, rgba(37,99,235,.10), transparent 60%),
      var(--c-surface-2);
  }
  .chat-launcher{
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  .bubble{ max-width: 86%; font-size: 15px; }
  .chat-input button{ min-width: 84px; }
}

/* === High-contrast / Reduced motion === */
@media (prefers-reduced-motion: reduce){
  * { animation: none !important; transition: none !important; }
}

/* Optional: pressed states better on touch */
@media (hover: none){
  .chat-launcher:hover,
  .chat-close:hover,
  .chat-input button:hover { transform: none; }
}
