/* ========= GLOBAL & BASE STYLES (Mobile-first) ========= */
html,
body {
  height: 100%;
  overflow: hidden;
  margin: 0;
  padding: 0;
  font-size: 0.875rem; /* Base font-size */
  font-family: "Roboto", sans-serif !important;
}

#main-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#toggle-sidebar {
  background-color: transparent;
  border: none;
  color: #6a42c2 !important;
}

.body {
  color: white;
}

#session-list {
  flex-grow: 1;
  overflow-y: auto;
}

/* Scrollbar styling for #session-list and #chat-history */
#session-list,
#chat-history {
  scrollbar-width: thin;
  scrollbar-color: #6c757d #f1f1f1;
}

#session-list::-webkit-scrollbar,
#chat-history::-webkit-scrollbar {
  width: 8px;
}

#session-list::-webkit-scrollbar-thumb,
#chat-history::-webkit-scrollbar-thumb {
  background-color: #6c757d;
  border-radius: 4px;
}

#session-list::-webkit-scrollbar-track,
#chat-history::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

#new-chat {
  position: sticky;
  bottom: 0;
}

.chat-icon {
  cursor: pointer;
  font-size: 1.2rem;
  color: #5f6368;
  transition: color 0.3s;
}

.chat-icon:hover {
  color: #000;
}

.header {
  background-color: white;
  padding: 1rem;
  box-shadow: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(106, 66, 194, 0.1);
}

.send-button {
  background-color: #6a42c2;
  color: #fff;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
  opacity: 0.8;
  position: absolute;
  bottom: 0.5rem; /* Align with parent padding */
  right: 0.5rem; /* Align with parent padding */
}

.send-button:hover {
  background-color: #333;
}

#content {
  transition: all 0.3s ease;
  flex-grow: 1;
  overflow: auto;
}

#chat-history {
  flex-grow: 1;
  overflow-y: auto;
  height: 75vh;
  max-height: 75vh;
}

/* Buttons */
.btn.btn-secondary.dropdown-toggle.selectmodel {
  background-color: #6a42c2 !important;
}

#sidebar {
  background-color: #f2f0f6 !important;
  border-right: 1px solid rgba(106, 66, 194, 0.2);
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  transition: all 0.3s ease;
}

/* ========= EXTRA SMALL SCREENS: 360px x 256px ========= */
@media (max-width: 360px) and (max-height: 256px) {
  body {
    font-size: 0.75rem;
  }
  #rightside .header {
    height: 6vh;
    min-height: 6vh;
    padding: 0.25rem 0.5rem;
  }
  #rightside .header img {
    max-height: 100%;
  }
  #content,
  #chat-container {
    padding: 0.25rem;
  }
  #chat-history {
    padding: 0.1rem;
    font-size: 0.75rem;
  }
  #chat-input-area,
  .chat-input-container,
  .chat-input-container textarea {
    padding: 0.25rem;
    font-size: 0.75rem;
  }
  .send-button,
  #toggle-sidebar,
  .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }
  .text-center {
    font-size: 0.65rem;
    margin-top: 0.25rem;
  }
  #sidebar,
  #session-list {
    padding: 0.25rem;
    font-size: 0.7rem;
  }
  /* Adjust chat history height for extra small screens */
  #chat-history {
    height: 40vh;
    max-height: 40vh;
  }
  .chat-message,
  .chat-icon,
  .send-button {
    font-size: 0.8rem;
  }
  .send-button {
    width: 2rem;
    height: 2rem;
  }
}

@media (max-width: 768px) {
  /* Sidebar on the left */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 70vw;
    max-width: 70vw;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: all 0.3s ease;
    transform: translateX(-100%); /* Initially hidden off-screen to the left */
  }
  #sidebar.expanded {
    transform: translateX(0); /* Slide in from left */
  }
  #sidebar.collapsed {
    transform: translateX(-100%);
  }
  /* Rightside (chat area) occupies full width but shifts right when sidebar is expanded */
  #rightside {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: all 0.3s ease;
  }
  /* When sidebar is expanded, shift the rightside to the right by 70vw */
  #rightside.expanded {
    transform: translateX(70vw);
  }
  #rightside.collapsed {
    transform: translateX(0);
  }
}

/* ========= RESPONSIVE TEXT ========= */
@media (max-width: 576px) {
  .responsive-text {
    font-size: 0.7rem;
  }
}

@media (min-width: 577px) {
  .responsive-text {
    font-size: 0.875rem;
  }
}

@media (max-width: 400px) {
  .responsive-text {
    font-size: 0.6rem !important;
  }
}

@media (max-width: 360px) {
  .responsive-text {
    font-size: 0.6rem !important;
  }
  .selectmodel {
    font-size: 0.7rem !important;
    padding: 0.25rem 0.5rem !important;
  }
}

