body {
  font-family: 'Source Sans 3', sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Use dynamic viewport height for better mobile support */
  margin: 0;
  background-color: #1e1e1e; /* Gray.B10 */
  color: #e0e0e0;            /* Gray.B130 */
  /* Support for safe area insets on mobile devices */
  padding-bottom: env(safe-area-inset-bottom);
}

#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background-color: #2b2b2b;
  scrollbar-width: thick;            /* Firefox */
  scrollbar-color: #64b5f6 #1e1e1e; /* Firefox */
}

/* WebKit (Chrome, Edge, Safari) */
#chat-box::-webkit-scrollbar {
  width: 12px;
}

#chat-box::-webkit-scrollbar-track {
  background: #1e1e1e;
}

#chat-box::-webkit-scrollbar-thumb {
  background-color: #64b5f6;
  border-radius: 6px;
  border: 2px solid #1e1e1e;
}

#chat-input {
  display: flex;
  padding: 10px;
  border-top: 1px solid #4d4d4d; /* Gray.B40 */
  background-color: #1e1e1e;
  /* Ensure input stays above mobile browser buttons */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

#user-input {
  flex: 1;
  font-size: 1rem;
  padding: 6px;
  border: 1px solid #4d4d4d; /* Gray.B40 */
  border-radius: 4px;
  background-color: #2b2b2b; /* like Gray.B30 */
  color: #e0e0e0;            /* Gray.B130 */
}

#user-input::placeholder {
  color: #888888;            /* Gray.B70 */
}

button {
  margin-left: 10px;
  padding: 6px 12px;
  font-size: 1rem;
  background-color: #2196f3; /* Blue.B40 */
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #64b5f6; /* Blue.B70 */
}

u, b {
  color: #64b5f6; /* Blue.B70 for emphasis */
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  flex-wrap: wrap;
}

.top-bar h1 {
  margin: 0;
  font-size: 1.5rem;
}

.top-bar img {
  height: 60px;
  width: auto;
  max-width: 100%;
}

/* Caution and Settings Row */
.caution-settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: -10px;
  padding: 0 20px;
  position: relative;
}

/* Settings Button */
.settings-btn {
  background: none;
  border: none;
  color: #888888;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-btn:hover {
  background-color: #2b2b2b;
  color: #64b5f6;
}

.settings-btn.active {
  background-color: #2b2b2b;
  color: #64b5f6;
}

/* Settings Bubble */
.settings-bubble {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background-color: #2b2b2b;
  border: 1px solid #4d4d4d;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  min-width: 220px;
  margin-top: 8px;
}

.settings-bubble::before {
  content: '';
  position: absolute;
  top: -8px;
  right: 16px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid #4d4d4d;
}

.settings-bubble::after {
  content: '';
  position: absolute;
  top: -7px;
  right: 16px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid #2b2b2b;
}

.settings-content {
  padding: 16px;
}

.settings-content h3 {
  margin: 0 0 12px 0;
  font-size: 1rem;
  color: #e0e0e0;
  text-align: center;
}

/* Backend Section Styles */
.backend-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Login Section Styles */
.login-section {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  padding: 0 16px;
}

.login-btn {
  background-color: #404040;
  color: #a0a0a0;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: not-allowed;
  width: 80%;
  max-width: 120px;
}

.login-btn:disabled {
  background-color: #404040;
  color: #a0a0a0;
  opacity: 0.6;
}

