/* styles.css */

/* CSS Variables for Easy Theming */
:root {
  --color-background: rgba(18, 18, 18, 0.404);
  --color-sidebar: rgba(30, 30, 30, 0.4); /* Added transparency for blur effect */
  --color-primary: #2962ff;
  --color-secondary: rgba(30, 30, 30, 0.6); /* Added transparency */
  --color-text: #ffffff;
  --color-message-user: rgb(48, 48, 48, 0.85);
  --color-message-bot: rgba(51, 51, 51, 0.8);
  --color-button-hover: #0039cb;
  --color-input-background: rgba(44, 44, 44, 0.8); /* Added transparency */
  --font-family: 'Inter', sans-serif;
  --border-radius: 15px;
  --transition-speed: 0.3s;
  --blur-amount: 10px;
  --background-gradient: url('https://images.unsplash.com/photo-1487621167305-5d248087c724?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D');
  --texture-overlay: url('https://www.transparenttextures.com/patterns/diagonal-stripes.png'); /* Example texture */
}

/* Global Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--background-gradient);
  color: var(--color-text);
  height: 100vh;
  overflow: hidden;
}

h1, h2 {
  margin: 0 0 10px 0;
  font-weight: 600;
}

p {
  margin: 0 0 10px 0;
  line-height: 1.5;
}

/* Container */
#container {
  display: flex;
  height: 95vh;
  overflow: hidden;
  position: relative;
  background-color: var(--color-background);
  background-image: var(--texture-overlay);
  background-size: cover;
  background-repeat: repeat;
  backdrop-filter: blur(var(--blur-amount));
  border-radius: 20px;
  backdrop-filter: blur(10px);
  margin: 20px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}

/* Sidebar */
#sidebar {
  width: 20%;
  background-color: var(--color-sidebar);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-speed) ease-in-out;
  backdrop-filter: blur(var(--blur-amount));
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

#tab-selector {
  display: flex;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}


.tab {
  flex: 1;
  padding: 20px;
  background-color: transparent;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  font-size: 16px;
  transition: background-color var(--transition-speed), color var(--transition-speed);
  backdrop-filter: blur(5px);
}

.tab.active,
.tab:hover {
  background-color: var(--color-secondary);
  color: #ffffff;
}

#tab-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.content {
  display: none;
}

.content.active {
  display: block;
}

/* Chat Area */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(18, 18, 18, 0.7); /* Slight transparency */
  backdrop-filter: blur(5px);
}

/* Chat Header */
#chat-header {
  background-color: transparent;
  color: var(--color-text);
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;}

#chat-header h1 {
  font-size: 24px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Chat History */
#chat-history {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: transparent;
  background-image: var(--texture-overlay);
  background-size: cover;
  background-repeat: repeat;
}

.message {
  margin-bottom: 20px;
  display: flex;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  justify-content: flex-end;
}

.message.bot {
  justify-content: flex-start;
}

.text {
  padding: 16px 20px;
  border-radius: 20px;
  min-width: 20%;
  max-width: 70%;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1),
              inset 0 1px 0 rgba(255,255,255,0.1);
  white-space: pre-wrap;
  transition: transform 0.2s ease;
}

.text:hover {
  transform: translateY(-2px);
}

.message.user .text {
  background: linear-gradient(135deg, var(--color-message-user), rgba(48, 48, 48, 0.95));
  color: #ffffff;
  border-bottom-right-radius: 4px;
  margin-left: 40px;
}

.message.bot .text {
  background: linear-gradient(135deg, var(--color-message-bot), rgba(51, 51, 51, 0.9));
  color: var(--color-text);
  border-bottom-left-radius: 4px;
  margin-right: 40px;
}

.text pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 8px;
  margin: 8px 0;
  font-family: 'Courier New', Courier, monospace;
}

.text p {
  margin: 0;
}
/* Chat Form */
#chat-form {
  display: flex;
  padding: 15px;
  background-color: var(--color-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
}

#chat-input {
  flex: 1;
  padding: 15px;
  font-size: 16px;
  border: none;
  border-radius: var(--border-radius);
  margin-right: 10px;
  background-color: var(--color-input-background);
  color: var(--color-text);
  transition: background-color var(--transition-speed);
}

#chat-input::placeholder {
  color: #888;
}

