:root {
  --bg-main: #0a0a0f;
  --bg-chat: rgba(18, 18, 24, 0.85);
  --bg-user: #3b82f6;
  --bg-assistant: rgba(39, 39, 42, 0.9);
  --text-main: #f3f4f6;
  --text-secondary: #a1a1aa;
  --accent: #3b82f6;
  --border: rgba(59, 130, 246, 0.2);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius: 14px;
}

body {
  font-family: "Segoe UI", "Arial", sans-serif;
  background: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #0a0a0f 100%);
  color: var(--text-main);
  width: 100vw;
  height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(2.5px 2.5px at 40px 70px, rgba(255, 255, 255, 0.9), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 50px 160px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 90px 40px, rgba(255, 255, 255, 0.8), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 130px 80px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 160px 120px, rgba(255, 255, 255, 0.7), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 200px 50px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 250px 90px, rgba(255, 255, 255, 0.85), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 300px 140px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 350px 60px, rgba(255, 255, 255, 0.75), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 400px 100px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 450px 170px, rgba(255, 255, 255, 0.8), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 500px 30px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 550px 80px, rgba(255, 255, 255, 0.7), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 600px 130px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(3px 3px at 100px 200px, rgba(59, 130, 246, 0.8), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 300px 250px, rgba(139, 92, 246, 0.7), rgba(0, 0, 0, 0)),
    radial-gradient(2.5px 2.5px at 500px 300px, rgba(6, 182, 212, 0.8), rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 700px 150px, rgba(255, 255, 255, 0.9), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 150px 350px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 80px 450px, rgba(255, 255, 255, 0.85), rgba(0, 0, 0, 0)),
    radial-gradient(1.5px 1.5px at 250px 400px, rgba(236, 72, 153, 0.7), rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 400px 350px, #ffffff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 550px 450px, rgba(255, 255, 255, 0.8), rgba(0, 0, 0, 0)),
    radial-gradient(2.5px 2.5px at 650px 380px, rgba(34, 197, 94, 0.7), rgba(0, 0, 0, 0));
  background-repeat: repeat;
  background-size: 750px 500px;
  animation: twinkle 3s ease-in-out infinite, blink 1.5s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes twinkle {

  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.9);
  }

  50% {
    opacity: 0.9;
    transform: scale(1.1);
  }
}

@keyframes blink {
  0% {
    opacity: 0.2;
    filter: brightness(0.7);
  }

  50% {
    opacity: 1;
    filter: brightness(1.3);
  }

  100% {
    opacity: 0.4;
    filter: brightness(0.9);
  }
}

#stars-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

#shooting-stars {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

@keyframes starBlink {

  0%,
  100% {
    opacity: 0.2;
    transform: scale(0.8);
  }

  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

@keyframes shoot {
  0% {
    transform: translateX(0) translateY(0);
    opacity: 1;
  }

  70% {
    opacity: 1;
  }

  100% {
    transform: translateX(400px) translateY(200px);
    opacity: 0;
  }
}

@keyframes twinkle {

  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }
}

body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, transparent 0%, rgba(10, 10, 15, 0.4) 100%);
  pointer-events: none;
  z-index: 1;
}

#chat-container {
  display: flex;
  flex-direction: column;
  width: 95vw;
  max-width: 800px;
  height: 80vh;
  margin: 10vh auto;
  background: rgba(18, 18, 24, 0.9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 50px rgba(59, 130, 246, 0.2);
  overflow: hidden;
  border: 1px solid rgba(59, 130, 246, 0.3);
  position: relative;
  z-index: 10;
  transition: all 0.3s ease;
}

#chat-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg,
      #3b82f6 0%,
      #8b5cf6 25%,
      #06b6d4 50%,
      #8b5cf6 75%,
      #3b82f6 100%);
  background-size: 200% 100%;
  animation: shimmer 3s linear infinite;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  z-index: 2;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.6), 0 0 40px rgba(139, 92, 246, 0.4);
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