.backend-label {
  color: #e0e0e0;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}

/* Radio Button Styles */
.radio-group {
  display: flex;
  flex-direction: row;
  gap: 8px;
  justify-content: center;
}

.radio-option {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
  white-space: nowrap;
}

.radio-option:hover {
  background-color: #3a3a3a;
}

.radio-option input[type="radio"] {
  margin-right: 8px;
  accent-color: #64b5f6;
  cursor: pointer;
}

.radio-label {
  color: #e0e0e0;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.radio-option:hover .radio-label {
  color: #64b5f6;
}

.radio-option input[type="radio"]:checked + .radio-label {
  color: #64b5f6;
  font-weight: 500;
}

/* Disabled radio option styles */
.radio-option-disabled {
  opacity: 0.5;
  cursor: not-allowed !important;
}

.radio-option-disabled:hover {
  background-color: transparent !important;
}

.radio-option-disabled input[type="radio"] {
  cursor: not-allowed !important;
}

.radio-label-disabled {
  color: #666666 !important;
  cursor: not-allowed !important;
}

.radio-option-disabled:hover .radio-label-disabled {
  color: #666666 !important;
}

/* Admin Section Styles */
.admin-section {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #444;
}

/* Checkbox Styles */
.checkbox-option {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
  white-space: nowrap;
  justify-content: center;
}

.checkbox-option:hover {
  background-color: #3a3a3a;
}

.checkbox-option input[type="checkbox"] {
  margin-right: 8px;
  accent-color: #64b5f6;
  cursor: pointer;
  transform: scale(1.1);
}

.checkbox-label {
  color: #e0e0e0;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-option:hover .checkbox-label {
  color: #64b5f6;
}

.checkbox-option input[type="checkbox"]:checked + .checkbox-label {
  color: #64b5f6;
  font-weight: 500;
}

/* Disabled checkbox styles */
.checkbox-option input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.checkbox-option input[type="checkbox"]:disabled + .checkbox-label {
  color: #666666;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  /* Mobile-specific viewport adjustments */
  body {
    /* Use the smaller of 100vh and 100dvh for better mobile browser support */
    height: 100vh;
    height: 100dvh;
    /* Additional bottom padding for mobile browsers */
    padding-bottom: max(env(safe-area-inset-bottom), 20px);
  }
  
  /* Reduce top bar padding on mobile */
  .top-bar {
    padding: 8px 12px; /* Reduced from 16px */
  }

  .top-bar h1 {
    font-size: 1.1rem; /* Slightly smaller */
  }

  .top-bar img {
    height: 32px; /* Reduced from 40px */
    margin-left: auto;
  }

  /* Reduce caution row spacing */
  .caution-settings-row {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 4px; /* Reduced from 8px */
    flex-wrap: wrap;
    padding: 0 12px; /* Reduced from 0 20px */
    margin-top: -5px; /* Reduced from -10px */
  }

  .caution-settings-row p {
    padding-left: 0 !important;
    flex: 1;
    min-width: 180px; /* Reduced from 200px */
    font-size: 0.85rem; /* Slightly smaller text */
    margin: 0; /* Remove any default margins */
  }

  /* Optimize chat box for mobile viewport */
  #chat-box {
    padding: 8px; /* Reduced from 12px */
  }

  /* Ensure input area fits */
  #chat-input {
    flex-direction: column;
    padding: 8px; /* Reduced from 10px */
    /* Extra padding on mobile to avoid browser buttons */
    padding-bottom: max(8px, env(safe-area-inset-bottom, 20px));
  }

  #user-input {
    width: 100%;
    margin-bottom: 6px; /* Reduced from 8px */
    font-size: 0.9rem; /* Slightly smaller */
  }

  button {
    width: 100%;
    margin-left: 0;
    padding: 8px 12px; /* Slightly reduced */
    font-size: 0.9rem; /* Slightly smaller */
  }

  .settings-btn {
    width: auto;
    margin-left: 0;
    padding: 6px; /* Reduced from 8px */
  }

  .settings-container {
    flex-shrink: 0;
  }

  .settings-bubble {
    right: 0;
    left: auto;
  }
}

/* Login/Authentication Styles */
.login-btn {
  background-color: #404040;
  color: #a0a0a0;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: not-allowed;
  width: 80%;
  max-width: 120px;
  transition: all 0.2s ease;
  margin: 0;
}

.login-btn:disabled {
  background-color: #404040;
  color: #a0a0a0;
  opacity: 0.6;
}

.login-btn-enabled {
  background-color: #2196f3 !important;
  color: white !important;
  cursor: pointer !important;
  opacity: 1 !important;
}

.login-btn-enabled:hover {
  background-color: #64b5f6 !important;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 0;
}

.user-label {
  color: #e0e0e0;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
  margin: 0;
}

.user-email {
  color: #64b5f6;
  font-size: 0.75rem;
  font-weight: 400;
  text-align: center;
  word-break: break-all;
  max-width: 100%;
  line-height: 1.2;
  margin-bottom: 4px;
}

.logout-btn {
  background-color: #f44336;
  color: white;
  border: 1px solid #d32f2f;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  width: 80%;
  max-width: 100px;
  transition: all 0.2s ease;
  margin: 0;
}

.logout-btn:hover {
  background-color: #d32f2f;
}

/* Conversation Section Styles */
.conversation-section {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #444;
  display: flex;
  justify-content: center;
}

.clear-conversation-btn {
  background-color: #ff9800;
  color: white;
  border: 1px solid #f57c00;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  width: 80%;
  max-width: 140px;
  transition: all 0.2s ease;
  margin: 0;
}

.clear-conversation-btn:hover {
  background-color: #f57c00;
}

