/* ============================================
   HEADER (chat-ui.css)
   ============================================ */
#popupHeader {
  height: var(--header-h);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #2a4d73 !important;
  color: #F3F4F6;
  font-weight: 700;
  font-size: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 10;
  touch-action: none !important;
}

#popupHeader .header-icons {
  display: flex;
  align-items: center;
  gap: 8px;
}

#popupHeader .hdr-icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

#popupHeader .hdr-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#popupHeader .hdr-icon-btn i {
  pointer-events: none;
  font-size: 18px;
}

/* --- HEADER MOBILE --- */
@media (max-width: 820px) {
  #popupHeader {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 70px !important;
    margin: 0 !important;
    padding: 0 16px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    background: #2a4d73 !important;
    z-index: 100 !important;
    touch-action: none !important;
    box-sizing: border-box !important;
  }
}

/* ============================================
   CHATBOX & MESSAGES
   ============================================ */
#chatContentArea {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: #ffffff !important;
}

#chatScrollArea {
  flex: 1 1 auto;
  overflow-y: auto !important;
  padding: 24px 24px calc(140px + env(safe-area-inset-bottom)) 24px !important;
  box-sizing: border-box;
  background: #ffffff !important;
  -webkit-overflow-scrolling: touch !important;
  touch-action: pan-y !important;
  overscroll-behavior: none !important;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#chatScrollArea::-webkit-scrollbar {
  display: none;
}

#chatContainer {
  padding: 0 !important;
  box-sizing: border-box;
  height: auto;
  overflow: visible;
  max-width: 720px;
  margin: 0 auto;
}

#chatContainer::after {
  display: none !important;
}

.chat-entry {
  display: flex;
  justify-content: flex-end;
  margin: 16px 0;
  scroll-margin-top: 20px;
}

.chat-entry.bot {
  position: relative;
  padding-left: 0 !important;
  padding-top: 44px !important;
  margin-bottom: 32px;
  justify-content: flex-start;
  flex-direction: column;
  align-items: flex-start;
}

.chat-entry.bot::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  background-image: url('https://static.wixstatic.com/media/ba4616_885c99c666a14fd7a4deb062cd15ee6e~mv2.jpg');
  background-size: cover;
  background-position: center;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  border: 2px solid #ffffff;
  z-index: 5 !important;
}

.system-message {
  max-width: 100%;
  padding: 0 !important;
  background: transparent !important;
  font-size: 15.5px;
  line-height: 1.65;
  color: #1f2937;
}

.bot-action-bar {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s ease;
  align-self: flex-start;
}

.chat-entry.bot:hover .bot-action-bar {
  opacity: 1;
}

.bot-action-btn {
  background: transparent;
  border: none;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.bot-action-btn:hover {
  background: #f3f4f6;
  color: #111827;
}

.user-message {
  max-width: 80% !important;
  margin: 0;
  padding: 16px 44px 16px 20px !important;
  border-radius: 24px;
  background: #f3f4f6 !important;
  color: var(--txt);
  font-size: 15.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  align-self: flex-end;
  position: relative;
  transition: all 0.3s ease;
}

.user-message p {
  margin-bottom: 12px !important;
  display: block;
}

.user-message .msg-text p:last-child {
  margin-bottom: 0 !important;
}

.user-message .msg-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  box-orient: vertical;
  overflow: hidden;
  -webkit-line-clamp: unset;
}

.user-message.is-collapsed .msg-text {
  -webkit-line-clamp: 3;
}

.msg-toggle-btn {
  display: none;
  position: absolute;
  top: 12px;
  right: 10px;
  width: 32px;
  height: 32px;
  background: transparent;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #4b5563;
  transition: background 0.2s, transform 0.3s ease;
}

.msg-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.user-message.has-toggle .msg-toggle-btn {
  display: flex;
}

.user-message.has-toggle:not(.is-collapsed) .msg-toggle-btn svg {
  transform: rotate(180deg);
}

.msg-tools {
  position: absolute;
  right: 14px;
  bottom: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-in-out;
  z-index: 10;
}

.user-message:hover .msg-tools {
  opacity: 1;
  pointer-events: auto;
}

.msg-icon {
  font-size: 14px;
  cursor: pointer;
  opacity: 0.7;
}

.msg-icon:hover {
  opacity: 1;
}

.msg-text {
  pointer-events: auto !important;
}

/* Chat Markdown Styles */
.system-message :is(h1, h2, h3) {
  font-weight: 700;
  line-height: 1.2;
  margin: 22px 0 12px;
  color: #111827;
}

.system-message h1 {
  font-size: 20px;
}

.system-message h2 {
  font-size: 18px;
}

.system-message h3 {
  font-size: 16px;
}

.system-message p {
  margin: 0 0 14px;
}

.system-message>p:nth-of-type(-n+3) {
  text-indent: 1em;
}

.system-message :is(ul, ol) {
  margin: 0 0 16px 24px;
  padding-left: 12px;
}

.system-message li {
  margin: 6px 0;
}

:where(#chatContainer, .system-message) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

:where(#chatContainer, .system-message) table {
  width: 100% !important;
  margin: 16px 0 !important;
  display: table !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  overflow: hidden;
  font-size: 14px;
}

#chatContainer .system-message table,
#chatContainer .system-message table * {
  border-style: solid !important;
  border-color: rgba(0, 0, 0, 0.06) !important;
}