#header {
  padding: 18px 20px 10px 20px;
  background: transparent;
  text-align: center;
  font-size: 1.8rem;
  font-weight: bold;
  letter-spacing: 1px;
  text-shadow: 0 2px 8px #0006;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  z-index: 3;
}

#bot-name {
  background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899, #3b82f6);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 3s ease infinite;
  font-family: 'Segoe UI', Arial, sans-serif;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

#header svg,
#header #bot-icon {
  width: 32px;
  height: 32px;
  vertical-align: middle;
  filter: drop-shadow(0 2px 4px #0008);
  border-radius: 50%;
  object-fit: cover;
  display: inline-block;
}

#clear-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 5px;
  border-radius: 5px;
  transition: color 0.2s, background 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#clear-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  transform: scale(1.1);
}

#messages {
  flex: 1;
  padding: 30px 20px 40px 20px;
  overflow-y: auto;
  overflow-x: visible;
  background: var(--bg-chat);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--bg-chat);
  min-height: 0;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
  z-index: 1;
}

#messages::-webkit-scrollbar {
  width: 8px;
  background: var(--bg-chat);
}

#messages::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 8px;
}

.message {
  margin: 20px 4px;
  padding: 14px 20px;
  border-radius: 12px;
  display: block;
  width: fit-content;
  max-width: 95%;
  min-width: 60px;
  word-break: break-word;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  position: relative;
  animation: messageSlide 0.3s ease-out;
  user-select: text;
  pointer-events: auto;
  z-index: 1;
}

.message * {
  pointer-events: auto !important;
}

.message a,
.message a:visited,
.message a:hover,
.message a:active,
.message button {
  pointer-events: auto !important;
  cursor: pointer !important;
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message::after {
  content: "";
  display: block;
  clear: both;
}

.user {
  background: linear-gradient(90deg, var(--bg-user) 80%, #2563eb 100%);
  color: #fff;
  align-self: flex-end;
  text-align: right;
  border-bottom-right-radius: 4px;
  border-top-right-radius: 20px;
  border-top-left-radius: 20px;
  border-bottom-left-radius: 20px;
  margin-left: auto;
}

.assistant {
  background: var(--bg-assistant);
  color: var(--text-secondary);
  align-self: flex-start;
  text-align: left;
  border-bottom-left-radius: 4px;
  border-top-right-radius: 20px;
  border-top-left-radius: 20px;
  border-bottom-right-radius: 20px;
  margin-right: auto;
  max-width: 85%;
}

.image-container {
  position: relative;
  display: inline-block;
}

.image-container img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

.download-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  text-decoration: none;
  transition: background 0.2s;
  cursor: pointer;
}

.download-btn:hover {
  background: var(--accent);
}

.message-text {
  line-height: 1.6;
  white-space: pre-wrap;
}

.message-text strong {
  color: var(--accent);
}

.search-results {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  width: 100%;
  position: relative;
  z-index: 9999;
}

.search-results-title {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-results-title span {
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  position: relative;
  z-index: 9999;
}

.search-links-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 9999;
}

.search-link-item,
.search-link-card {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(30, 64, 175, 0.1)) !important;
  border: 1px solid rgba(59, 130, 246, 0.4) !important;
  border-radius: 10px;
  color: #60a5fa !important;
  text-decoration: none !important;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.25s ease !important;
  cursor: pointer !important;
  pointer-events: auto !important;
  position: relative;
  z-index: 99999 !important;
}

.search-link-item:hover,
.search-link-card:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(30, 64, 175, 0.2)) !important;
  transform: translateX(5px) scale(1.02) !important;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.35) !important;
}

.search-link-item:active,
.search-link-card:active {
  transform: translateX(3px) scale(1.01) !important;
}

.search-link-card {
  display: flex;
  align-items: center;
  padding: 12px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(139, 92, 246, 0.08));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 10px;
  text-decoration: none !important;
  color: var(--text-main) !important;
  transition: all 0.3s ease;
  pointer-events: auto !important;
  cursor: pointer !important;
  position: relative;
  z-index: 100;
  min-height: 60px;
}