/* ========= DESKTOP STYLES (min-width: 769px) ========= */
@media (min-width: 769px) {
  /* Main container remains relative */
  #main-container {
    position: relative;
    width: 100vw;
    height: 100vh;
  }
  /* Sidebar on the left */
  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 20vw;
    height: 100vh;
    /* Uncomment and adjust these if desired:
    background-color: #fff;
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    */
    transition: all 0.3s ease;
  }
  /* When collapsed, sidebar moves off-screen */
  #sidebar.collapsed {
    width: 20vw;
    left: -20vw;
    overflow: hidden;
    transition: all 0.3s ease;
  }
  /* Chat area (rightside) is absolutely positioned with a left offset */
  #rightside {
    position: absolute;
    top: 0;
    right: 0;
    left: 20vw; /* aligned next to sidebar when expanded */
    height: 100vh;
    transition: left 0.3s ease;
    overflow: hidden;
  }

  /* When sidebar is collapsed, rightside expands to full width */
  #sidebar.collapsed ~ #rightside {
    left: 0;
  }

  #sidebar.collapsed ~ .chat-input-container {
    left: 0vw !important;
  }
  #sidebar:not(.collapsed) ~ .chat-input-container {
    left: 20vw !important; /* Align with sidebar when not collapsed */
  }
}

/* Optional color override */
bg-primary {
  color: #6a42c2 !important;
}

/* For Chrome, Safari, and Opera: hide chat-history scrollbar */
#chat-history::-webkit-scrollbar {
  display: none;
}

#chat-history {
  /* For Firefox */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* Hide session-list scrollbar */
#session-list {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#session-list::-webkit-scrollbar {
  display: none;
}

/* Prevent chat history from being hidden under the input area */
#chat-history {
  padding-bottom: calc(
    5vh
  ); /* Adjust 4rem based on your input container's typical height */
}

/* For WebKit-based browsers (Chrome, Safari, Opera) */
.chat-input-container textarea::-webkit-scrollbar {
  width: 4px;
}

.chat-input-container textarea::-webkit-scrollbar-track {
  background: transparent; /* Or use a subtle color if desired */
}

.chat-input-container textarea::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.4);
  border-radius: 2px;
}

/* Ensure the chat container is a positioning context */
#chat-container {
  position: relative;
  width: 100%;
  margin: 0 0;
}

/* Chat input container fixed 5vh from the bottom, with a background that spans its width */
.chat-input-container {
  position: absolute;
  bottom: 0vh;
  left: 0;
  right: 0;
  width: 90%;
  margin: 0 auto; /* Center horizontally */
  padding: 0.75rem 1rem;
  background-color: #f2f0f6;

  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
  display: flex;
  flex-direction: column; /* Stack children vertically */
  border: 1px solid rgba(106, 66, 194, 0.2);
}

/* Textarea styling: auto-grow up to 7 lines with a slim scrollbar */
.chat-input-container textarea {
  border: none;
  background: none;
  resize: none; /* Disable manual resizing */
  height: auto; /* Allow auto height */
  min-height: 2rem;
  font-size: 1rem;
  line-height: 1.5em; /* Assume each line is 1.5em tall */
  outline: none;
  overflow-y: hidden; /* Hide scrollbar until necessary */
  max-height: calc(1.5em * 7); /* Limit to 7 lines */
  width: 100%;
  display: block;
}

/* Slim scrollbar for WebKit browsers (Chrome, Safari, Opera) */
.chat-input-container textarea::-webkit-scrollbar {
  width: 4px;
}

.chat-input-container textarea::-webkit-scrollbar-track {
  background: transparent;
}

.chat-input-container textarea::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.4);
  border-radius: 2px;
}

/* Slim scrollbar for Firefox */
.chat-input-container textarea {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.4) transparent;
}

/* Push the misc div to the bottom and force it to align left */
#misc {
  margin-top: auto; /* Pushes it to the bottom */
  align-self: flex-start; /* Align to the left edge of the container */
  display: flex;
  gap: 0.5rem;
}

#upload-button {
  background-color: transparent !important;
  color: #6a42c2; /* matching text color */
  border: 1px solid #6a42c2;
  border-radius: 0.5rem; /* rectangular with rounded corners */
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
}

#upload-button:hover {
  background-color: rgba(106, 66, 194, 0.3); /* slightly darker on hover */
}

.btn.btn-secondary.dropdown-toggle.selectmodel {
  background-color: transparent !important;
  border: 1px solid #6a42c2;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  color: #6a42c2 !important; /* Sets the text color */
  text-decoration-color: #6a42c2;
}
.file-name {
  font-size: 0.75rem;
  color: #6a42c2;
}

