/* Global Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html, body {
  height: 100%;
  overflow: hidden;  /* Prevent overall page scrolling */
}
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f4f7f6;
  color: #333;
  display: flex;
  flex-direction: column;
}

/* Header (Fixed at top) */
header {
  background: linear-gradient(135deg, #1E88E5, #42A5F5);
  padding: 10px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 200;
}
.header-left {
  display: flex;
  align-items: center;
}
.hamburger {
  background: none;
  border: none;
  font-size: 1.5em;
  color: #fff;
  cursor: pointer;
  margin-right: 10px;
}
header .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
  border: 2px solid #fff;
  object-fit: cover;
}
header .title {
  font-size: 1.2em;
  font-weight: bold;
  color: #fff;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.new-chat-btn {
  background-color: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: bold;
  color: #1e293b;
  transition: background 0.3s, box-shadow 0.3s;
}
.new-chat-btn:hover {
  background-color: #f1f5f9;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Main Container for Mobile Layout */
/* Fixed height: viewport height minus header */
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 60px; /* height of header */
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* Chat Container uses Flex so that input stays at bottom */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}
.chat-box {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #f8f8f8;
}
.input-area {
  flex: 0 0 auto;
  padding: 15px;
  border-top: 1px solid #ddd;
  background: #fff;
  display: flex;
  z-index: 250;
}
.input-area textarea {
  flex: 1;
  resize: none;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1em;
  height: 80px;
  max-height: 150px;
  white-space: pre-wrap;
}
.input-area button {
  margin-left: 10px;
  padding: 10px 20px;
  font-size: 1em;
  background: #1E88E5;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s;
}
.input-area button:disabled {
  background: #999;
  cursor: not-allowed;
}
.input-area button:hover:not(:disabled) {
  background: #1565C0;
}

/* Sidebar - Off‑Canvas on Mobile */
.sidebar {
  position: fixed;
  top: 60px; /* below header */
  left: -250px; /* hidden by default on mobile */
  width: 250px;
  height: calc(100vh - 60px);
  background: #e9eff1;
  border-right: 1px solid #ccc;
  padding: 10px;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  z-index: 150;
  overflow-y: auto;
}
.sidebar.active {
  left: 0;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  color: #1E88E5;
  font-weight: bold;
}
#toggleSidebar {
  background: none;
  border: none;
  font-size: 1.5em;
  cursor: pointer;
  color: #1E88E5;
  outline: none;
}
.role-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1;  /* pushes fixed boxes to bottom */
}
.role-list li {
  margin-bottom: 8px;
}
.role-list button {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 4px;
  background: #c8d6e5;
  cursor: pointer;
  transition: background 0.3s;
  font-size: 0.95em;
}
.role-list button:hover {
  background: #a4b0be;
}
.role-list button.selected {
  background: #1E88E5;
  color: #fff;
}

/* Fixed Auth & Donation Boxes (Always at the bottom of sidebar) */
.fixed-auth-box,
.fixed-donation-box {
  width: 100%;
  padding: 12px 10px;
  box-sizing: border-box;
  border-radius: 6px;
  text-align: center;
  font-size: 0.95em;
  margin-top: auto;
  margin-bottom: 10px;
}
.fixed-auth-box {
  background: rgba(30, 136, 229, 0.9);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.fixed-auth-box a {
  color: #fff;
  text-decoration: none;
  font-weight: bold;
}
.fixed-auth-box a:hover {
  text-decoration: underline;
}
.fixed-donation-box {
  background: #ff813f;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  font-size: 1.45em;
  font-family: 'Cookie', cursive;
}
.fixed-donation-box a {
  color: #fff;
  text-decoration: none;
  font-weight: bold;
}
.fixed-donation-box a:hover {
  text-decoration: underline;
}

/* Chat Message Styles */
.message {
  margin-bottom: 15px;
  display: flex;
}
.message.user {
  justify-content: flex-end;
}
.message.bot {
  justify-content: flex-start;
}
.message .bubble {
  max-width: 80%;
  padding: 12px 18px;
  border-radius: 16px;
  font-size: 1em;
  line-height: 1.4;
  white-space: pre-wrap;
}
/* New rule to wrap code inside the bubble */
.message .bubble code {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}
.message.user .bubble {
  background: #1E88E5;
  color: #fff;
  border-bottom-right-radius: 0;
}
.message.bot .bubble {
  background: #e5e5ea;
  color: #000;
  border-bottom-left-radius: 0;
}

/* Scrollbar Styles for Chat Box */
.chat-box::-webkit-scrollbar {
  width: 6px;
}
.chat-box::-webkit-scrollbar-track {
  background: #f1f1f1;
}
.chat-box::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.down-arrow {
  position: absolute;
  left: 50%;
  bottom: 100px; /* Adjust this value as needed */
  width: 40px;
  height: 40px;
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: none; /* Initially hidden */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 300;
}

/* Loading Indicator */
#loading-indicator {
  font-style: italic;
  color: #555;
  margin-top: 10px;
}

/* Footer */
footer {
  background: #f1f1f1;
  text-align: center;
  font-size: 0.6em;
  color: #555;
  border-top: 1px solid #ddd;
  padding: 10px;
}

/* Desktop Layout Overrides (≥768px) */
@media (min-width: 768px) {
  /* Switch main container to row layout */
  .main-container {
    flex-direction: row;
    height: calc(100vh - 60px);
  }
  /* On desktop, sidebar is visible by default */
  .sidebar {
    left: 0;
  }
  /* Toggling sidebar on desktop hides it and adjusts chat container margin */
  .sidebar.active {
    left: -250px;
  }
  /* Adjust chat container margin based on sidebar state */
  .sidebar:not(.active) + .chat-container {
    margin-left: 250px;
  }
  .sidebar.active + .chat-container {
    margin-left: 0;
  }
  .chat-container {
    flex: 1;
    position: relative;
  }
}

/* Mobile Overrides (≤767px) */
@media (max-width: 767px) {

  .sidebar {
    top: 60px; /* below header */
    height: -webkit-fill-available; /* viewport minus header (60px) and input-area (110px) */
    overflow-y: auto;
    padding-bottom: 20px; /* add a bit of padding for better appearance */
    /*z-index: 400; !* above everything else *!*/
  }

  /* For mobile, set chat-box height to allow scrolling */
  .chat-box {
    height: calc(100vh - 170px); /* 60px header + 110px input area */
    overflow-y: auto;
    flex: none;
    padding-bottom: 120px;
  }
  /* Fix the input-area at the bottom with fixed height */
  .input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 110px;
    z-index: 100;
  }
  /* Ensure active sidebar appears above the input-area */
  .sidebar.active {
    z-index: 300;
  }
}