:where(#chatContainer, .system-message) th,
:where(#chatContainer, .system-message) td {
  padding: 10px 12px !important;
  vertical-align: top;
  border-width: 0 !important;
  border-right-width: 1px !important;
  border-bottom-width: 1px !important;
}

:where(#chatContainer, .system-message) thead th {
  background: #f9fafb !important;
  font-weight: 700 !important;
  color: #374151;
}

:where(#chatContainer, .system-message) tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

/* Loaders & Spinners */
.edit-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  margin: 0 auto 10px auto;
  border-radius: 12px;
  font-size: 12px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  max-width: 800px;
  pointer-events: auto;
}

.edit-info button {
  border: none;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  background: #fcd34d;
  color: #78350f;
  font-weight: 600;
}

/* Kalıntı temizlendi: finly-waiting -> app-waiting-spinner */
.app-waiting-spinner {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding-left: 4px;
  font-size: 13px;
  font-style: italic;
  color: #6b7280;
}

.app-waiting-spinner .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  animation: appBlink 1.4s infinite ease-in-out both;
}

.app-waiting-spinner .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.app-waiting-spinner .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes appBlink {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

/* Kalıntı temizlendi: fc-loader-inner -> app-loader-inner */
.app-loader-inner {
  width: min(520px, calc(100vw - 48px));
  padding: 28px 22px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.12);
  display: grid;
  justify-items: center;
  gap: 14px;
}

/* Kalıntı temizlendi: fc-loader-spinner -> app-loader-spinner */
.app-loader-spinner {
  width: 92px;
  height: 92px;
  border-radius: 999px;
  border: 10px solid rgba(29, 62, 47, 0.1);
  border-top-color: var(--brand);
  animation: appSpin 0.9s linear infinite;
}

@keyframes appSpin {
  to { transform: rotate(360deg); }
}

/* --- CHATBOX & MESSAGES MOBILE --- */
@media (max-width: 820px) {
  #chatContentArea,
  #chatContainer {
    background-color: #ffffff !important;
  }

  #chatContentArea {
    width: 100% !important;
    height: 100% !important;
    position: relative !important;
    overflow: hidden !important;
    background: #ffffff !important;
    transition: transform 0.3s ease;
  }

  #chatContentArea.reduced {
    transform: translateX(80vw);
  }

  #chatScrollArea {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding: 16px 16px calc(140px + env(safe-area-inset-bottom)) 16px !important;
    box-sizing: border-box !important;
    background: #ffffff !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior: none !important;
  }

  #popupPanel.active~#chatContentArea #chatScrollArea,
  #chatContentArea.reduced #chatScrollArea {
    overflow: hidden !important;
    touch-action: none !important;
    pointer-events: none;
  }

  .system-message {
    font-size: 15px !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  .user-message {
    font-size: 15px !important;
    padding: 14px 40px 14px 16px !important;
    max-width: 85% !important;
    border-radius: 20px;
  }
}

/* ============================================
   INPUT BOX
   ============================================ */
#messageInputContainer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 24px 32px 24px;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 1) 50%);
  z-index: 5;
  pointer-events: none;
  touch-action: none !important;
}

.message-box {
  display: flex;
  align-items: flex-end;
  padding: 12px 12px 12px 20px;
  border-radius: 24px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  pointer-events: auto;
}

.chat-input-div {
  display: block !important;
  width: 100% !important;
  cursor: text !important;
  -webkit-user-select: text !important;
  user-select: text !important;
  pointer-events: auto !important;
  outline: none !important;
  box-shadow: none !important;
}

.chat-input-div:empty:before {
  content: attr(data-placeholder);
  color: #9ca3af;
  pointer-events: none;
  display: block;
  font-style: normal;
}

.chat-input-div:focus:before {
  content: "" !important;
}

.message-box .chat-input-div {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  margin-right: 14px !important;
  box-sizing: border-box;
  line-height: 22px;
  padding: 16px 0;
  min-height: 88px;
  max-height: 200px;
  overflow-y: auto !important;
  touch-action: pan-y !important;
  overscroll-behavior: none !important;
  resize: none;
  border: none;
  background: transparent;
  white-space: pre-wrap;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  font-size: 15.5px;
}

.message-box button {
  border: none;
  background: none;
  font-size: 18px;
  color: #d1d5db;
  cursor: not-allowed;
  margin-bottom: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
  flex-shrink: 0 !important;
}

.message-box button.enabled {
  color: #ffffff;
  background: var(--brand);
  cursor: pointer;
}

/* --- INPUT BOX MOBILE --- */
@media (max-width: 820px) {
  #messageInputContainer {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    background: #ffffff !important;
    border-top: none !important;
    padding: 0 !important;
    z-index: 9999 !important;
    box-sizing: border-box !important;
    transition: none !important;
  }

  #messageInputContainer::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 50vh;
    background: #F3F4F6 !important;
    z-index: -1;
  }

  .message-box {
    width: 100% !important;
    max-width: 100% !important;
    background: #F3F4F6 !important;
    border: none !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05) !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom)) 20px !important;
    gap: 12px !important;
    box-sizing: border-box !important;
  }

  #messageInputContainer .message-box .chat-input-div {
    font-size: 16px !important;
    min-height: 24px !important;
    height: auto !important;
    max-height: 120px !important;
    display: block !important;
    text-align: left !important;
    width: 100% !important;
    background: transparent !important;
    outline: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .chat-input-div:empty:before {
    font-size: 16px !important;
    display: block !important;
    position: static !important;
    text-align: left !important;
    color: #6b7280 !important;
  }

  #sendButton,
  .message-box button {
    position: relative !important;
    align-self: flex-end !important;
    margin: 0 !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 999px !important;
    background: transparent !important;
    border: 1px solid #d1d5db !important;
    color: #4b5563 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
  }

  .message-box button.enabled {
    background: #e8f0fe !important;
    border-color: transparent !important;
    color: var(--brand) !important;
  }
}