#chat-input:focus {
  outline: none;
  background-color: rgba(44, 44, 44, 0.9);
}

#chat-form button {
  padding: 15px 25px;
  font-size: 16px;
  background-color: var(--color-primary);
  border: none;
  border-radius: var(--border-radius);
  color: #ffffff;
  cursor: pointer;
  transition: background-color var(--transition-speed);
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#chat-form button:hover {
  background-color: var(--color-button-hover);
}

.model-selector {
  background: linear-gradient(to bottom, var(--color-input-background), rgba(44, 44, 44, 0.9));
  color: var(--color-text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  padding: 12px 20px;
  margin-right: 10px;
  min-width: 120px;
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition-speed);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: calc(100% - 12px) center;
  background-color: rgba(55, 55, 55, 0.9);
  padding-right: 35px;
}

.model-selector:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.model-selector:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(41, 98, 255, 0.3);
}

/* Instruction Items */
.instruction-item {
  background-color: rgba(44, 44, 44, 0.8);
  padding: 10px 15px;
  border-radius: var(--border-radius);
  margin-bottom: 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Memory Items */
#memory-content p {
  background-color: rgba(44, 44, 44, 0.8);
  padding: 10px 15px;
  border-radius: var(--border-radius);
  margin-bottom: 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.typing-indicator .dot {
  height: 8px;
  width: 8px;
  margin: 0 4px;
  background-color: var(--color-message-bot);
  border-radius: 50%;
  display: inline-block;
  animation: blink 1.4s infinite both;
}

.typing-indicator .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: 0 2px;
  background-color: #555;
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}

.status {
  font-size: 14px;
  color: #555;
}

@keyframes blink {
  0% {
    opacity: 0.2;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0.2;
  }
}

/* Hamburger Menu (Mobile) */
#hamburger-menu {
  display: none;
  position: fixed;
  top: 25px;
  left: 25px;
  padding: 12px;
  background: rgba(30, 30, 30, 0.7);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  z-index: 1001;
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: background-color var(--transition-speed);
}

#hamburger-menu:hover {
  background: rgba(40, 40, 40, 0.8);
}

#hamburger-menu span {
  display: block;
  width: 25px;
  height: 2px;
  margin: 4px 0;
  background-color: var(--color-text);
  border-radius: 1px;
  transition: all var(--transition-speed);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Action Buttons */
.action-button {
  padding: 10px 20px;
  background-color: var(--color-secondary);
  border: none;
  border-radius: var(--border-radius);
  color: #ffffff;
  cursor: pointer;
  transition: background-color var(--transition-speed);
  margin-bottom: 20px;
}

.action-button:hover {
  background-color: rgba(30, 30, 30, 0.8);
}

/* Instruction Form */
#instruction-form {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}

#instruction-input {
  padding: 10px;
  font-size: 14px;
  border: none;
  border-radius: var(--border-radius);
  margin-bottom: 10px;
  background-color: var(--color-input-background);
  color: var(--color-text);
  resize: vertical;
}

#instruction-input::placeholder {
  color: #888;
}

#instruction-input:focus {
  outline: none;
  background-color: rgba(44, 44, 44, 0.9);
}

#instruction-form button {
  align-self: flex-end;
  padding: 10px 20px;
  font-size: 14px;
  background-color: var(--color-secondary);
  border: none;
  border-radius: var(--border-radius);
  color: #ffffff;
  cursor: pointer;
  transition: background-color var(--transition-speed);
}

#instruction-form button:hover {
  background-color: rgba(30, 30, 30, 0.8);
}

/* Instructions List */
#instructions-list .instruction-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#instructions-list .instruction-item span {
  flex: 1;
  margin-right: 10px;
}

.edit-button,
.delete-button {
  padding: 5px 10px;
  background-color: transparent;
  border: 1px solid var(--color-primary);
  border-radius: var(--border-radius);
  color: var(--color-primary);
  cursor: pointer;
  transition: background-color var(--transition-speed), color var(--transition-speed);
  margin-left: 5px;
}

