/* Google Fonts - Poppins */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&family=JetBrains+Mono&display=swap");

:root {
  --panel-bg: rgba(22, 27, 34, 0.9);
  --panel-border: rgba(100, 100, 100, 0.4);
  --history-bg: rgba(13, 17, 23, 0.95);
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --accent-primary: #58a6ff;
  --user-bubble-bg: linear-gradient(135deg, #1f6feb, #58a6ff);
  --ai-bubble-bg: #21262d;
  --code-bg: #0d1117;
}

/* Mobil cihazda panel açılanda arxa fonun scroll olmasını əngəlləyir */
body.ai-panel-open-mobile {
  overflow: hidden;
}

/* --- Widget Düyməsi --- */
#ai-widget-button {
  position: fixed;
  bottom: 25px;
  right: 25px;
  z-index: 10000;
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(88, 166, 255, 0.4);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}
#ai-widget-button:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: 0 10px 30px rgba(88, 166, 255, 0.5);
}
#ai-widget-button svg {
  width: 30px;
  height: 30px;
}
#ai-widget-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Əsas Panel --- */
#ai-panel {
  position: fixed;
  bottom: 25px;
  right: 25px;
  width: 600px;
  height: 80vh;
  min-height: 600px;
  max-height: 900px;
  max-width: calc(100vw - 40px);
  background: var(--panel-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: "Poppins", sans-serif;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: scale(0.95) translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
}
#ai-panel.open {
  display: flex;
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* --- Panel Başlığı --- */
#ai-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--panel-border);
  color: var(--text-primary);
  flex-shrink: 0;
}
#ai-panel-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.header-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-buttons button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  transition: color 0.2s;
  padding: 5px;
  line-height: 1;
}
.header-buttons button:hover {
  color: var(--text-primary);
}
#ai-menu-toggle svg {
  width: 22px;
  height: 22px;
}

/* --- Panel Kontenti --- */
#ai-panel-content {
  position: relative;
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Tarixçə Paneli --- */
#ai-history {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 100%;
  background: var(--history-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 10;
}
#ai-history.open {
  transform: translateX(0);
}
#ai-history-header {
  padding: 15px 10px;
  border-bottom: 1px solid var(--panel-border);
}
#ai-new-chat {
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px;
  width: 100%;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}
#ai-new-chat:hover {
  background: #4a91e2;
}
#ai-history-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 5px 0;
}
.history-item {
  padding: 12px 15px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  transition: background-color 0.2s, color 0.2s;
}
.history-item:hover {
  background: var(--panel-bg);
  color: var(--text-primary);
}
.history-item.active {
  background: var(--accent-primary);
  color: white;
  font-weight: 500;
}
.delete-chat {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: none;
  opacity: 0.7;
  font-size: 20px;
  line-height: 1;
  padding: 2px 5px;
}
.history-item:hover .delete-chat {
  display: inline;
}
.delete-chat:hover {
  opacity: 1;
  color: #ff6b6b;
}

/* --- Söhbət Pəncərəsi --- */
#ai-chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
}
#ai-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* --- Mesaj Stili --- */
.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: popIn 0.3s ease-out forwards;
}

.user-message-wrapper {
  align-self: flex-end;
}

.ai-message-wrapper {
  align-self: flex-start;
}

.message-bubble {
  line-height: 1.6;
  font-size: 15px;
  overflow-wrap: break-word;
  word-break: break-word;
}
@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.user-message {
  align-self: flex-end;
  background: var(--user-bubble-bg);
  color: white;
  padding: 12px 18px;
  border-radius: 20px 20px 5px 20px;
}
.ai-message {
  align-self: flex-start;
  background: var(--ai-bubble-bg);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: 20px 20px 20px 5px;
  /* Yazı animasiyası üçün kursorun rəngi */
  color-scheme: light;
}

/* --- İSTƏK 1: YÜKLƏMƏ ANİMASİYASI ÜÇÜN YENİ STİLLƏR --- */
.ai-message.thinking {
  background: transparent;
  padding: 0;
}

/* --- İSTƏK 2: LOADER ÖLÇÜSÜ DƏYİŞDİ --- */
.loader-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px; /* 80px idi */
  height: 48px; /* 80px idi */
}