.search-link-card:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(139, 92, 246, 0.15));
  border-color: rgba(59, 130, 246, 0.6);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.25);
}

.search-link-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 4px;
  min-width: 0;
}

.search-link-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #60a5fa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-link-url {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.search-arrow {
  font-size: 18px;
  color: #60a5fa;
  flex-shrink: 0;
}

.search-link-card:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(139, 92, 246, 0.2));
  border-color: rgba(59, 130, 246, 0.5);
  transform: translateX(8px) scale(1.02);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
}

.search-link-img {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.search-link-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.search-link-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #60a5fa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-link-url {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.search-arrow {
  font-size: 18px;
  color: #60a5fa;
  flex-shrink: 0;
}

.search-link-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-link-icon {
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

#input-container {
  display: flex;
  border-top: 1px solid var(--border);
  background: #1e1e23;
  padding: 10px 12px;
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 5;
}

#input-container input,
#input-container textarea {
  flex: 2;
  border: none;
  padding: 12px 14px;
  font-size: 0.95rem;
  border-radius: 8px;
  background: #23232a;
  color: var(--text-main);
  outline: none;
  transition: background 0.2s;
  box-shadow: 0 2px 8px #0002;
  resize: none;
  overflow-y: auto;
  min-height: 45px;
  max-height: 200px;
  font-family: inherit;
  line-height: 1.4;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) #23232a;
}

#input-container textarea {
  height: auto;
}

#input-container textarea::-webkit-scrollbar {
  width: 6px;
}

#input-container textarea::-webkit-scrollbar-track {
  background: #23232a;
  border-radius: 3px;
}

#input-container textarea::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 3px;
}

#input-container input:focus,
#input-container textarea:focus {
  background: #18181b;
  border: 1px solid var(--accent);
}

#upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

#upload-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent);
  transform: scale(1.1);
}

#input-container button {
  padding: 0 22px;
  border: none;
  background: linear-gradient(90deg, var(--accent), #f59e42);
  color: #fff;
  font-weight: bold;
  font-size: 1.08rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px #0002;
  transition: background 0.2s, transform 0.1s;
  outline: none;
}

/* Login Styles */
#login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
}

.login-card {
  background: rgba(18, 18, 24, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow), 0 0 40px rgba(59, 130, 246, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  max-width: 90%;
  width: 400px;
}

.login-logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  margin-bottom: 5px;
}

.login-card h1 {
  margin: 0;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 2rem;
}

.login-card p {
  color: var(--text-secondary);
  margin: 0 0 10px 0;
}

.login-note {
  font-size: 0.8rem !important;
  color: #ef4444 !important;
  max-width: 300px;
  margin-top: 15px !important;
}

#header {
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  width: 60px;
}

#user-profile-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--accent);
}

.bot-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
}

.header-actions {
  display: flex;
  gap: 15px;
  align-items: center;
  width: auto;
  justify-content: flex-end;
}

#logout-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform 0.2s, color 0.2s;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#logout-btn:hover {
  transform: scale(1.1);
  color: #ef4444;
}

#input-container button:hover {
  background: linear-gradient(90deg, #f59e42, var(--accent));
  transform: scale(1.04);
}

@media (max-width: 900px) {
  #chat-container {
    max-width: 100vw;
    width: 100vw;
    height: 100dvh;
    /* Dynamic viewport height to handle keyboard resize better */
    margin: 0;
    border-radius: 0;
    border: none;
  }

  #header {
    padding: 15px 20px;
  }

  #messages {
    padding: 25px 20px;
    flex-grow: 1;
    overflow-y: auto;
  }

  #input-container {
    padding: 15px 20px 30px 20px;
    /* Extra bottom padding for mobile safe area */
  }
}

@media (max-width: 600px) {
  #header {
    padding: 12px 15px;
  }

  #messages {
    padding: 20px 12px;
  }

  #input-container {
    padding: 10px 12px 25px 12px;
  }
}