.llm-settings-control-group {
  background-color: transparent !important;
  border: 1px solid #6a42c2;
  border-radius: 0.5rem;

  font-size: 1rem;
  color: #6a42c2 !important; /* Sets the text color */
  text-decoration-color: #6a42c2;
  border: none;
}

.advanced-settings-button {
  border: none;
}

@supports (height: 100dvh) {
  #chat-history {
    height: 75dvh;
    max-height: 75dvh;
  }
}

.chat-input-container {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background-color: #f2f0f6;
  box-shadow: 0 -10px 20px -10px rgba(242, 240, 246, 0.7); /* only fades upward */

  backdrop-filter: blur(2px); /* optional, enhances soft look */
}

#chat-history {
  height: calc(var(--vh, 1vh) * 75);
}
html,
body {
  overflow-x: hidden;
  overflow-y: auto;
}

/**/
#session-list {
  max-height: calc(100vh - 6rem); /* Adjust 6rem if buttons are taller */
  overflow-y: auto;
}
@media (max-width: 768px) {
  #sidebar {
    display: flex;
    flex-direction: column;
    height: 100dvh; /* Dynamic full height accounting for iOS browser chrome */

    padding-bottom: env(safe-area-inset-bottom); /* iOS safe area */
    overflow: hidden;
  }

  #session-list {
    flex-grow: 1;
    overflow-y: auto;
    max-height: calc(
      100dvh - 8rem
    ); /* Adjusted to leave room for the buttons + safe space */
  }

  /* Optional: make the button container sticky so it's always visible */
  #sidebar > .p-3:last-of-type {
    position: sticky;
    bottom: env(safe-area-inset-bottom, 0);
    background: #f2f0f6;
    z-index: 1;
  }
}

@media (max-width: 360px) and (max-height: 256px) {
  #session-list {
    flex-grow: 1;
    overflow-y: auto;
    height: 90vh; /* Adjusted for smaller screens */
    max-height: 90vh; /* Adjusted for smaller screens */
  }

  body {
    font-size: 0.65rem;
  }
  h2.text-sm {
    font-size: 0.9rem !important;
    margin-bottom: 0.25rem !important;
  }
  #sidebar > * {
    padding: 0.25rem !important;
  }
  .header .flex.items-center.gap-2 {
    height: 10vh !important;
    max-height: 10vh !important;
  }

  .header .flex.items-center.gap-2 img {
    max-height: 100% !important;
    object-fit: contain;
  }
  .header {
    margin-top: 0.5rem;
    height: 15vh;
    min-height: 15vh;
    padding: 0rem;
  }

  #chat-history {
    height: 57vh !important;
    max-height: 57vh !important;
    padding: 0.1rem !important;
  }

  .chat-input-container {
    padding: 0.25rem 0.5rem;
  }

  textarea#user-input {
    font-size: 0.7rem;
  }

  #sidebar {
    font-size: 0.65rem;
  }

  .send-button,
  #upload-button {
    width: 2rem;
    height: 2rem;
    font-size: 0.8rem;
    padding: 0.25rem;
  }

  #upload-button i {
    font-size: 0.8rem;
  }

  #navLinks {
    padding: 0.25rem !important;
  }

  #navLinks img {
    max-height: 20px !important;
    height: auto;
    width: auto;
  }
  /* Layout: side-by-side and compact */
  #sidebar > .p-3:last-of-type {
    display: flex;
    justify-content: space-between;
    gap: 0 !important;
    padding: 0.25rem !important;
  }

  /* Button base style */
  #sidebar > .p-3:last-of-type button {
    width: 48%; /* slightly shorter */
    font-size: 0.75rem;
    padding: 0.4rem 0.25rem;
    margin-top: 0 !important;
    border-radius: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid white; /* subtle white border for contrast */
    background-color: #333; /* dark background for contrast */
    color: white;
    transition: background-color 0.2s, border-color 0.2s;
  }

  /* Rounded outer edges only */
  #sidebar > .p-3:last-of-type button:first-child {
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5rem;
  }

  #sidebar > .p-3:last-of-type button:last-child {
    border-top-right-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
  }

  /* On hover: brighten up */
  #sidebar > .p-3:last-of-type button:hover {
    background-color: #555;
    border-color: #fff;
  }

  /* Replace original text with short label */
  #new-chat::after {
    content: "New";
    display: inline-block;
    margin-left: 0.5rem;
  }
  #clear-all-chats::after {
    content: "Clear All";
    display: inline-block;
    margin-left: 0.5rem;
  }

  #new-chat > i,
  #clear-all-chats > i {
    margin-right: 0 !important;
  }

  /* Hide original text */
  #new-chat,
  #clear-all-chats {
    font-size: 0 !important;
  }

  #new-chat::after,
  #clear-all-chats::after {
    font-size: 0.75rem;
  }
}