.spinning-loader {
  position: absolute;
  width: 42px; /* 70px idi */
  height: 42px; /* 70px idi */
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    var(--accent-primary),
    #ff6b6b,
    #6bff6b,
    #ffeb3b,
    var(--accent-primary)
  );
  animation: spin 1.5s linear infinite;
}

.spinning-loader::before {
  content: "";
  position: absolute;
  top: 4px; /* 6px idi */
  left: 4px; /* 6px idi */
  right: 4px; /* 6px idi */
  bottom: 4px; /* 6px idi */
  background: var(--ai-bubble-bg);
  border-radius: 50%;
}

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

.loader-logo {
  position: absolute;
  color: var(--accent-primary);
}

.loader-logo svg {
  width: 18px; /* 30px idi */
  height: 18px; /* 30px idi */
}
/* --- DƏYİŞİKLİKLƏR BİTDİ --- */

.ai-message p {
  margin: 0 0 10px 0;
}
.ai-message p:last-child {
  margin-bottom: 0;
}

.message-bubble ul,
.message-bubble ol {
  margin-top: 10px;
  margin-bottom: 10px;
  padding-left: 25px;
}
.message-bubble li {
  margin-bottom: 5px;
}

/* --- Mesaj Kopyalama Düyməsi --- */
.copy-message-btn {
  background: none;
  border: 1px solid var(--panel-border);
  color: var(--text-secondary);
  cursor: pointer;
  align-self: flex-end;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
  opacity: 0;
}
.message-wrapper:hover .copy-message-btn {
  opacity: 0.7;
}
.copy-message-btn:hover {
  opacity: 1;
  background: var(--ai-bubble-bg);
  color: var(--text-primary);
}
.copy-message-btn svg {
  width: 13px;
  height: 13px;
}

/* --- Vurğulanan Mətn Stili --- */
.ai-message strong {
  background-color: rgba(88, 166, 255, 0.2);
  color: #adefff;
  padding: 2px 6px;
  border-radius: 5px;
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}

/* --- Kod Bloku Stili --- */
.code-block {
  background: var(--code-bg);
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  margin: 10px 0;
  overflow: hidden;
}
.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #21262d;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.code-block-header button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
}
.code-block-header button:hover {
  color: white;
}
.code-block-header button svg {
  width: 14px;
  height: 14px;
}
.code-block pre {
  margin: 0;
}
.code-block pre code {
  font-family: "JetBrains Mono", monospace;
  display: block;
  padding: 15px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: #a5d6ff;
}

/* --- Mesaj Yazma Sahəsi --- */
#ai-input-container {
  padding-top: 15px;
  padding-bottom: 10px;
  border-top: 1px solid var(--panel-border);
  background: var(--history-bg);
  flex-shrink: 0;
}

#ai-input-area {
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 10px;
}

#ai-powered-by {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 10px;
}

#ai-input {
  flex: 1;
  background: var(--ai-bubble-bg);
  border: 1px solid var(--panel-border);
  color: white;
  padding: 12px 18px;
  border-radius: 25px;
  font-size: 15px;
  transition: border-color 0.2s;
  resize: none;
  max-height: 100px;
}
#ai-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}
#ai-input:disabled {
  background-color: #333;
  cursor: not-allowed;
}

/* --- İSTƏK 1: STOP DÜYMƏSİ STİLİ --- */
#ai-stop {
  background: #ff6b6b; /* Qırmızı rəng */
  border: none;
  color: white;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; /* JS tərəfindən idarə olunur */
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
#ai-stop:hover {
  background: #e05252;
  transform: scale(1.1);
}
#ai-stop svg {
  width: 20px; /* Bir az daha kiçik kvadrat */
  height: 20px;
}

#ai-send {
  background: var(--accent-primary);
  border: none;
  color: white;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
#ai-send:hover {
  background: #4a91e2;
  transform: scale(1.1);
}
#ai-send:disabled {
  background-color: #555;
  cursor: not-allowed;
  transform: scale(1);
}
#ai-send svg {
  width: 22px;
  height: 22px;
}

/* --- Scrollbar Stili --- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* --- Mobil Uyğunluq --- */
@media (max-width: 768px) {
  #ai-panel {
    width: 100% !important;
    height: 100% !important;
    bottom: 0 !important;
    right: 0 !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(22, 27, 34, 0.98);
  }
}