.edit-button:hover,
.delete-button:hover {
  background-color: var(--color-primary);
  color: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

table th {
  background-color: var(--color-primary);
  color: #ffffff;
  padding: 10px;
}

table td {
  background-color: rgba(44, 44, 44, 0.8);
  color: var(--color-text);
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

table tr:last-child td {
  border-bottom: none;
}

/* Styled ul to look like tables */
ul {
  width: 100%;
  list-style: none;
  padding: 0;
  margin-bottom: 20px;
  display: table;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 30%;
  height: auto;
}

code {
  border-radius: 4px;
}

/* Code block copy button */
.copy-button {
  position: absolute;
  top: 18px;
  right: 18px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
}

pre:hover .copy-button {
  opacity: 1;
}

.copy-button:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  transform: translateY(-1px);
}

.copy-button:active {
  transform: translateY(0);
}


.controls button {
  cursor: pointer;
  color: #ffffff;
  background-color: var(--color-secondary);
  border: none;
  border-radius: var(--border-radius);
  padding: 10px 12px;
  font-size: 12px;
  transition: background-color var(--transition-speed);
  margin: 2px;
}

.controls button:hover {
  background-color: rgba(30, 30, 30, 0.8);
}


/* Mobile Styles */
@media (max-width: 1500px) {
  #sidebar {
    position: fixed;
    width: 100%;
    height: 50vh; 
    bottom: -50vh;
    z-index: 1000;
    overflow-y: auto;
    transition: bottom 0.3s ease-in-out;
    visibility: hidden; /* Hide when not active */
  }
  
  #sidebar.active {
    bottom: 0;
    visibility: visible; /* Show when active */
  }

  #chat-area {
    margin-bottom: 0; /* No margin by default */
    transition: margin-bottom 0.3s ease-in-out;
  }
  
  #chat-area.sidebar-active {
    margin-bottom: 50vh;
  }
  #hamburger-menu {
    display: block;
  }

  #container {
    flex-direction: column;
  }

  #tab-selector .tab {
    padding: 15px;
    font-size: 14px;
  }

  #chat-form {
    padding: 10px;
  }

  #chat-input {
    padding: 10px;
    font-size: 14px;
  }

  #chat-form button {
    padding: 10px 15px;
    font-size: 14px;
  }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  #container {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    order: 2;
  }

  #chat-area {
    width: 100%;
    order: 1;
    overflow-y: auto;
  }

  #hamburger-menu {
    display: block;
  }
}

/* Add these styles */
#threads-list {
  margin-top: 15px;
}

.thread-item {
  padding: 12px;
  margin: 8px 0;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.thread-item:hover {
  background: rgba(255,255,255,0.1);
  transform: translateX(5px);
}

.thread-item.active {
  background: var(--color-primary);
  font-weight: 600;
}

::selection {
  background: rgba(41, 98, 255, 0.493);
  color: #ffffff;
}
/* Improved Modal CSS */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(var(--blur-amount));
  z-index: 999999999999999999999;
  opacity: 0;
  transition: opacity 0.3s ease;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal.show {
  opacity: 1;
}

.modal-content {
  background: var(--color-secondary);
  width: 90%;
  max-width: 600px;
  border-radius: var(--border-radius);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  transform: translateY(-20px);
  transition: transform 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  background-color: var(--color-message-bot);
  color: var(--color-text);
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.close-button {
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s ease;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

.close-button:hover {
  opacity: 1;
  background-color: rgba(255, 255, 255, 0.1);
}

.search-input-container {
  padding: 20px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--color-text);
}

.search-input-container input[type="text"] {
  width: 100%;
  padding: 12px 20px 12px 50px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--color-text);
  background-color: var(--color-input-background);
  transition: border-color 0.2s ease;
  outline: none;
}

.search-input-container input[type="text"]:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(41, 98, 255, 0.2);
}

.loading-indicator {
  display: none;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: 3px solid rgba(41, 98, 255, 0.3);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.search-results-container {
  padding: 0 20px 20px;
  overflow-y: auto;
  max-height: 300px;
}

.search-results-container li {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  background-color: var(--color-message-bot);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background-color 0.2s ease;
}

.search-results-container li:hover {
  background-color: var(--color-message-user);
}

.result-icon {
  font-size: 1rem;
  color: var(--color-primary);
  margin-right: 12px;
}

.result-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-snippet {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-results {
  padding: 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

.message.error-message {
  border-left: 4px solid #ff4444;
  background: #ffe6e6;
}

.error-header {
  font-weight: bold;
  color: #cc0000;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-header i {
  font-size: 1.2em;
}

.error-content {
  color: #990000;
  white-space: pre-wrap;
}