/* =========================================================
   CHATBOT — Direction C
   ========================================================= */
.chat-fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 20px;
  z-index: 9999;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: var(--sh-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  -webkit-user-select: none;
  user-select: none;
  color: #fff;
}
.chat-fab:active { transform: scale(0.92); }
.chat-fab.chat-open { transform: scale(0) rotate(180deg); opacity: 0; pointer-events: none; }

.chat-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  background: var(--danger);
  border: 2px solid var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: var(--w-bold);
  color: #fff;
  opacity: 0;
  transform: scale(0);
  transition: transform var(--dur-base) var(--ease-out), opacity var(--dur-base) var(--ease-out);
  font-variant-numeric: tabular-nums;
}
.chat-fab-badge.visible { opacity: 1; transform: scale(1); }

.chat-window {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 10000;
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 580px;
  background: var(--surface);
  border: 1px solid var(--line-1);
  border-bottom: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--sh-4);
  display: flex;
  flex-direction: column;
  transform: translateY(105%);
  transition: transform 0.35s cubic-bezier(0.22,1,0.36,1);
  overflow: hidden;
}
.chat-window.chat-open { transform: translateY(0); }

.chat-window-header {
  background: var(--surface);
  padding: calc(var(--safe-top) + 12px) 14px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line-1);
}
.chat-window-header-left { display: flex; flex-direction: column; gap: 2px; }
.chat-window-title {
  font-size: var(--t-15);
  font-weight: var(--w-semibold);
  color: var(--ink-1);
  letter-spacing: -0.01em;
}
.chat-window-status {
  font-size: var(--t-10);
  color: var(--ok);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-window-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  display: inline-block;
}
.chat-window-actions { display: flex; align-items: center; gap: 6px; }

.chat-btn-reset,
.chat-btn-close {
  background: var(--surface);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease);
  -webkit-user-select: none;
  user-select: none;
}
.chat-btn-reset { font-size: 14px; }
.chat-btn-close { font-size: 16px; font-weight: var(--w-semibold); line-height: 1; }
.chat-btn-reset:hover,
.chat-btn-close:hover { background: var(--surface-2); }
.chat-btn-reset:active,
.chat-btn-close:active { background: var(--surface-sunken); }

.chat-window-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.chat-window-messages::-webkit-scrollbar { width: 3px; }
.chat-window-messages::-webkit-scrollbar-track { background: transparent; }
.chat-window-messages::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }

.chat-msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: var(--r-md);
  font-size: var(--t-13);
  line-height: 1.45;
  word-wrap: break-word;
  animation: msgIn 0.2s var(--ease-out);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-bot {
  background: var(--surface);
  color: var(--ink-1);
  border: 1px solid var(--line-1);
  align-self: flex-start;
  border-bottom-left-radius: var(--r-xs);
}
.chat-msg-user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: var(--r-xs);
}
.chat-msg-typing {
  background: var(--surface);
  border: 1px solid var(--line-1);
  align-self: flex-start;
  border-bottom-left-radius: var(--r-xs);
  padding: 11px 14px;
}

.typing-dots { display: flex; gap: 5px; align-items: center; }
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-4);
  animation: bounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.chat-window-input-area {
  padding: 10px 10px calc(10px + var(--safe-bottom));
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--surface);
  border-top: 1px solid var(--line-1);
  flex-shrink: 0;
}

.chat-window-input {
  flex: 1;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 9px 12px;
  font-size: var(--t-14);
  font-family: inherit;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  color: var(--ink-1);
  background: var(--surface);
  resize: none;
  max-height: 100px;
  line-height: 1.4;
}
.chat-window-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chat-window-input::placeholder { color: var(--ink-4); }

.chat-btn-send {
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
}
.chat-btn-send:active:not(:disabled) { transform: scale(0.92); }
.chat-btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== CHATBOT LINK COPY BUTTON ===== */
.chat-link-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 4px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--accent);
  word-break: break-all;
}

.chat-link-block a {
  color: var(--accent) !important;
  text-decoration: underline;
  font-size: var(--t-12);
  font-weight: var(--w-medium);
  line-height: 1.4;
  word-break: break-all;
}

.chat-link-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: var(--t-11);
  font-weight: var(--w-semibold);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
}

.chat-link-copy-btn svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.chat-link-copy-btn:active { transform: scale(0.94); }

.chat-link-copy-btn.copied {
  background: var(--ok);
  border-color: var(--ok);
  animation: copyPop 0.3s var(--ease-out);
}

@keyframes copyPop {
  0%   { transform: scale(0.94); }
  50%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@media (prefers-color-scheme: dark) {
  .chat-window { background: var(--surface); border-color: var(--line-1); }
  .chat-window-header { background: var(--surface); border-bottom-color: var(--line-1); }
  .chat-msg-bot { background: var(--surface); border-color: var(--line-1); color: var(--ink-1); }
  .chat-msg-typing { background: var(--surface); border-color: var(--line-1); }
  .chat-window-messages { background: var(--bg); }
  .chat-window-input-area { background: var(--surface); border-top-color: var(--line-1); }
  .chat-window-input { background: var(--surface); color: var(--ink-1); border-color: var(--line-2); }
  .chat-link-block { background: var(--accent-soft); border-left-color: var(--accent); }
  .chat-link-block a { color: var(--accent) !important; }
}
